dc-js / dc.js

Multi-Dimensional charting built to work natively with crossfilter rendered with d3.js
Apache License 2.0
7.42k stars 1.8k forks source link

implement filterHandler for series charts #1471

Open gordonwoodhull opened 6 years ago

gordonwoodhull commented 6 years ago

https://stackoverflow.com/questions/51421943/pie-chart-not-updating-properly-when-using-brush-in-series-chart

The RangedFilter expects to receive raw X values, but it's receiving arrays (usually).

A messy way to fix it for the common case where the key is just a composite:

chart.filterHandler(function(dimensions, filters) {
  if (filters.length === 0) {
    dimension.filter(null);
  } else {
    var filter = dc.filters.RangedFilter(filters[0][0], filters[0][1]);
    dimension.filterFunction(function(k) {
      return filter.isFiltered(chart.keyAccessor()({key: k, value: null}));
    });
  }
  return filters;
});

But if we insist that the key must be a composite of series and key, then keyAccessor and seriesAccessor should not be as general as they are now.

gordonwoodhull commented 5 years ago

I think the situation has gotten even weirder in 3.0: since we consistently apply the filter in the parent and all children, the handler must be overridden in the child charts as well, e.g.:

  .chart(function(c) { return dc.lineChart(c).curve(d3.curveCardinal).filterHandler(seriesFilter); })

Demo fiddle: https://jsfiddle.net/gordonwoodhull/zvnhcwpk/16/

Cf. https://stackoverflow.com/q/55438591/676195