Open
Description
Hey Gordon,
From the thread on the user group:
https://groups.google.com/forum/#!topic/dc-js-user-group/g-Pws58K6B0
The stackMixin incorrectly filters descending non-ordinal scales. The domain filter on the stack function filters values with the following code:
return p.x >= xDomain[0] && p.x <= xDomain[xDomain.length-1];
For example if x=10 and domain is [0, 20], the ascending case is correct:
10 >= 0 && 10 <= 20 //returns true
In the descending case, if x=10 and domain is [20, 0], the descending case is incorrect:
10 >= 20 && 10 <= 0 //returns false
As a solution, likely d3.extent on the domain? Or if it's always expected that the domain is an array with min and max at the ends, Math.max and Math.min or some variation of that calculation should suffice:
var minDomain = Math.min(xDomain[0], xDomain[xDomain.length-1]),
maxDomain = Math.max(xDomain[0], xDomain[xDomain.length-1]);
return function(p) {
//return true;
return p.x >= minDomain && p.x <= maxDomain;
};
As a secondary note, dc.filters.RangedFilter has similar logic, and should be checked as well.
dc.filters.RangedFilter = function(low, high) {
var range = Array(low, high);
range.isFiltered = function(value) {
return value >= this[0] && value < this[1];
};
return range;
};