-
Notifications
You must be signed in to change notification settings - Fork 11.9k
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
Use abs() when comparing for spanGaps #10316
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. If all tests pass, I think this is ok. Can you add a regression test?
Thanks! I added tests, needed more than just a regression test for this because I didn't find any existing tests for using a numeric value for spanGaps. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suspect the data is sorted when parsed and the order does not really matter. Can you verify that? If I'm right, your actual use case must be more complex. Maybe using some optimizations to skip the sorting?
test/specs/controller.line.tests.js
Outdated
xAxisKey: 'x', | ||
yAxisKey: 'y', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do these lines affect the tests in any way? These should be the defaults.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, they don't. I added them when what I really needed was the linear scale, and forgot to remove them. I went ahead and pushed an update.
I think there are some fixtures. |
I don't think so... I'm definitely not using "parsing: false" which if I understand right is what would skip that. |
I think I was just wrong :) |
Here's a repro using the CDN chart.js, the only difference is the order of the data. Working spangaps: https://jsfiddle.net/82zcyh9n/13/ |
I think the fact that the data is unsorted makes sense, if the line controller ignores the order and draws the points in whatever order provided (meaning it may be possible to backtrack on the x axis). If that's the case, then spanGaps is arguably not working correctly except when "parsing: false" is provided to signal that the data is already in final order? I'm really outta my depth on this code though, so take with a grain of salt :) |
This does appear to be true, check this one out with out-of-order points: It seems like spanGaps doesn't use sorted data, even when it might be expected (because parsing: false" is not provided). |
Not sure if this is intended but I've been using data in descending order by X axis value, to share underlying data structures with components that need it that way. It seems to work fine, except that spanGaps breaks because the "gap" is negative and always compares less-than the threshold.
This fixes that issue, but of course isn't appropriate if ascending order is required -- I may have missed something but I didn't see a specification about that in the docs.