Skip to content

Keep the stack order when the first dataset of a stack is hidden - #12331

Open
exclusiveabhi wants to merge 1 commit into
chartjs:masterfrom
exclusiveabhi:fix-stack-order-hidden-dataset
Open

exclusiveabhi wants to merge 1 commit into
chartjs:masterfrom
exclusiveabhi:fix-stack-order-hidden-dataset

Conversation

@exclusiveabhi

Copy link
Copy Markdown

Fixes #11978

When the first dataset of a stack is hidden (for example from the legend), the stacks of a grouped stacked bar chart swap places. In the issue, hiding "Comp 1" moves stack 1 to the left of stack 0, even though "Comp 2" still has visible bars in stack 0.

_getStacks() builds the stack list in the order the stacks are first seen among the visible datasets only. With the first dataset of stack 0 hidden, stack 1 is seen first and takes the first position.

Hidden datasets are now part of that walk, but only to hold the position of a stack that still has visible bars, so the stacks keep their order. A stack with no visible bars still takes no space (#6368), and stacked: false charts are unchanged. The dataset lookup moved to a private getGroupedMetas() helper.

Added a test that hides the first dataset with chart.hide(0) and checks the stack indexes and the bar positions. It fails on master.

@exclusiveabhi

Copy link
Copy Markdown
Author

@LeeLenaleee @etimberg could one of you approve the CI run when you get a chance? This fixes #11978, where hiding the first dataset of a stack from the legend reorders the stacks. Happy to adjust anything.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Stacked Bar Chart with Groups wrong order when hiding the first dataset by clicking on the legend

1 participant