SimpleBarChart Horizontal Bar is too short - doubly subtracts the label width
Closed this issue · 0 comments
Bug summary
We were showing a visualization of the number of session that a merchant could see and the bar was surprising short for the available space.
![image](https://private-user-images.githubusercontent.com/1164344/248384306-a1892410-7882-401e-a8f5-7c10e2728ad3.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjA1MjAxODgsIm5iZiI6MTcyMDUxOTg4OCwicGF0aCI6Ii8xMTY0MzQ0LzI0ODM4NDMwNi1hMTg5MjQxMC03ODgyLTQwMWUtYThmNS03YzEwZTI3MjhhZDMucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDcwOSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA3MDlUMTAxMTI4WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9OWQ3M2M5MDRmMzViZTI3NzM0NjhlOTFiZjE4MTk4Mjc1YmYyZjEyMzM4MjY3M2IxNGNkYTU1N2FlZjEzMDkyMiZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.I-NyEuEUzAd-Klj-ScogbBDm_9Zjt8g9mi6kxrhlikU)
From looking into and debugging the code we found that the label width is subtracted once here and once here. This leads to having the bar be about 20px wide despite the available space being 250px and the label being about 80px wide.
Expected behavior
When available space is approx 242px
And the label takes up approx 90px
Then the bar should be between 100 and 150px wide.
Actual behavior
Bar is only 28px wide
![image](https://private-user-images.githubusercontent.com/1164344/248386171-0810c6ff-2cde-4909-ac9a-8c87fe8f8625.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjA1MjAxODgsIm5iZiI6MTcyMDUxOTg4OCwicGF0aCI6Ii8xMTY0MzQ0LzI0ODM4NjE3MS0wODEwYzZmZi0yY2RlLTQ5MDktYWM5YS04Yzg3ZmU4Zjg2MjUucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDcwOSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA3MDlUMTAxMTI4WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9YTUzNzc3M2JiY2Q5NmFmYjUzNWQ2YjllMjZiNWJiNjgyMzQ2YzVkMmRjNzJhYmI5ZmRlNTg0YTU0MDljNjEzNyZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.8244SNQGhqFDrQi3g0RnCO5_vbB0M9N7kiH-cW9N6y0)
Steps to reproduce the problem
- Render a horizontal bar chart with long X axis labels in terms of number of characters, with a sizeable horizontal space
- See that no matter the values, the bars end up squished
Reduced test case
Reproducible here with 9.4.0 Polaris Viz: https://codesandbox.io/s/shopify-polaris-viz-react-typescript-playground-forked-q9g3st?file=/src/index.tsx
Unable to reproduce with the same code with 8.2.0 Polaris Viz; so it's been introduced since then.
Specifications
- Polaris-Viz version number: 9.4.0
- Browser: Chrome
- Device: M1 Mac OS
- Operating System: M1 Mac OS