-
Notifications
You must be signed in to change notification settings - Fork 11.9k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Support decimal stepSize #5786
Support decimal stepSize #5786
Conversation
src/scales/scale.linearbase.js
Outdated
// If the user specified a precision, round to that number of decimal places | ||
factor = Math.pow(10, precision); | ||
spacing = Math.ceil(spacing * factor) / factor; | ||
} | ||
} | ||
var niceMin = Math.floor(dataRange.min / spacing) * spacing; | ||
var niceMax = Math.ceil(dataRange.max / spacing) * spacing; | ||
// If a precision is not speified, calculate factor based on spacing |
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.
speified -> specified
Maybe I didn't understand the issue / feature behind both options: I'm a bit worried about mixing both configs and have
I think we should support that case:
What about: |
When In that sense, it seems natual to me that |
Or, should the auto-generated tick interval be completely independent from the precision? Should In that case, there may be another confusion. eg. |
I understand, I thought that |
Thanks @benmccann, I have added a jsdoc and fixed a typo. |
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.
... but this may cause confusion. eg.
stepSize: 0.524, precision: 2
results in 0, 0.52, 1.04, 1.56
I think the confusion comes from the fact that the precision applies to two concepts: the tick generation and the displayed format. Initially introduced to fix #4103, it's definitely not to control the displayed format, so you right.
Or, should the auto-generated tick interval be completely independent from the precision? Should precision be only applied to the generated tick values?
I think it's possible to override the display format with scale.ticks.callback
but that's not really convenient.
Thanks @nagix
This PR adds support for decimal
stepSize
for linear scales. In the current code,stepSize
>= 1, ticks will be rounded to integersstepSize
< 1, ticks will have the appropriate decimal precisionstepSize
is not specified, the tick interval will be set to a 'nice' number, so there is no rounding issueIn this PR, the decimal precision is calculated based on
stepSize
if specified, or a generated 'nice' number orticks.precision
(only ifstepSize
is not specified).Fixes #5392
Fixes #5579