chart.filter and chart.filters - re-applying multiple ordinal filters

44 views
Skip to first unread message

Ethan Jewett

unread,
Jul 28, 2015, 11:49:43 AM7/28/15
to dc-js user group
Hi all,

If I have, say, a row chart or a geochoropleth, is it possible to programmatically apply a filter on more than one ordinal value? For example, if my chart is a geocloropleth of the US states, chart.filter("IL") will filter to Illinois. But chart.filter(["IL", "IA", "MN"]) results in errors. Further, if multiple states are selected, chart.filter() only returns the first one selected. chart.filters() returns all the filters, but chart.filters doesn't seem to be usable for setting filters.

Underlying problem is that I want to do an operation where I remove all filters and then re-apply them, but I don't see how it is possible to re-apply filters on ordinal charts with multiple values selected.

Thanks,
Ethan

Gordon Woodhull

unread,
Jul 28, 2015, 11:59:15 AM7/28/15
to dc.js user group
Hi Ethan!

The code around filters is very weird and special-casey. It would be great to clean it up in a future version.

I think what you're looking for is

chart.filter([["IL", "IA", "MN"]]); // another array!

Why, I don't know. Presumably someone found a need to distinguish this from an ordinary array for some reason. 

The code is

        if (_ instanceof Array && _[0] instanceof Array && !_.isFiltered) {
            _[0].forEach(function (d) { ...


Cheers,
Gordon


--
You received this message because you are subscribed to the Google Groups "dc-js user group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dc-js-user-gro...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dc-js-user-group/003a9765-3a8e-4bdc-96f9-c72d2602568d%40googlegroups.com.

Ethan Jewett

unread,
Jul 28, 2015, 12:16:41 PM7/28/15
to dc-js-us...@googlegroups.com
Hey Gordon,

Thanks! That does the trick. Cleaning it up would be good, but who has the time? :-) I can do what I need given that information about the API. (And yes, this is all about working around the fact that removing records from Crossfilter requires setting filters specifically for the removal.)

Cheers,
Ethan

Gordon Woodhull

unread,
Jul 28, 2015, 12:57:27 PM7/28/15
to dc-js-us...@googlegroups.com
Exactly. File it under 3.0!
Glad this worked for you.
Reply all
Reply to author
Forward
0 new messages