Repository navigation
fix(category): do not modify the user provided labels array - #12344
Open
saadkhantareen wants to merge 1 commit into
Open
saadkhantareen wants to merge 1 commit into
saadkhantareen wants to merge 1 commit into
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.
Summary
The category scale generates labels for data values that are missing from the labels array, but it did so by pushing to (and later splicing out of) the exact array instance the user provided, either as
data.labelsor as the scalelabelsoption. The user's array was left modified after the chart ran. The scale now works on its own copy of the labels array, so the array provided by the user is never modified, while the generated labels keep working exactly as before.Changes
src/scales/scale.category.js:CategoryScalecaches a copy of the labels array (taken in the newgetLabels()override) and discards the cache oninit(), when the copy is rebuilt from the current source array. The previousinit()cleanup that spliced parse-added labels back out of the user's array is no longer needed and was removed.test/specs/scale.category.tests.js: two regression tests covering both label sources (scalelabelsoption anddata.labels) asserting that missing labels are still generated for the ticks while the user-provided array stays unchanged.Tests
Karma + Jasmine in headless Chrome (specs selected by file name via
--grep):karma start --single-run --browsers ChromeHeadless --grep scale.category— 26 passed (24 existing + 2 new), 0 failed. The two new tests were verified to fail before the fix.--grep scale440 passed,--grep controller553 passed,--grep core419 passed,--grep plugin242 passed,--grep element59 passed,--grep helpers219 passed,--grep platform26 passed,--grep global9 passed,--grep mixed4 passed.eslint src/scales/scale.category.js test/specs/scale.category.tests.js— clean.Fixes #11893