fix(scale): avoid duplicate final tick with bounds:'data' and fractional max - #12288
Open
contactjawad wants to merge 1 commit into
Open
fix(scale): avoid duplicate final tick with bounds:'data' and fractional max#12288contactjawad wants to merge 1 commit into
contactjawad wants to merge 1 commit into
Conversation
…nal max When a linear scale bounds to data and the data max has a fractional part that rounds down to the last emitted tick, the rounded niceMax was pushed again, producing a duplicate final tick and axis label. Skip the push when it would duplicate the last tick.
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.
What
A linear scale using
bounds: 'data'emits a duplicate final tick (and a duplicate axis label) when the data maximum has a fractional part that rounds down to the last generated integer tick. For example, data[0, 5.4]produces labels['0','1','2','3','4','5','5'].Why
In
generateTicks, withbounds: 'data'theniceMaxis the raw data max, andnumSpacesisMath.ceil((niceMax - niceMin) / spacing). The loop therefore emits ticks up to and including the integer just below the data max (e.g.5for a max of5.4).niceMaxis then rounded to the tick factor and unconditionally pushed again:When the rounded
niceMaxequals the last loop-emitted tick, that value is added twice.How
Guard the final push so it does not duplicate the last emitted tick:
Test
Added a spec in
test/specs/scale.linear.tests.jsalongside the existing "Should bound to data" test, using dataset[0, 5.4],bounds: 'data'andticks.autoSkip: false, asserting the labels are['0','1','2','3','4','5']. Before the fix the labels are['0','1','2','3','4','5','5'], so the test fails on the previous behavior and passes with the fix.