square/crossfilter — pull request #22 by zackham (2012-04-12 22:45:32+00:00)
Title: Multiple arguments to filter result in union of filter operations

Addresses issues #13 and #5.

The test says it all:

data.total.filter([0, 100], 190, [200, 300]);
assert.isTrue(data.date.top(Infinity).every(function(d) { return (d.total >= 0 && d.total < 100) || (d.total >= 200 && d.total < 300) || d.total == 190; }));
assert.equal(data.date.top(Infinity).length, 38);

How it works:

* First range/value is filtered, resulting in only those values selected.
* State var (union) is set, which disables incremental updates in filterIndex and instead assumes all values in bisected range are not selected, and adds them.
* Next time filterIndex runs, since hi0/lo0 are no longer valid for incremental updates, a pass is made to select all records and hi0/lo0 are updated accordingly.

Happy to rework this if it isn't coded up the way you'd like, just let me know.

Thanks,
Zack