Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for stacked bars with a mix of strings and numbers in the x-axis #1884

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

reganperkins
Copy link

@reganperkins reganperkins commented Oct 30, 2024

🐛 Bug Fix

issue

If stacked bars have a mix of string and number values in the x-axis, the order breaks the stacked bars. This makes it look like the data is correct but the values in the data do not match the values shown in the chart.

example

https://codesandbox.io/p/sandbox/vibrant-joana-hht45t
in the example above if you look at L2 Males the tooltips show 10 but the value should really be 30 (ie its showing the values for L2, not 1)

solution

The issue was in visx/xycharts/lib/utils/combineBarStackData the order was being lost due to an object being used to hold dataByStackValue. Objects do not follow a consistent ordering. If we change this to use a Map we are guaranteed to have the keys be iterated in order of insertion

fix

use a Map rather than an object to store the data, this preserves the order of the data and prevents issues when the x columns are a mix of numbers and strings

… order of the data and prevents issues when the x columns are a mix of numbers and strings
@reganperkins reganperkins changed the title use a Map rather then an object to store the data, this preserves the… Fix for stacked bars with a mix of strings and numbers in the x-axis Nov 1, 2024
@reganperkins reganperkins reopened this Nov 1, 2024
@reganperkins reganperkins marked this pull request as ready for review November 1, 2024 18:39
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.

1 participant