crossfilter / reductio

Reductio: Crossfilter grouping
Other
250 stars 42 forks source link

group.post.cap(length).() always does natural ordering #47

Open mukherjeea opened 8 years ago

mukherjeea commented 8 years ago
var skuDim = ndx.dimension(function(d){ return d.sku; });
var skuGroup = skuDim.group();
var skuReducer = reductio().count(true).sum('hits');
skuReducer(skuGroup);
skuGroup.order(function(p) { return p.sum; });
console.log(skuGroup.top(Infinity));
console.log(skuGroup.post().cap(3)());`

crossfilter top orders correctly. reductio post().cap(length)() doesn't.

esjewett commented 8 years ago

Sorry, I was just not familiar enough with this part of the API. I would prefer if it respected group ordering, but the way it works right now is that you need to use the sortBy option of the post processing capability like so:

group.post().sortBy('value.sum', d3.descending).cap(3)()

I'll answer on StackOverflow as well.

Longer-term, I'd prefer that the post-processing respected group order by default, so I will consider making that change for a 1.0 release and therefore leave this issue open.

Thanks, Ethan

esjewett commented 8 years ago

You'll need to create a fake group. There is an example in the dc.js FAQ: https://github.com/dc-js/dc.js/wiki/FAQ#fake-groups

Note that you could also use dc.js's ordering and capping capabilities rather than Reductio's. Up to you!

mukherjeea commented 8 years ago

Cheers Ethan. I got it working. That's why I removed the comment here and added the comment on SO. I would be nice the have the feature as well because most of the time I'm guessing people would want to use it in charts. I don't know where it fits between dc.js and reductio but I think this might be pretty useful. Thanks again!

raino01r commented 7 years ago

So, is it possible to add a fake group on a reductio-ned group?

Probably the solution is already given, but to me it is not clear. Assume

reducer = reductio();
// complicate filtering on reducer
group = reducer(group)

then just doing the following looks like a lost of functionality. Am I wrong?

group = remove_empty_bins(group)
esjewett commented 7 years ago

Please don't ask new questions on old issues being used to track features. Open a question on Stackoverflow or a new issue here with a running example of your issue/question. Thanks!