Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mpenalver opened this issue Aug 23, 2021 · 0 comments
Open

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

mpenalver opened this issue Aug 23, 2021 · 0 comments

Comments

@mpenalver
Copy link

mpenalver commented Aug 23, 2021

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;
    };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant