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

Heat map filtering #532

Open dtfoster opened 10 years ago

dtfoster commented 10 years ago

I've noticed that filtering in the new heat map chart type only changes the colouring of the boxes correctly when clicking on a box or axis label. When calling the filter method manually (heatmapChart.filter([1,1]) for example), all of the boxes are greyed out after the filter, even though the filtering of the data has been applied correctly.

I think the issue is that the hasFilter function isn't currently set up to deal with 2 element arrays as input, such as [1,1]. I suggest something like the following to fix the issue:

_chart.hasFilter = function (filter) {
    if (!arguments.length) return _filters.length > 0;
    if (filter instanceof Array){
        var out;
        out = false;
        _filters.forEach(function(x){
            if (x.isFiltered(filter)){
            out = true
            }
        })
        return out
    }else{
        return _filters.indexOf(filter) >= 0
    };
};
gordonwoodhull commented 10 years ago

Thanks for the report and possible fix!

Would you be willing to submit a PR with tests that fail before and succeed after your fix? The current tests are in spec/heatmap-spec.js.