Repository navigation
Conversation
When several category scales have no labels of their own, each one appends its values to the shared data.labels array, so every scale shows categories that belong to the others. Keep inferred labels on the scale that parsed them. A single category scale still writes them into data.labels, and labels supplied by the user are unchanged. Fixes chartjs#11495
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 #11495
Problem
With more than one category scale and no
data.labelsor scalelabels, each scale shows categories from the other scales. A medications axis and an encounters axis both end up labeled "Medications" and "Encounters", and the bars are placed on the wrong index. The same mix happens between a category x scale and a category y scale.Root cause
CategoryScale.parseinfers a missing string label by pushing it onto the array fromgetLabels(). That falls through to the sharedchart.data.labelsarray. Every category scale appends to the same list, so laterbuildTickswalks categories that were parsed by a different scale.Fix
When another category scale exists and the user did not supply labels, the inferred labels stay on the scale that parsed them. One category scale still writes inferred labels into
data.labels.options.labels,data.xLabels,data.yLabels, and a non-emptydata.labelsare unchanged.Tests
Regression coverage in
test/specs/scale.category.tests.js:data.labelsdata.labelsare still sharedThe new assertions failed before the change (
['Medications', 'Encounters']on both scales). The category specs and the full Chrome Karma suite pass afterward, andpnpm run lintpasses.Scope
src/scales/scale.category.jsand the category scale spec. No public options and no change for charts that already pass labels.