...
function intervalTreeGroup(tree, firstDate, lastDate) {
return {
all: function() {
var begin = d3.time.day(firstDate), end = d3.time.day(lastDate);
var i = new Date(begin);
var ret = [], count;
do {
next = new Date(i);
next.setDate(next.getDate()+1);
count = 0;
tree.queryInterval(i.getTime(), next.getTime(), function() {
++count;
});
ret.push({key: i, value: count});
i = next;
}
while(i.getTime() <= end.getTime());
return ret;
}
};
}
//calculate interval and convert from unix timestamps to js date objects
//create cccc for cleared completed closed and cancelled
var cccc = [];
activities.forEach(function(d) {
if([2,3,4,5].indexOf(+d["statusId"]) > -1) {
cccc.push(d);
}
});
cccc.forEach(function(d) {
d["activityDateEntered"] = new Date(d.activityDateEntered * 1000);
d["activityDateWorkStart"] = new Date(d.activityDateWorkStart * 1000);
if (d["activityDateWorkComplete"] == null){
d["activityDateWorkComplete"] = new Date();
} else {
d["activityDateWorkComplete"] = new Date(d.activityDateWorkComplete * 1000);
};
d.activityDateWorkInterval = [d["activityDateWorkStart"].getTime(), d["activityDateWorkComplete"].getTime()]
})
//creates crossfilter object of activities
var cf = crossfilter(cccc);
var intervalDim = cf.dimension(function(d) {return d.activityDateWorkInterval;});
var startDim = cf.dimension(function(d) {return d.activityDateWorkStart;});
var endDim = cf.dimension(function(d) {return d.activityDateWorkComplete;});
//start and close dates for activities
var minDate = startDim.bottom(1)[0]["activityDateEntered"],
maxDate = endDim.top(1)[0]["activityDateWorkComplete"];
var dailyActivitiesTree = cf.groupAll().reduce(
function(v,d) {
v.insert(d.activityDateWorkInterval);
return v;
},
function(v,d) {
v.remove(d.activityDateWorkInterval);
return v;
},
function() {
return lysenkoIntervalTree(null);
}
)
var dailyActivitiesGroup = intervalTreeGroup(dailyActivitiesTree.value(),minDate,maxDate);
var datesChart = dc.barChart("#timeline");
datesChart
.height(60)
.width(this.width)
.dimension(intervalDim)
.group(dailyActivitiesGroup)
.x(d3.time.scale().domain([minDate,maxDate]))
.xUnits(d3.time.day)
.brushOn(true)
.controlsUseVisibility(true)
.yAxis().ticks(0).tickFormat('');
console.log("buuts")
dc.renderAll();
...