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

[SimpleBarChart] Horizontal bars become compressed when legend wraps onto multiple lines #1565

Open
acmertz opened this issue Jul 24, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@acmertz
Copy link
Contributor

acmertz commented Jul 24, 2023

Bug summary

The thickness of bars rendered in a <SimpleBarChart> are currently determined automatically based on the chart height that was set in chartContainer.minHeight on the theme definition. Although this appears to be an intentional behavior in the code so that everything (including the legend) fits within the provided bounds, it can lead to situations where bar charts that are supposed to look similar actually render bars with vastly different heights because their legends take up a different amount of space.

Current behavior

fixed-chart-height-with-wrapping-legend.mp4

Desired behavior

We've worked around this behavior by using the renderLegendContent prop to render a custom legend with height: 0 and overflow: visible, and then using a ResizeObserver to monitor the height of the legend's children so we could apply padding to the container to reserve enough space so that the legend doesn't visually clip the bottom bound.

Despite its naming convention, chartContainer.minHeight is treated as a fixed height in ChartDimensions.tsx and the chart does not expand vertically when the legend wraps.

Implementing one of the following options (or similar) could alleviate the need for workarounds to maintain a stable bar height:

  • Add a prop to configure the height of the bars
  • Add an option to let the legend flow beneath the chart instead of reserving space within the bounds

Reduced test case

https://codesandbox.io/s/polaris-viz-wrapping-legend-with-fixed-chart-height-m438th?file=/src/index.tsx

Open the code sandbox and resize the preview area so that the legend reflows onto multiple lines. The horizontal bars get narrower as the legend takes up more vertical space.

Specifications

  • Polaris-Viz version number: v9.8.1
  • Browser: Chrome 115
  • Device: MacBook Pro with M1 Pro
  • Operating System: macOS Ventura 13.4.1
@acmertz acmertz added the bug Something isn't working label Jul 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant