-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Shrink VirtualCFO horizontal chart's left-axis padding to fit label width #95995
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
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
a45557b
Shrink VirtualCFO horizontal chart's left-axis padding to fit label w…
luacmartins 599ff8e
Increase left-axis label edge buffer to 32px
luacmartins 330b0fb
Regenerate golden PNG fixtures for 32px left-axis edge buffer
luacmartins 0cf014a
Rename leftAxisLabelSpace to leftAxisLabelPadding and LEFT_AXIS_LABEL…
luacmartins 386bbed
Clamp left category-axis label offset to 16px max
luacmartins 23b3958
Merge branch 'main' into cmartins-updatePadding
luacmartins 36eeaac
Measure fallback tick labels for left-axis padding
luacmartins 573437f
Merge branch 'main' into cmartins-updatePadding
luacmartins a502bce
Merge branch 'main' into cmartins-updatePadding
luacmartins 43889f0
reduce gap
luacmartins 215d4b3
update comment
luacmartins a2f0c47
update golden images
luacmartins 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
Binary file modified
BIN
+48 Bytes
(100%)
...ory-chart-renderer/tests/__golden__/top-employees-by-spend-truncated-labels.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+235 Bytes
(100%)
server/victory-chart-renderer/tests/__golden__/top-employees-by-spend.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
14 changes: 14 additions & 0 deletions
14
...mponents/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/utils/getFontGlyphWidth.ts
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,14 @@ | ||
| import type {SkFont} from '@shopify/react-native-skia'; | ||
|
|
||
| /** | ||
| * Sums glyph advance widths for `text`. Mirrors victory-native's internal label-width | ||
| * calculation so measurements line up with what `CartesianAxis` actually renders. | ||
| */ | ||
| function getFontGlyphWidth(text: string, font: SkFont | null): number { | ||
| if (!font) { | ||
| return 0; | ||
| } | ||
| return font.getGlyphWidths(font.getGlyphIDs(text)).reduce((sum, width) => sum + width, 0); | ||
| } | ||
|
|
||
| export default getFontGlyphWidth; |
17 changes: 17 additions & 0 deletions
17
src/components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/utils/resolvePadding.ts
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,17 @@ | ||
| import {LEFT_AXIS_LABEL_PADDING} from '@components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/constants'; | ||
| import type {ProcessNodeResult} from '@components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/types'; | ||
|
|
||
| import lodashIsObject from 'lodash/isObject'; | ||
|
|
||
| /** | ||
| * Shrinks `padding.left` down to the left axis's measured label width (plus a small edge buffer) | ||
| * whenever the configured padding is wider than the label content actually needs. | ||
| */ | ||
| function resolvePadding(padding: ProcessNodeResult['padding'], leftAxisLabelPadding: ProcessNodeResult['leftAxisLabelPadding']): ProcessNodeResult['padding'] { | ||
| if (leftAxisLabelPadding === undefined || !lodashIsObject(padding) || typeof padding.left !== 'number') { | ||
| return padding; | ||
| } | ||
| return {...padding, left: Math.min(padding.left, Math.ceil(leftAxisLabelPadding) + LEFT_AXIS_LABEL_PADDING)}; | ||
| } | ||
|
|
||
| export default resolvePadding; |
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.
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.
When a horizontal chart supplies multiple left-side y-axis configurations, this assignment overwrites the earlier measurement with the last axis encountered.
yAxisis intentionally accumulated as an array in the same traversal, so a later axis with shorter labels can makeresolvePadding()shrinkpadding.leftbelow the width required by an earlier axis, clipping that axis's labels. Retain the maximum measured width instead of the last value.Useful? React with 👍 / 👎.