Repository navigation
[Payment due @situchan] [No QA] Victory Chart: Support horizontal bars #91659
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
26 commits
Select commit
Hold shift + click to select a range
1305d5b
add domain, domainPadding and padding to context
s77rt 837647c
add parsePadding and parseDomain
s77rt e843d84
add isHorizontal param
s77rt a2df0ef
pass rootProcessedResult to children to get access to isHorizontal
s77rt 7b3d23f
update comment
s77rt 3543be6
make domain and domainPadding aware of isHorizontal
s77rt c743bf4
axix horizontal bar support
s77rt adc0af3
remove comments
s77rt 1807152
add categories and handle data for horizontal bars
s77rt df3367f
remove console log
s77rt ce14f7c
lint
s77rt 7ec4ce9
pass down isHorizontal
s77rt 99e160e
add victory-native patch to support horizontal bars
s77rt 24bc5e0
parse group offset
s77rt cbf63d9
lint
s77rt 28eb0a1
Apply suggestions from code review
s77rt 55e3ae6
fix componenet name
s77rt c47f651
typo
s77rt e31e06f
Merge branch 'main' into horizontal-charts
s77rt d5c4676
fix crash on main
s77rt 4c9f399
fix patch corder radius values
s77rt 394184b
key data by x and y values for horizontal mode
s77rt 9050737
fallback if barWidth is not set
s77rt 14cab87
typo
s77rt e3398c2
fix displayName
s77rt ca27658
handle barWidth and betweenGroupPadding fallback
s77rt 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
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,13 @@ | ||
| # `victory-native` patches | ||
|
|
||
| ### [victory-native+41.20.2+001+horizontal-bars.patch](victory-native+41.20.2+001+horizontal-bars.patch) | ||
|
|
||
| - Reason: | ||
|
|
||
| ``` | ||
| This patch adds support to horizontal bars when rendered in <BarGroup /> | ||
| ``` | ||
|
|
||
| - Upstream PR/issue: Not yet. This is urgent patch with deadline. | ||
| - E/App issue: https://github.com/Expensify/Expensify/issues/636601 | ||
| - PR introducing patch: https://github.com/Expensify/App/pull/91659 |
111 changes: 111 additions & 0 deletions
111
patches/victory-native/victory-native+41.20.2+001+horizontal-bars.patch
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,111 @@ | ||
| diff --git a/node_modules/victory-native/dist/cartesian/components/BarGroup.d.ts b/node_modules/victory-native/dist/cartesian/components/BarGroup.d.ts | ||
| index b486f76..45788f0 100644 | ||
| --- a/node_modules/victory-native/dist/cartesian/components/BarGroup.d.ts | ||
| +++ b/node_modules/victory-native/dist/cartesian/components/BarGroup.d.ts | ||
| @@ -16,6 +16,7 @@ type BarGroupProps = { | ||
| groupWidth: number; | ||
| gapWidth: number; | ||
| }) => void; | ||
| + isHorizontal?: boolean; | ||
| }; | ||
| export declare function BarGroup({ betweenGroupPadding, withinGroupPadding, chartBounds, roundedCorners, children, onBarSizeChange, barWidth: customBarWidth, barCount, }: BarGroupProps): React.DetailedReactHTMLElement<React.InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>[] | null; | ||
| export declare namespace BarGroup { | ||
| diff --git a/node_modules/victory-native/dist/cartesian/hooks/useBarGroupPaths.d.ts b/node_modules/victory-native/dist/cartesian/hooks/useBarGroupPaths.d.ts | ||
| index 63b69bc..75641b1 100644 | ||
| --- a/node_modules/victory-native/dist/cartesian/hooks/useBarGroupPaths.d.ts | ||
| +++ b/node_modules/victory-native/dist/cartesian/hooks/useBarGroupPaths.d.ts | ||
| @@ -1,6 +1,6 @@ | ||
| import type { ChartBounds, PointsArray } from "../../types"; | ||
| import { type RoundedCorners } from "../../utils/createRoundedRectPath"; | ||
| -export declare const useBarGroupPaths: (points: PointsArray[], chartBounds: ChartBounds, betweenGroupPadding?: number, withinGroupPadding?: number, roundedCorners?: RoundedCorners, customBarWidth?: number, barCount?: number) => { | ||
| +export declare const useBarGroupPaths: (points: PointsArray[], chartBounds: ChartBounds, betweenGroupPadding?: number, withinGroupPadding?: number, roundedCorners?: RoundedCorners, customBarWidth?: number, barCount?: number, isHorizontal?: boolean) => { | ||
| barWidth: number; | ||
| groupWidth: number; | ||
| gapWidth: number; | ||
| diff --git a/node_modules/victory-native/src/cartesian/components/BarGroup.tsx b/node_modules/victory-native/src/cartesian/components/BarGroup.tsx | ||
| index f46fad7..ad75c04 100644 | ||
| --- a/node_modules/victory-native/src/cartesian/components/BarGroup.tsx | ||
| +++ b/node_modules/victory-native/src/cartesian/components/BarGroup.tsx | ||
| @@ -20,6 +20,7 @@ type BarGroupProps = { | ||
| groupWidth: number; | ||
| gapWidth: number; | ||
| }) => void; | ||
| + isHorizontal?: boolean; | ||
| }; | ||
|
|
||
| export function BarGroup({ | ||
| @@ -31,6 +32,7 @@ export function BarGroup({ | ||
| onBarSizeChange, | ||
| barWidth: customBarWidth, | ||
| barCount, | ||
| + isHorizontal, | ||
| }: BarGroupProps) { | ||
| // Collect the bar props | ||
| const bars = [] as BarGroupBarProps[]; | ||
| @@ -49,6 +51,7 @@ export function BarGroup({ | ||
| roundedCorners, | ||
| customBarWidth, | ||
| barCount, | ||
| + isHorizontal, | ||
| ); | ||
|
|
||
| // Handle bar size change | ||
| diff --git a/node_modules/victory-native/src/cartesian/hooks/useBarGroupPaths.ts b/node_modules/victory-native/src/cartesian/hooks/useBarGroupPaths.ts | ||
| index 4bfb6d4..9805bfe 100644 | ||
| --- a/node_modules/victory-native/src/cartesian/hooks/useBarGroupPaths.ts | ||
| +++ b/node_modules/victory-native/src/cartesian/hooks/useBarGroupPaths.ts | ||
| @@ -15,17 +15,19 @@ export const useBarGroupPaths = ( | ||
| roundedCorners?: RoundedCorners, | ||
| customBarWidth?: number, | ||
| barCount?: number, | ||
| + isHorizontal?: boolean, | ||
| ) => { | ||
| const numGroups = points[0]?.length || 0; | ||
|
|
||
| - const { yScale } = useCartesianChartContext(); | ||
| + const { xScale, yScale } = useCartesianChartContext(); | ||
|
|
||
| const groupWidth = React.useMemo(() => { | ||
| + const boundSize = isHorizontal ? chartBounds.top - chartBounds.bottom : chartBounds.right - chartBounds.left; | ||
| return ( | ||
| - ((1 - betweenGroupPadding) * (chartBounds.right - chartBounds.left)) / | ||
| + ((1 - betweenGroupPadding) * boundSize) / | ||
| Math.max(1, numGroups) | ||
| ); | ||
| - }, [betweenGroupPadding, chartBounds.left, chartBounds.right, numGroups]); | ||
| + }, [betweenGroupPadding, chartBounds, numGroups, isHorizontal]); | ||
|
|
||
| const barWidth = React.useMemo(() => { | ||
| if (customBarWidth) return customBarWidth; | ||
| @@ -46,19 +48,24 @@ export const useBarGroupPaths = ( | ||
| const offset = -groupWidth / 2 + i * (barWidth + gapWidth); | ||
| pointSet.forEach(({ x, y, yValue }) => { | ||
| if (typeof y !== "number") return; | ||
| - const barHeight = yScale(0) - y; | ||
| + const barHeight = isHorizontal ? xScale(0) - x : yScale(0) - y; | ||
|
s77rt marked this conversation as resolved.
Resolved
|
||
| if (roundedCorners) { | ||
| const nonUniformRoundedRect = createRoundedRectPath( | ||
| - x + offset, | ||
| - y, | ||
| - barWidth, | ||
| - barHeight, | ||
| - roundedCorners, | ||
| + isHorizontal ? x : x + offset, | ||
| + isHorizontal ? y + offset : y, | ||
| + isHorizontal ? barHeight : barWidth, | ||
| + isHorizontal ? barWidth : barHeight, | ||
| + isHorizontal ? {topLeft: roundedCorners.bottomLeft, topRight: roundedCorners.topLeft, bottomLeft: roundedCorners.bottomRight, bottomRight: roundedCorners.topRight} : roundedCorners, | ||
| Number(yValue), | ||
| ); | ||
| p.addRRect(nonUniformRoundedRect); | ||
| } else { | ||
| - p.addRect(Skia.XYWHRect(x + offset, y, barWidth, barHeight)); | ||
| + p.addRect(Skia.XYWHRect( | ||
| + isHorizontal ? x : x + offset, | ||
| + isHorizontal ? y + offset : y, | ||
| + isHorizontal ? barHeight : barWidth, | ||
| + isHorizontal ? barWidth : barHeight, | ||
| + )); | ||
| } | ||
| }); | ||
| return p; | ||
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
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.