-
Notifications
You must be signed in to change notification settings - Fork 842
Fix labelBackgroundColor to apply to background instead of text #44990
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
Merged
annacmc
merged 10 commits into
trunk
from
fix/charts-100-fix-labelbackgroundcolor-to-apply-to-background-instead-of
Sep 1, 2025
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
e723945
Add labelTextColor property to ChartTheme interface
annacmc 4d5f865
Add labelTextColor to all theme configurations
annacmc e88e975
Fix pie chart labels to use labelTextColor instead of labelBackground…
annacmc 5786cce
Add Storybook controls and documentation for label color properties
annacmc 8f74158
Remove non-functional labelBackgroundColor control from Storybook
annacmc 6941a1d
Implement functional labelBackgroundColor with visual backgrounds
annacmc 9f92832
Set labelBackgroundColor default to transparent to preserve original …
annacmc fa42add
changelog
annacmc 19deb86
Set default label text color to white
annacmc 8fa7534
Fix TypeScript error in Storybook stories
annacmc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
...harts/changelog/fix-charts-100-fix-labelbackgroundcolor-to-apply-to-background-instead-of
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| Significance: minor | ||
| Type: fixed | ||
|
|
||
| Charts: fix label background colour and text colour |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -243,21 +243,42 @@ const PieChartInternal = ( { | |
| pathProps.onMouseLeave = onMouseLeave; | ||
| } | ||
|
|
||
| // Estimate text width more accurately for background sizing | ||
| const fontSize = 12; | ||
| const estimatedTextWidth = arc.data.label.length * fontSize * 0.6; // Rough estimate | ||
| const labelPadding = 6; | ||
| const backgroundWidth = estimatedTextWidth + labelPadding * 2; | ||
| const backgroundHeight = fontSize + labelPadding * 2; | ||
|
|
||
| return ( | ||
| <g key={ `arc-${ index }` }> | ||
| <path { ...pathProps } /> | ||
| { hasSpaceForLabel && ( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should probably skip the rendering if the label is set to empty
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| <text | ||
| x={ centroidX } | ||
| y={ centroidY } | ||
| dy=".33em" | ||
| fill={ providerTheme.labelBackgroundColor || '#333' } | ||
| fontSize={ 12 } | ||
| textAnchor="middle" | ||
| pointerEvents="none" | ||
| > | ||
| { arc.data.label } | ||
| </text> | ||
| <g> | ||
| { providerTheme.labelBackgroundColor && ( | ||
| <rect | ||
| x={ centroidX - backgroundWidth / 2 } | ||
| y={ centroidY - backgroundHeight / 2 } | ||
| width={ backgroundWidth } | ||
| height={ backgroundHeight } | ||
| fill={ providerTheme.labelBackgroundColor } | ||
| rx={ 4 } | ||
| ry={ 4 } | ||
| pointerEvents="none" | ||
| /> | ||
| ) } | ||
| <text | ||
| x={ centroidX } | ||
| y={ centroidY } | ||
| dy=".33em" | ||
| fill={ providerTheme.labelTextColor || '#333' } | ||
| fontSize={ fontSize } | ||
| textAnchor="middle" | ||
| pointerEvents="none" | ||
| > | ||
| { arc.data.label } | ||
| </text> | ||
| </g> | ||
| ) } | ||
| </g> | ||
| ); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.

Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we please try to use
getStringWidthinstead:jetpack/projects/js-packages/charts/src/components/shared/utils.ts
Line 24 in 2cf8757