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

Stack Mixin incorrectly filters descending non-ordinal scales #525

Open
mtraynham opened this issue Feb 23, 2014 · 4 comments
Open

Stack Mixin incorrectly filters descending non-ordinal scales #525

mtraynham opened this issue Feb 23, 2014 · 4 comments
Labels
Milestone

Comments

@mtraynham
Copy link
Contributor

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;
};
@gordonwoodhull
Copy link
Contributor

Thanks for the report!

@gordonwoodhull
Copy link
Contributor

These need to use the chart's ordering, which is how we build the domain of the scale.

There is almost a philosophical, or perhaps abstract nonsense, problem here, which is that d3 conflates ordinal and categorical variables. They probably did this because you eventually have to decide on an order for things.

In any case it is not the case that categorical variables can be ordered simply by using the comparison operators, and throughout dc.js we will have to detect whether we are dealing with an "ordinal" scale, which actually means categorical, and use the ordering there instead.

@gordonwoodhull
Copy link
Contributor

Also related: #772

@gordonwoodhull
Copy link
Contributor

Note that this issue also causes elasticY to calculate the domain as [0,0]; see #1538 (comment).

Therefore the workarounds are:

  • use evadeDomainFilter to stop the buggy filtering
  • do not use elasticY; calculate the Y scale domain yourself

Demo fiddle: https://jsfiddle.net/gordonwoodhull/gnmoqhck/31/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants