-
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
Fix issue #4928: linear tick generator doesn't round values to needed precision. #4943
Conversation
- linear tick generator doesn't round values to needed precision.
src/core/core.ticks.js
Outdated
// Put the values into the ticks array | ||
var precision = 1; | ||
if (spacing < 1) { | ||
precision = Math.pow(10, spacing.toPrecision().length - 2); |
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.
Would it be equivalent to replace .toPrecision()
with .toString()
? I think that would make it clearer
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.
In this case I think they both return equal results. Since the code is trying to find the number of significant digits after the decimal point.
You're on a roll! This is great! |
The logarithmic tick generator contains the same problem. |
Rounding negative values didn't create the expected result |
Could be useful to unit test these expected values (positive and negative)? |
Where is such a test best placed, and should the test be run directly on the BTW a lot of test code use the function
example |
I don't think tests can run directly on generators because they are not accessible from Not sure why |
Agree about testing on a real chart. For the |
… needed precision. (chartjs#4943) * Fix issue 4928 - linear tick generator doesn't round values to needed precision. * Improve: replace toPrecision() in toString() to improve readability. * Fix: logarithmic tick generator doesn't round values to needed precision. * Fix: rounding tick values didn't work for negative values. * Add: Core ticks tests
… needed precision. (chartjs#4943) * Fix issue 4928 - linear tick generator doesn't round values to needed precision. * Improve: replace toPrecision() in toString() to improve readability. * Fix: logarithmic tick generator doesn't round values to needed precision. * Fix: rounding tick values didn't work for negative values. * Add: Core ticks tests
Fixes #4928 - linear tick generator doesn't round values to needed precision.
Test case: https://codepen.io/anon/pen/LOLxvL
v2.7
Proposed fix