fix(linear-scale): respect stepSize for non-divisible min/max ranges#12225
Open
syawqy wants to merge 1 commit intochartjs:masterfrom
Open
fix(linear-scale): respect stepSize for non-divisible min/max ranges#12225syawqy wants to merge 1 commit intochartjs:masterfrom
syawqy wants to merge 1 commit intochartjs:masterfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #12165
Summary
When
min,max, andstepSizeare set, linear tick generation used a spacing-based tolerance (spacing / 1000) to detect whole step counts.With larger step sizes, that tolerance can be too loose and misclassify non-divisible ranges as divisible, producing evenly distributed ticks instead of
stepSizeincrements.This change switches the whole-step check to a machine-precision-based epsilon derived from
stepCount.Behavior after fix
For non-divisible ranges, ticks follow
stepSizemultiples and keepmaxas the final shorter interval:min: 0,max: 3333,stepSize: 500[0, 500, 1000, 1500, 2000, 2500, 3000, 3333]Floating-point divisible ranges still behave correctly:
min: 0,max: 0.3,stepSize: 0.1Tests
Added regression tests in
test/specs/scale.linear.tests.jsfor:0..3333,stepSize: 500)0..0.3,stepSize: 0.1)Validated with:
pnpm run lint-jspnpm run test-ci-karma scale.linear.testsReferences