NickQiZhu/dc.js — pull request #91 by krikrou (2012-11-23 18:16:39+00:00)
Title: add pivot features

This addition allows to use crossfilter groups as chart series in dc.js.

1 - use this fork of crossfilter (https://github.com/e-smile/crossfilter/tree/pivot), which allow to calculate reduce functions across projected groups at minimum cost:
```js
data = [{
value:14,countrycode:"US",state:"California",status:"plan",id:111,region:"South",date: "2013-05-25T16:10:09Z"
},{
value:15,countrycode:"US",state:"California",status:"actual",id:111,region:"South",date: "2013-05-25T16:10:09Z"
},{
value:45,countrycode:"US",state:"COL",status:"plan",id:122,region:"West",date:"2010-05-25T16:10:09Z"
}];

data = crossfilter(data);
statusDimension = data.dimension(function(d) {
return d.status;
});
statusGroup = statusDimension.group();

dateDimension = data.dimension(function(d) {
return d3.time.day(d.dd);
});
dateGroup = dateDimension.group();
monthTypeGroup = dateDimension.group(function(d){return d3.time.month(d)});
monthTypeGroup.reduce(
//add
function(p, v, i, pivot) {
++p[pivot[0].idx()[i]].count;
p[pivot[0].idx()[i]].value += +v.value;
return p;
},
//remove
function(p, v,i,pivot) {
--p[pivot[0].idx()[i]].count;
p[pivot[0].idx()[i]].value -= +v.value;
return p;
},
//init
function(pivot) {
var l, i, obj ={};
if(l = pivot[0].all().length){
for(i=0; i