Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Support custom filter functions. #36

wants to merge 9 commits into


None yet

jasondavies commented Aug 27, 2012

This is an extension to #33. Useful for filtering multi-valued fields, for example.

zackham and others added some commits Apr 12, 2012

Fix groupAll() after union reset.
This is also somewhat more efficient for large datasets, since it
recomputes group values from scratch rather than selecting all values,
removing them, and then adding them again.
Union of filters: return the dimension.
This is for consistency with non-union filters.
Support custom filter functions.
This allows more esoteric filtering to occur e.g. multi-valued fields.
The filter function is called for every value, so this is slower than
incremental range filtering.

This is really helpful Jason!


jasondavies commented Sep 24, 2012

Thanks! I've successfully used bit vectors to represent multi-valued fields that only have up to 32 values. You can also simply use objects or arrays for more values.

enjalot commented Oct 26, 2012

This definitely saved me a lot of trouble! Thanks.
Here is a simple example of using arrays: http://enjalot.com/tributary/3955491/

@gkostov gkostov referenced this pull request Nov 16, 2012


Filtering by regex #43

A great many thanks for authoring this Jason. I'm currently working on a project where this is very handy and I've set up a little regexp filter for a text dimension. It works great apart from one of the 6 dimensions simply not updating its group once an arbitrary filter has been set. Clearing the filter on the dimension with filterAll doesn't help.

I've coerced it into behaving by exposing the resetMany call on group and calling it manually on the recalcitrant chart for every renderAll. I'll see if I can work up a negative test for this, but I'm wondering what's causing it since the other groups are updating fine.

sjzabel commented Dec 18, 2012

Thank you Jason... I'm using this in conjunction with the D3 geo library to filter data by state selection

kisielk commented Jan 28, 2013

Just wondering if there's a reason this hasn't been merged yet? We are looking at using this same functionality for custom regexp filters.


mbostock commented Jan 29, 2013

There's no reason this hasn't been merged other than time…

Just wondering what the scope of lo1 in src/crossfilter.js on line 287 should be.
It's being set in global scope.
If I comment it out, the tests still work fine.
introduced in commit 63d50a3


jasondavies commented Feb 13, 2013

Yes, this was a dangling global and I’ve removed it now. Thanks.

@jasondavies jasondavies referenced this pull request Feb 28, 2013


multi-value filtering #50


jasondavies commented Mar 2, 2013

Superseded by #64.

@jasondavies jasondavies closed this Mar 2, 2013

@jasondavies jasondavies deleted the jasondavies:filter-custom branch Mar 2, 2013

Should it be possible with #64 to filter two or more values of a (categorical) dimension? and if so, how?


jasondavies commented Mar 12, 2013

var query = ["foo", "bar"];
dimension.filter(function(d) { return query.indexOf(d) >= 0; });

Slightly faster but trickier if you want to create dynamic filters:

dimension.filter(function(d) { return d === "foo" || d === "bar"; });

RandomEtc commented Mar 12, 2013

Also worth trying an object if you have more/dynamic terms to match:

var query = { foo: 1, bar: 1 };
dimension.filter(function(d) { return d in query; });

Thanks a lot!! I understand how this works now!

Hi there! I've been a "fan" of Crossfilter for more than year now and I'm really excited with all the updates that have been implemented recently. Kudos to the contributors! However, I'm a lil confused with how Github works and I'm wondering what's the latest version of Crossfilter in accordance with @jasondavies repo - is it 1.1.3 or 1.1.2?

Apparently, 1.1.2 is able to have custom filter as mentioned above but 1.1.3 has no such capabilities yet?

Also, has the ability to filter multiple arguments as such "dimension.filter([1,5],10,[13,16])" been implemented? A solution was mentioned in #22 but I can't seem to do such filtering using Crossfilter 1.1.2. If it hasn't, then is there any way I could do such filtering using version 1.1.2?

Thanks for the help rendered!


jasondavies commented Mar 18, 2013

@jaytjioe, Crossfilter uses semver, thus there have been no new features added in v1.1.x since v1.1.0 (these are called patch versions). The next minor version will be v1.2.0, and will include filtering by arbitrary functions. Efficient multi-range filtering will probably not be until v1.3.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment