dc.js icon indicating copy to clipboard operation
dc.js copied to clipboard

Custom filters do not work in the chart where they are applied

Open mpenalver opened this issue 3 years ago • 0 comments

Custom filters work on other charts built from the same crossfilter, but not on the chart where the filter was applied. Example:

  let bubbleChartFilter = {
    filterType: "bubbleChartFilter",
    isFiltered: function (value) {
      return value > 0;
    },
  };

This filter considers only data items where the dimension's value is greater than 0. When used in dc.bubbleChart("#bubble-chart").filter(bubbleChartFilter), it is correctly applied to the chart's crossfilter dimension and, as expected, it is picked up by crossfilter groups derived from other dimensions, but no data is displayed on the bubble chart. The reason is that the isSelectedNode method of the BubbleMixing class works for filter values only and not for filter objects. The code below based on _defaultFilterHandler solves the problem. I presume that a similar solution can be applied to the other charts.

    isSelectedNode = function (d) {
      for (let i = 0; i < this._filters.length; i++) {
        const filter = this._filters[i];
        if (filter.isFiltered) {
          if (filter.isFiltered(d.key)) {
            return true;
          }
        } else if (filter <= d.key && filter >= d.key) {
          return true;
        }
      }
      return this._filters.length == 0;
    };

mpenalver avatar Aug 23 '21 20:08 mpenalver