How do I get the current filter for a crossfilter dimension?
Asked Answered
R

2

10

I have a crossfilter.dimension. How do I get the current filter set on it (for example if it was set by a brush from a chart)?

Example:

dimension.filterRange([1,15]) // returns dimension

Given this filtered dimension, how do I get the values 1 and 15 out?

Raquel answered 5/2, 2015 at 21:17 Comment(1)
I don't believe you can. It would be nice to be able to access both dimension accessors and current filters, but I can see why they don't allow this. The workaround is to track the filter separately so that you can look it up when you need to.Bankbook
P
2

Stumbled on this old question because it is the top-voted unanswered crossfilter question, with 1k views!

This feature was contributed by Thomas Gillet in 1.4.5 as dimension.currentFilter()

The tough remaining problem: when you get beyond filterExact and filterRange, the more complex filters use filterFunction. You might be able to retrieve the function but functions are essentially opaque.

For example, if you are using dc.js, it will generate a filter function when

  • multiple items are selected in pie chart, row chart, or bar chart with ordinal dimension
  • the chart has a two-dimensional filter, like the scatter plot or the heatmap

For this reason, if you're using dc.js, you should use chart.filters() instead.

Palstave answered 10/1, 2020 at 19:14 Comment(0)
C
0

Thank you, Gordon. This was really helpful to me! One note - your link is correct -- it goes to filters(), but the text displays as chart.filter() which is in the API, but doesn't return multiple filters on a chart. I tried to edit your answer, but it won't allow single character changes!

Cockayne answered 24/7, 2020 at 17:48 Comment(1)
Thanks @sottitron. Didn't see this earlier because you added an answer instead of commenting on my answer. Fixed now, please delete this.Palstave

© 2022 - 2024 — McMap. All rights reserved.