Repository navigation
[Payment due @truph01] [NoQA] [Insights] Horizontal bar chart follow-ups: switch narrow layouts and grow height #102321
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
aldo-expensify
merged 15 commits into
Expensify:main
from
software-mansion-labs:@adamgrzybowski/horizontal-bar-charts-follow-ups
Oct 2, 2026
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
94ecb75
Grow horizontal bar chart height instead of skipping category labels
adamgrzybowski 779804f
Switch narrow bar charts to horizontal when category labels don't fit
adamgrzybowski 194c8bb
Centralize bar chart domain padding constants
adamgrzybowski 38efe99
Sync Mobile-Expensify submodule pointer to main
adamgrzybowski 05f535b
Split semicolon-joined JSDoc comment into two sentences
adamgrzybowski f4cc611
Extract shared vertical bar label geometry and drop hook fallback flag
adamgrzybowski e1a83ac
Sync Mobile-Expensify submodule pointer to main
adamgrzybowski d07d8f6
Simplify horizontal bar chart label positioning and padding
adamgrzybowski bf18bad
Fix long chart label width measurement to prevent axis overflow
adamgrzybowski 8c75ace
Cap horizontal chart category labels as a fraction of chart width
adamgrzybowski 6c6ff3e
Sync Mobile-Expensify submodule pointer to main
adamgrzybowski eca44b9
Merge branch 'main' into @adamgrzybowski/horizontal-bar-charts-follow…
mhawryluk 0770458
Fix chart padding
mhawryluk b670264
Merge branch 'main' into @adamgrzybowski/horizontal-bar-charts-follow…
mhawryluk b80ce89
Use compact format for values on chart value axis
mhawryluk 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
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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 |
|---|---|---|
| @@ -1,12 +1,69 @@ | ||
| import {ChartFontsProvider} from '@components/Charts/hooks'; | ||
| import BAR_INNER_PADDING, {VERTICAL_BAR_DOMAIN_PADDING} from '@components/Charts/barChartConstants'; | ||
| import {ChartFontsProvider, useChartFontManager, useChartLabelFormats, useChartLabelLayout, useChartLabelMeasurements} from '@components/Charts/hooks'; | ||
| import {getVerticalBarLabelLayoutInputs, getVerticalBarPlotBounds, getYAxisLabelWidth} from '@components/Charts/utils'; | ||
| import {GLYPH_PADDING, LABEL_ROTATIONS} from '@components/Charts/VictoryTheme'; | ||
|
|
||
| import variables from '@styles/variables'; | ||
|
|
||
| import type {LayoutChangeEvent} from 'react-native'; | ||
|
|
||
| import React, {useState} from 'react'; | ||
| import {View} from 'react-native'; | ||
|
|
||
| import type {BarChartContentProps} from './types'; | ||
|
|
||
| import HorizontalBarChartContentBody from './HorizontalBarChartContent'; | ||
| import VerticalBarChartContentBody from './VerticalBarChartContent'; | ||
|
|
||
| function BarChartContent({isHorizontal = false, ...props}: BarChartContentProps) { | ||
| return <ChartFontsProvider>{isHorizontal ? <HorizontalBarChartContentBody {...props} /> : <VerticalBarChartContentBody {...props} />}</ChartFontsProvider>; | ||
| const FONT_SIZE = variables.iconSizeExtraSmall; | ||
|
|
||
| /** | ||
| * Resolves the bar chart orientation on every layout change and renders the matching body. Wide layouts pass | ||
| * `isHorizontal`. Narrow layouts predict the vertical chart's label fit from the container width, so the chart | ||
| * switches to horizontal bars when labels don't fit even at 45° and back to vertical when the container grows. | ||
| */ | ||
| function BarChartOrientationDispatcher({isHorizontal = false, canFallBackToHorizontalBars = false, ...props}: BarChartContentProps) { | ||
| const fontManager = useChartFontManager(); | ||
| const [containerWidth, setContainerWidth] = useState(0); | ||
| const {data, yAxisUnit, yAxisUnitPosition = 'left'} = props; | ||
|
|
||
| const {formatCompactValue} = useChartLabelFormats({data, unit: yAxisUnit, unitPosition: yAxisUnitPosition}); | ||
| const measurements = useChartLabelMeasurements(data, fontManager, FONT_SIZE); | ||
|
|
||
| // Predict the vertical chart's plot geometry from the container width so the fit decision matches what it would measure after mounting. | ||
| const yAxisLabelWidth = getYAxisLabelWidth(data, formatCompactValue, fontManager, FONT_SIZE, VERTICAL_BAR_DOMAIN_PADDING); | ||
| const plotBounds = getVerticalBarPlotBounds(containerWidth, yAxisLabelWidth + GLYPH_PADDING); | ||
|
|
||
| const {labelRotation} = useChartLabelLayout({ | ||
| data, | ||
| fontManager, | ||
| fontSize: FONT_SIZE, | ||
| measurements, | ||
| ...getVerticalBarLabelLayoutInputs({ | ||
| containerWidth, | ||
| plotLeft: plotBounds.left, | ||
| plotRight: plotBounds.right, | ||
| plotWidth: plotBounds.width, | ||
| dataLength: data.length, | ||
| innerPadding: BAR_INNER_PADDING, | ||
| }), | ||
| }); | ||
|
adamgrzybowski marked this conversation as resolved.
Resolved
|
||
|
|
||
| const renderHorizontal = isHorizontal || (canFallBackToHorizontalBars && labelRotation === LABEL_ROTATIONS.VERTICAL); | ||
|
|
||
| const handleLayout = (event: LayoutChangeEvent) => { | ||
| setContainerWidth(event.nativeEvent.layout.width); | ||
| }; | ||
|
|
||
| return <View onLayout={handleLayout}>{renderHorizontal ? <HorizontalBarChartContentBody {...props} /> : <VerticalBarChartContentBody {...props} />}</View>; | ||
| } | ||
|
|
||
| function BarChartContent(props: BarChartContentProps) { | ||
| return ( | ||
| <ChartFontsProvider> | ||
| <BarChartOrientationDispatcher {...props} /> | ||
| </ChartFontsProvider> | ||
| ); | ||
| } | ||
|
|
||
| export default BarChartContent; | ||
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
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.
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.