dc.js client / server code (for mongo)

223 views
Skip to first unread message

Blair Nilsson

unread,
Feb 23, 2016, 4:58:27 AM2/23/16
to dc-js user group
Running the crossfilter part of dc.js on the server is something which has been driving many people crazy (myself included)

I built a system for doing so, but, because we were commercializing a sister project, I couldn't release the code.

Finally, we are at a stage where the code to hand the processing off from dc.js to mongodb can be open sourced.

You have no idea how long I have been wanting to share this with the community. (Well, Gordon does...)

It isn't in what you would call a "good" state (no docs or demos), but technically it is usable, the code is not bad.

Over the next few weeks we will be pushing patches in, building document / demos etc which will bring it up to a good state.

so...

How to use it....

Say you had a row chart which was going to show the number of cats a person had brought.

the data looked like...

invoice, person, cats
1, 'blair', 2
2, 'bob', 3
3, 'blair', 1

and it was in a collection called catCollection in the mongo server.

(the chart should show that blair had 3 cats, and bob also had 3 cats)


var catSource = fakeFilter.fakeCrossFilter().dim('name').sum('cats').filterNullKey(true).limit(60).sort('value',-1);

var cat_chart = dc.rowChart('#catChart')
                 
.dim(catSource)
                 
.group(catSource)
                 
.height(....)

#... other charts etc go here....

fakeFilter.registry.url('http://localhost:3000');
fakeFilter.registry.collection('catCollection');
fakeFilter.registry.registerAll();

fakeFilter.registry.fetchData(function() {
  dc.renderAll();
});


The catSource is BOTH a dimension and a group. (that is, it supports all the calls you would make on the dimension as well as the group itself)

notes:

using .cap() is RIGHT OUT. happily it gives you limit.... which does mostly the same thing.

You CAN'T give it a custom reduce function, since.... clients handing arbitrary code down to mongo for it to execute would be a HUGE security hole.
However it does handle sum, count, avg, max, min etc...

So it shouldn't be too limiting.... (hopefully)

It does generate pretty readable queries for the aggregation pipeline, so if you need to get your debugging hat on for what is happening at the mongo end, then it shouldn't be too bad.

The code is pretty short, and reasonably clean.

It does however patch the filter handler in dc.js.... I'm not sure it needs to do this anymore. if it does, then is it a bug in dc.js ;)

drum roll please...

The client code is at...


and predictably... the server code is at


I'll be putting up demos and howto guides in the next few days.

enjoy!



Reply all
Reply to author
Forward
0 new messages