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

Use abs() when comparing for spanGaps #10316

Merged
merged 3 commits into from
May 1, 2022
Merged

Conversation

luke-heberling
Copy link
Contributor

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.

Copy link
Member

@kurkle kurkle left a 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?

@luke-heberling
Copy link
Contributor Author

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.

Copy link
Member

@kurkle kurkle left a 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?

Comment on lines 973 to 974
xAxisKey: 'x',
yAxisKey: 'y',
Copy link
Member

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.

Copy link
Contributor Author

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.

@kurkle
Copy link
Member

kurkle commented Apr 27, 2022

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.

I think there are some fixtures.

@luke-heberling
Copy link
Contributor Author

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?

I don't think so... I'm definitely not using "parsing: false" which if I understand right is what would skip that.
However, now that you put it that way... if the data is expected to be sorted before the spanGaps calc sees it then there's something else going on. The test appears to show that the data is NOT sorted, note how the index for "stop" changes based on the order.

@kurkle
Copy link
Member

kurkle commented Apr 27, 2022

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?

I don't think so... I'm definitely not using "parsing: false" which if I understand right is what would skip that.
However, now that you put it that way... if the data is expected to be sorted before the spanGaps calc sees it then there's something else going on. The test appears to show that the data is NOT sorted, note how the index for "stop" changes based on the order.

I think I was just wrong :)

@kurkle kurkle requested a review from etimberg April 27, 2022 04:48
@luke-heberling
Copy link
Contributor Author

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/
broken spangaps: https://jsfiddle.net/82zcyh9n/12/

@luke-heberling
Copy link
Contributor Author

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 :)

@luke-heberling
Copy link
Contributor Author

luke-heberling commented Apr 27, 2022

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?

This does appear to be true, check this one out with out-of-order points:
no spangaps: https://jsfiddle.net/kne0oa7y/
yes spangaps: https://jsfiddle.net/3vLzwhu9/

It seems like spanGaps doesn't use sorted data, even when it might be expected (because parsing: false" is not provided).
The change to use abs() might still be a good step forward, which would meet reasonable expectations for reversed data.

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

Successfully merging this pull request may close these issues.

3 participants