dc-js / dc.js

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

zooming series chart filters out all data #1297

Open gordonwoodhull opened 7 years ago

gordonwoodhull commented 7 years ago

As reported on Stack Overflow:

http://stackoverflow.com/questions/43682744/dc-js-weird-mouse-zooming-for-serieschart

When the series chart zooms, it filters using an ordinary dc.filters.RangedFilter because it inherits this functionality from coordinateGridMixin. But the series chart requires strange "multikey" data with multiple parts to the key, so assuming this is implemented as an array (as it usually is), the dimension starts comparing arrays against the start and end of the range.

Arrays coerce to NaN and NaN always compares false, so all data is filtered out.

A workaround looks like this:

  seriesChart.filterHandler(function(dimension, filters) {
    if(filters.length === 0) // 1
      dimension.filter(null);
    else {
      console.assert(filters.length===1); // 2
      console.assert(filters[0].filterType==='RangedFilter');
      dimension.filter(function(d) { // 3
        return filters[0][0] <= d[1] && d[1] < filters[0][1];
      })
    }
  });

Perhaps the seriesChart could do something like that itself, using the keyAccessor? I haven't thought it through completely, but it seems like the current behavior is completely broken.

I'm surprised I can't find an issue for brushing series charts - seems like that should be broken in exactly the same way.

fdmota commented 6 years ago

This solution is incomplete for v3. The filterHandler needs to be set for the children chart as well. Unless there is a new better way of doing it....