bug: s2 chart title wrap #825
Conversation
…ec signal to wrap the title text when it is long or there is not enough space
| }; | ||
|
|
||
| // Average character width ratio for adobe-clean at the title font size | ||
| const AVG_CHAR_WIDTH_RATIO = 0.5; |
There was a problem hiding this comment.
This may not be dynamic enough.
Title accepts fontWeight. We might be able to estimate size using the fontWeight value, but we have an existing expression function that draws the actual text to get the exact size.
If we could either use that or make a title specific function (if necessary), we wouldn't have to worry about future props effecting this size either.
There was a problem hiding this comment.
yeah, this was my biggest concern with this solution. Let me try using this existing function!
…de into the story utils file to reduce duplicate code
…e text width representation, updated tests
… jumpy re-rendering
|
|
🎨 Storybook -> https://opensource.adobe.com/react-spectrum-charts/PR-825 🎨 S2 Storybook -> https://opensource.adobe.com/react-spectrum-charts/PR-825-s2 📚 Docs -> https://opensource.adobe.com/react-spectrum-charts/PR-825-docs/ |


Implementing an expression function that is used in the title spec signal to wrap the title text when it is long or there is not enough space.
wrapTitleText(): calculates the max number of characters allowed per line based on the width of the chart and an estimated size of the text. separates each word out into an array, adds words to that line until the next word will exceed the limit, and then makes a new array entry.Related Issue
Motivation and Context
Solves when a chart title is too long to fit on a single line within the chart's container width, the current S2 implementation shrinks the chart horizontally to accommodate the overflowing title text rather than wrapping the title onto multiple lines. This causes the data visualization area to contract unexpectedly and is visually broken for long or dynamic title strings.
How Has This Been Tested?
Unit testing the new function to wrap test, visible testing in storybook.
Screenshots (if appropriate):
Types of changes
Checklist: