diff --git a/patches/victory-native/details.md b/patches/victory-native/details.md
new file mode 100644
index 000000000000..6d7643d39cb3
--- /dev/null
+++ b/patches/victory-native/details.md
@@ -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
+ ```
+
+- 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
diff --git a/patches/victory-native/victory-native+41.20.2+001+horizontal-bars.patch b/patches/victory-native/victory-native+41.20.2+001+horizontal-bars.patch
new file mode 100644
index 000000000000..064636ba22be
--- /dev/null
+++ b/patches/victory-native/victory-native+41.20.2+001+horizontal-bars.patch
@@ -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, 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;
+ 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;
diff --git a/src/components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/components/VictoryChartBarGroup.tsx b/src/components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/components/VictoryChartBarGroup.tsx
index 6a622ee7948e..9a203cd1e0ff 100644
--- a/src/components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/components/VictoryChartBarGroup.tsx
+++ b/src/components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/components/VictoryChartBarGroup.tsx
@@ -7,23 +7,37 @@ import {useVictoryChartRenderArgs} from '@components/HTMLEngineProvider/HTMLRend
import getYKey from '@components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/utils/getYKey';
import parseAttribute from '@components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/utils/parseAttribute';
import parseCornerRadius from '@components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/utils/parseCornerRadius';
+import parseOffset from '@components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/utils/parseOffset';
import parseStyles from '@components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/utils/parseStyles';
-type VictoryCharBarGroupProps = {tnode: TNode};
+type VictoryChartBarGroupProps = {
+ tnode: TNode;
+ isHorizontal?: boolean;
+};
-const BAR_BETWEEN_GROUP_PADDING = 2 / 3;
-const BAR_WITHIN_GROUP_PADDING = BAR_INNER_PADDING;
-
-function VictoryCharBarGroup({tnode}: VictoryCharBarGroupProps) {
+function VictoryChartBarGroup({tnode, isHorizontal}: VictoryChartBarGroupProps) {
const {points, chartBounds} = useVictoryChartRenderArgs();
const barChildren = tnode.children.filter((child) => child.tagName === 'victorybar');
+ const firstBarChild = barChildren.at(0);
+
+ if (!firstBarChild) {
+ return null;
+ }
+
+ const roundedCorners = parseCornerRadius(firstBarChild?.attributes?.cornerradius ?? '');
+ const barWidth = firstBarChild.attributes.barwidth !== undefined ? Number(parseAttribute(firstBarChild.attributes.barwidth)) : undefined;
+ const betweenGroupPadding = barWidth
+ ? parseOffset(tnode.attributes.offset, chartBounds, barChildren.length, barWidth, points[getYKey(firstBarChild)].length, isHorizontal ?? false)
+ : undefined;
+
return (
{barChildren.map((child) => {
const yKey = getYKey(child);
@@ -40,6 +54,6 @@ function VictoryCharBarGroup({tnode}: VictoryCharBarGroupProps) {
);
}
-VictoryCharBarGroup.displayName = 'VictoryCharBarGroup';
+VictoryChartBarGroup.displayName = 'VictoryChartBarGroup';
-export default VictoryCharBarGroup;
+export default VictoryChartBarGroup;
diff --git a/src/components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/components/VictoryChartCartesian.tsx b/src/components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/components/VictoryChartCartesian.tsx
index 753ffb2314f6..de06e6443bba 100644
--- a/src/components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/components/VictoryChartCartesian.tsx
+++ b/src/components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/components/VictoryChartCartesian.tsx
@@ -3,8 +3,6 @@ import {CartesianChart} from 'victory-native';
import {useVictoryChartContext} from '@components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/context/VictoryChartContext';
import {VictoryChartRenderArgsProvider} from '@components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/context/VictoryChartRenderArgsContext';
import getYKey from '@components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/utils/getYKey';
-import parseAttribute from '@components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/utils/parseAttribute';
-import parseDomainPadding from '@components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/utils/parseDomainPadding';
import VictoryChartLabels from './VictoryChartLabels';
import VictoryChartLegend from './VictoryChartLegend';
import VictoryChartSeries from './VictoryChartSeries';
@@ -14,7 +12,7 @@ import VictoryChartSeries from './VictoryChartSeries';
* Labels and legend overlays are handled internally via `renderOutside`.
*/
function VictoryChartCartesian() {
- const {data, xKey, yKeys, xAxis, yAxis, tnode, labelItems, legendItems} = useVictoryChartContext();
+ const {tnode, data, xKey, yKeys, xAxis, yAxis, domain, domainPadding, padding, isHorizontal, labelItems, legendItems} = useVictoryChartContext();
return (
(
@@ -39,6 +37,7 @@ function VictoryChartCartesian() {
))}
diff --git a/src/components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/components/VictoryChartSeries.tsx b/src/components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/components/VictoryChartSeries.tsx
index 571541cb4280..c921c14c920a 100644
--- a/src/components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/components/VictoryChartSeries.tsx
+++ b/src/components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/components/VictoryChartSeries.tsx
@@ -5,7 +5,10 @@ import VictoryChartBar from './VictoryChartBar';
import VictoryChartBarGroup from './VictoryChartBarGroup';
import VictoryChartLine from './VictoryChartLine';
-type VictoryChartSeriesProps = {tnode: TNode};
+type VictoryChartSeriesProps = {
+ tnode: TNode;
+ isHorizontal?: boolean;
+};
type SeriesComponent = (props: VictoryChartSeriesProps) => React.ReactElement | null;
@@ -19,7 +22,7 @@ const SERIES_RENDERERS: Partial> = {
victoryline: VictoryChartLine,
};
-function VictoryChartSeries({tnode}: VictoryChartSeriesProps) {
+function VictoryChartSeries({tnode, isHorizontal}: VictoryChartSeriesProps) {
const SeriesRenderer = SERIES_RENDERERS[tnode.tagName ?? ''];
useEffect(() => {
@@ -33,7 +36,12 @@ function VictoryChartSeries({tnode}: VictoryChartSeriesProps) {
return null;
}
- return ;
+ return (
+
+ );
}
VictoryChartSeries.displayName = 'VictoryChartSeries';
diff --git a/src/components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/context/VictoryChartContext.tsx b/src/components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/context/VictoryChartContext.tsx
index 329e8f690e12..36d801870b00 100644
--- a/src/components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/context/VictoryChartContext.tsx
+++ b/src/components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/context/VictoryChartContext.tsx
@@ -13,6 +13,11 @@ type VictoryChartContextValue = {
yKeys: ProcessNodeResult['yKeys'];
xAxis: ProcessNodeResult['xAxis'];
yAxis: ProcessNodeResult['yAxis'];
+ domain: ProcessNodeResult['domain'];
+ domainPadding: ProcessNodeResult['domainPadding'];
+ padding: ProcessNodeResult['padding'];
+ isHorizontal: ProcessNodeResult['isHorizontal'];
+ categories: ProcessNodeResult['categories'];
labelItems: ProcessNodeResult['labelItems'];
legendItems: ProcessNodeResult['legendItems'];
chartContentStyles: ReturnType['nodeStyles'];
@@ -28,7 +33,7 @@ const VictoryChartContext = createContext(null)
*/
function VictoryChartProvider({tnode, children}: {tnode: TNode; children: React.ReactNode}) {
const {regular: regularTypeface} = useChartDefaultTypeface();
- const {data, xKey, yKeys, xAxis, yAxis, labelItems, legendItems} = processVictoryChartTree(tnode, regularTypeface);
+ const {data, xKey, yKeys, xAxis, yAxis, domain, domainPadding, padding, isHorizontal, categories, labelItems, legendItems} = processVictoryChartTree(tnode, regularTypeface, null);
const {nodeStyles: chartContentStyles, parentNodeStyles: chartContainerStyles} = parseStyles(tnode);
const hasCartesianData = Object.keys(data).length > 0;
@@ -55,6 +60,11 @@ function VictoryChartProvider({tnode, children}: {tnode: TNode; children: React.
yKeys,
xAxis,
yAxis,
+ domain,
+ domainPadding,
+ padding,
+ isHorizontal,
+ categories,
labelItems,
legendItems,
chartContentStyles,
diff --git a/src/components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/parsers/parserRegistry.ts b/src/components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/parsers/parserRegistry.ts
index d20acff2a2cc..91a9f211e56c 100644
--- a/src/components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/parsers/parserRegistry.ts
+++ b/src/components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/parsers/parserRegistry.ts
@@ -1,5 +1,6 @@
import type {NodeParser} from '@components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/types';
import parseVictoryAxisNode from './victoryAxisParser';
+import parseVictoryChartNode from './victoryChartParser';
import parseVictoryLabelNode from './victoryLabelParser';
import parseVictoryLegendNode from './victoryLegendParser';
import parseVictorySeriesNode from './victorySeriesParser';
@@ -9,6 +10,7 @@ import parseVictorySeriesNode from './victorySeriesParser';
* To support a new VictoryChart tag, add a new entry here and create the parser file.
*/
const PARSER_REGISTRY: Partial> = {
+ victorychart: parseVictoryChartNode,
victorybar: parseVictorySeriesNode,
victoryline: parseVictorySeriesNode,
victoryaxis: parseVictoryAxisNode,
diff --git a/src/components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/parsers/processVictoryChartTree.ts b/src/components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/parsers/processVictoryChartTree.ts
index a5f1762d94e8..94504a715c1e 100644
--- a/src/components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/parsers/processVictoryChartTree.ts
+++ b/src/components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/parsers/processVictoryChartTree.ts
@@ -9,17 +9,22 @@ import PARSER_REGISTRY from './parserRegistry';
* Recursively walk the HTML tnode tree, dispatching each node to its registered parser
* and merging the results into a single chart config.
*/
-function processVictoryChartTree(tnode: TNode, typeface: SkTypeface | null): ProcessNodeResult {
+function processVictoryChartTree(tnode: TNode, typeface: SkTypeface | null, rootProcessedResult: ProcessNodeResult | null): ProcessNodeResult {
const data: ProcessNodeResult['data'] = {};
const yKeys: ProcessNodeResult['yKeys'] = [];
let xAxis: ProcessNodeResult['xAxis'];
let yAxis: ProcessNodeResult['yAxis'];
+ let domain: ProcessNodeResult['domain'];
+ let domainPadding: ProcessNodeResult['domainPadding'];
+ let padding: ProcessNodeResult['padding'];
+ let isHorizontal: ProcessNodeResult['isHorizontal'];
+ let categories: ProcessNodeResult['categories'];
const labelItems: ProcessNodeResult['labelItems'] = [];
const legendItems: ProcessNodeResult['legendItems'] = [];
const parser = PARSER_REGISTRY[tnode.tagName ?? ''];
if (parser) {
- const result = parser(tnode, typeface);
+ const result = parser(tnode, typeface, rootProcessedResult);
if (result.data) {
lodashMerge(data, result.data);
}
@@ -32,6 +37,21 @@ function processVictoryChartTree(tnode: TNode, typeface: SkTypeface | null): Pro
if (result.yAxis?.length) {
yAxis = [...(yAxis ?? []), ...result.yAxis];
}
+ if (result.domain) {
+ domain = result.domain;
+ }
+ if (result.domainPadding) {
+ domainPadding = result.domainPadding;
+ }
+ if (result.padding) {
+ padding = result.padding;
+ }
+ if (result.isHorizontal) {
+ isHorizontal = result.isHorizontal;
+ }
+ if (result.categories) {
+ categories = result.categories;
+ }
if (result.labelItems) {
labelItems.push(...result.labelItems);
}
@@ -40,8 +60,11 @@ function processVictoryChartTree(tnode: TNode, typeface: SkTypeface | null): Pro
}
}
+ // If we have `rootProcessedResult` then forward it as is, otherwise we must be the root so pass the data that we just built
+ const rootProcessedNodeResult = rootProcessedResult ?? {data, xKey: X_KEY, yKeys, xAxis, yAxis, domain, domainPadding, padding, isHorizontal, categories, labelItems, legendItems};
+
for (const child of tnode.children) {
- const childResult = processVictoryChartTree(child, typeface);
+ const childResult = processVictoryChartTree(child, typeface, rootProcessedNodeResult);
lodashMerge(data, childResult.data);
yKeys.push(...childResult.yKeys);
if (childResult.xAxis) {
@@ -50,11 +73,26 @@ function processVictoryChartTree(tnode: TNode, typeface: SkTypeface | null): Pro
if (childResult.yAxis?.length) {
yAxis = [...(yAxis ?? []), ...childResult.yAxis];
}
+ if (childResult.domain) {
+ domain = childResult.domain;
+ }
+ if (childResult.domainPadding) {
+ domainPadding = childResult.domainPadding;
+ }
+ if (childResult.padding) {
+ padding = childResult.padding;
+ }
+ if (childResult.isHorizontal) {
+ isHorizontal = childResult.isHorizontal;
+ }
+ if (childResult.categories) {
+ categories = childResult.categories;
+ }
labelItems.push(...childResult.labelItems);
legendItems.push(...childResult.legendItems);
}
- return {data, xKey: X_KEY, yKeys, xAxis, yAxis, labelItems, legendItems};
+ return {data, xKey: X_KEY, yKeys, xAxis, yAxis, domain, domainPadding, padding, isHorizontal, categories, labelItems, legendItems};
}
export default processVictoryChartTree;
diff --git a/src/components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/parsers/victoryAxisParser.ts b/src/components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/parsers/victoryAxisParser.ts
index 6087fc96eae9..b33f9c9f15bd 100644
--- a/src/components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/parsers/victoryAxisParser.ts
+++ b/src/components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/parsers/victoryAxisParser.ts
@@ -1,14 +1,15 @@
import {Skia} from '@shopify/react-native-skia';
import type {SkTypeface} from '@shopify/react-native-skia';
import type {TNode} from 'react-native-render-html';
-import type {PartialProcessNodeResult, RawAxisStyle} from '@components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/types';
+import type {PartialProcessNodeResult, ProcessNodeResult, RawAxisStyle} from '@components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/types';
import parseAttribute from '@components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/utils/parseAttribute';
/**
* Parse axis config from a `` node.
* Dependent axes become yAxis entries; independent axes become the xAxis.
*/
-function parseVictoryAxisNode(tnode: TNode, typeface: SkTypeface | null): PartialProcessNodeResult {
+function parseVictoryAxisNode(tnode: TNode, typeface: SkTypeface | null, rootProcessedResult: ProcessNodeResult | null): PartialProcessNodeResult {
+ const isHorizontal = rootProcessedResult?.isHorizontal;
const isDependentAxis = 'dependentaxis' in tnode.attributes && tnode.attributes.dependentaxis !== 'false';
const orientation = parseAttribute(tnode.attributes.orientation);
const tickCount = parseAttribute(tnode.attributes.tickcount) ?? 0;
@@ -25,35 +26,65 @@ function parseVictoryAxisNode(tnode: TNode, typeface: SkTypeface | null): Partia
const font = typeface ? Skia.Font(typeface, fontSize) : null;
if (isDependentAxis) {
- return {
- yAxis: [
- {
- tickCount,
- tickValues,
- formatYLabel: formatLabel,
- axisSide: orientation === 'right' ? 'right' : 'left',
- lineColor,
- lineWidth,
- labelColor,
- labelOffset,
- font,
- },
- ],
- };
+ return isHorizontal
+ ? {
+ xAxis: {
+ tickCount,
+ tickValues,
+ formatXLabel: formatLabel,
+ axisSide: orientation === 'right' ? 'top' : 'bottom',
+ lineColor,
+ lineWidth,
+ labelColor,
+ labelOffset,
+ font,
+ },
+ }
+ : {
+ yAxis: [
+ {
+ tickCount,
+ tickValues,
+ formatYLabel: formatLabel,
+ axisSide: orientation === 'right' ? 'right' : 'left',
+ lineColor,
+ lineWidth,
+ labelColor,
+ labelOffset,
+ font,
+ },
+ ],
+ };
}
- return {
- xAxis: {
- tickCount,
- tickValues,
- formatXLabel: formatLabel,
- axisSide: orientation === 'top' ? 'top' : 'bottom',
- lineColor,
- lineWidth,
- labelColor,
- labelOffset,
- font,
- },
- };
+ return isHorizontal
+ ? {
+ yAxis: [
+ {
+ tickCount,
+ tickValues,
+ formatYLabel: formatLabel,
+ axisSide: orientation === 'top' ? 'right' : 'left',
+ lineColor,
+ lineWidth,
+ labelColor,
+ labelOffset,
+ font,
+ },
+ ],
+ }
+ : {
+ xAxis: {
+ tickCount,
+ tickValues,
+ formatXLabel: formatLabel,
+ axisSide: orientation === 'top' ? 'top' : 'bottom',
+ lineColor,
+ lineWidth,
+ labelColor,
+ labelOffset,
+ font,
+ },
+ };
}
export default parseVictoryAxisNode;
diff --git a/src/components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/parsers/victoryChartParser.ts b/src/components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/parsers/victoryChartParser.ts
new file mode 100644
index 000000000000..fb39dd45b622
--- /dev/null
+++ b/src/components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/parsers/victoryChartParser.ts
@@ -0,0 +1,20 @@
+import type {TNode} from 'react-native-render-html';
+import type {PartialProcessNodeResult} from '@components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/types';
+import parseCategories from '@components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/utils/parseCategories';
+import parseDomain from '@components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/utils/parseDomain';
+import parseDomainPadding from '@components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/utils/parseDomainPadding';
+import parsePadding from '@components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/utils/parsePadding';
+
+/**
+ * Parse chart config from a `` node.
+ */
+function parseVictoryChartNode(tnode: TNode): PartialProcessNodeResult {
+ const isHorizontal = 'horizontal' in tnode.attributes && tnode.attributes.horizontal !== 'false';
+ const domain = parseDomain(tnode.attributes.domain, isHorizontal);
+ const domainPadding = parseDomainPadding(tnode.attributes.domainpadding, isHorizontal);
+ const padding = parsePadding(tnode.attributes.padding);
+ const categories = parseCategories(tnode.attributes.categories);
+ return {domain, domainPadding, padding, isHorizontal, categories};
+}
+
+export default parseVictoryChartNode;
diff --git a/src/components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/parsers/victorySeriesParser.ts b/src/components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/parsers/victorySeriesParser.ts
index d9930fce5926..79b1ac8234be 100644
--- a/src/components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/parsers/victorySeriesParser.ts
+++ b/src/components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/parsers/victorySeriesParser.ts
@@ -1,6 +1,7 @@
+import type {SkTypeface} from '@shopify/react-native-skia';
import type {TNode} from 'react-native-render-html';
import {X_KEY} from '@components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/constants';
-import type {CartesianChartData, PartialProcessNodeResult, RawChartData} from '@components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/types';
+import type {CartesianChartData, PartialProcessNodeResult, ProcessNodeResult, RawChartData} from '@components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/types';
import getYKey from '@components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/utils/getYKey';
import parseAttribute from '@components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/utils/parseAttribute';
@@ -8,15 +9,26 @@ import parseAttribute from '@components/HTMLEngineProvider/HTMLRenderers/Victory
* Parse data points from a `` or `` node.
* Both series types share the same data structure: an array of {x, y} points.
*/
-function parseVictorySeriesNode(tnode: TNode): PartialProcessNodeResult {
+function parseVictorySeriesNode(tnode: TNode, typeface: SkTypeface | null, rootProcessedResult: ProcessNodeResult | null): PartialProcessNodeResult {
+ const isHorizontal = rootProcessedResult?.isHorizontal;
+ const categories = rootProcessedResult?.categories;
const points = parseAttribute(tnode.attributes.data) ?? [];
const yKey = getYKey(tnode);
const data: Record = {};
for (const point of points) {
- data[point.x] = {
- [X_KEY]: point.x,
- [yKey]: point.y,
- } as CartesianChartData;
+ if (isHorizontal) {
+ // Even though the X-Axis is going to hold the y values on horizontal mode, it's not the independent axis
+ // thus we cannot use `point.y` as the key since two points can have the same y value.
+ data[`${point.y}-${point.x}`] = {
+ [X_KEY]: point.y,
+ [yKey]: typeof point.x === 'number' ? point.x : categories?.indexOf(point.x),
+ } as CartesianChartData;
+ } else {
+ data[point.x] = {
+ [X_KEY]: point.x,
+ [yKey]: point.y,
+ } as CartesianChartData;
+ }
}
return {data, yKeys: [yKey]};
}
diff --git a/src/components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/types.ts b/src/components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/types.ts
index 7fb426a6ef1c..4575207ac169 100644
--- a/src/components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/types.ts
+++ b/src/components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/types.ts
@@ -121,6 +121,11 @@ type ProcessNodeResult = {
yKeys: YKey[];
xAxis: CartesianChartProps['xAxis'];
yAxis: CartesianChartProps['yAxis'];
+ domain: CartesianChartProps['domain'];
+ domainPadding: CartesianChartProps['domainPadding'];
+ padding: CartesianChartProps['padding'];
+ isHorizontal: boolean | undefined;
+ categories: string[] | undefined;
labelItems: LabelItem[];
legendItems: LegendItem[];
};
@@ -128,7 +133,7 @@ type ProcessNodeResult = {
/** Partial slice produced by a single per-tag parser before merging. */
type PartialProcessNodeResult = Partial;
-type NodeParser = (tnode: TNode, typeface: SkTypeface | null) => PartialProcessNodeResult;
+type NodeParser = (tnode: TNode, typeface: SkTypeface | null, rootProcessedResult: ProcessNodeResult | null) => PartialProcessNodeResult;
type ChartType = ValueOf;
diff --git a/src/components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/utils/parseCategories.ts b/src/components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/utils/parseCategories.ts
new file mode 100644
index 000000000000..cbea8c184c0c
--- /dev/null
+++ b/src/components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/utils/parseCategories.ts
@@ -0,0 +1,17 @@
+import lodashIsObject from 'lodash/isObject';
+import parseAttribute from './parseAttribute';
+
+/**
+ * Translate VictoryChart's `categories` attribute into string[].
+ */
+function parseCategories(attribute: string): string[] | undefined {
+ const categories = parseAttribute(attribute);
+ if (lodashIsObject(categories)) {
+ if ('x' in categories && Array.isArray(categories.x)) {
+ return categories.x.map(String);
+ }
+ }
+ return undefined;
+}
+
+export default parseCategories;
diff --git a/src/components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/utils/parseDomain.ts b/src/components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/utils/parseDomain.ts
new file mode 100644
index 000000000000..f5c51cc7c99d
--- /dev/null
+++ b/src/components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/utils/parseDomain.ts
@@ -0,0 +1,29 @@
+import lodashIsObject from 'lodash/isObject';
+import type {CartesianChartProps} from '@components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/types';
+import parseAttribute from './parseAttribute';
+
+type Domain = CartesianChartProps['domain'];
+
+/**
+ * Translate VictoryChart's `domain` attribute into victory-native's `domain` shape.
+ */
+function parseDomain(attribute: string, isHorizontal: boolean): Domain {
+ const domain = parseAttribute(attribute);
+ if (Array.isArray(domain)) {
+ return isHorizontal ? {x: [Number(domain.at(0)), Number(domain.at(1))]} : {y: [Number(domain.at(0)), Number(domain.at(1))]};
+ }
+ if (lodashIsObject(domain)) {
+ let x: [number, number] | undefined;
+ let y: [number, number] | undefined;
+ if ('x' in domain && Array.isArray(domain.x)) {
+ x = [Number(domain.x.at(0)), Number(domain.x.at(1))];
+ }
+ if ('y' in domain && Array.isArray(domain.y)) {
+ y = [Number(domain.y.at(0)), Number(domain.y.at(1))];
+ }
+ return isHorizontal ? {x: y, y: x} : {x, y};
+ }
+ return undefined;
+}
+
+export default parseDomain;
diff --git a/src/components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/utils/parseDomainPadding.ts b/src/components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/utils/parseDomainPadding.ts
index 8c439af02a03..ada97e835b6f 100644
--- a/src/components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/utils/parseDomainPadding.ts
+++ b/src/components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/utils/parseDomainPadding.ts
@@ -7,16 +7,13 @@ type DomainPadding = CartesianChartProps['domainPadding'];
/**
* Translate VictoryChart's `domainPadding` attribute into victory-native's `domainPadding` shape.
*/
-function parseDomainPadding(attribute: string): DomainPadding {
+function parseDomainPadding(attribute: string, isHorizontal: boolean): DomainPadding {
const domainPadding = parseAttribute(attribute);
if (typeof domainPadding === 'number') {
return domainPadding;
}
if (Array.isArray(domainPadding)) {
- return {
- left: Number(domainPadding.at(0)),
- right: Number(domainPadding.at(1)),
- };
+ return isHorizontal ? {bottom: Number(domainPadding.at(0)), top: Number(domainPadding.at(1))} : {left: Number(domainPadding.at(0)), right: Number(domainPadding.at(1))};
}
if (lodashIsObject(domainPadding)) {
let left: number | undefined;
@@ -37,7 +34,7 @@ function parseDomainPadding(attribute: string): DomainPadding {
top = Number(domainPadding.y.at(1));
bottom = Number(domainPadding.y.at(0));
}
- return {left, right, top, bottom};
+ return isHorizontal ? {left: bottom, right: top, top: right, bottom: left} : {left, right, top, bottom};
}
return undefined;
}
diff --git a/src/components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/utils/parseOffset.ts b/src/components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/utils/parseOffset.ts
new file mode 100644
index 000000000000..ffd3dc9da702
--- /dev/null
+++ b/src/components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/utils/parseOffset.ts
@@ -0,0 +1,15 @@
+import type {ChartBounds} from 'victory-native';
+import parseAttribute from './parseAttribute';
+
+/**
+ * Translate VictoryChart's `offset` attribute into victory-native's `betweenGroupPadding` percentage.
+ */
+function parseOffset(attribute: string, chartBounds: ChartBounds, groupCount: number, barWidth: number, pointsCount: number, isHorizontal: boolean): number {
+ const offset = attribute ? Number(parseAttribute(attribute)) : 0;
+ const boundSize = isHorizontal ? chartBounds.top - chartBounds.bottom : chartBounds.right - chartBounds.left;
+ const groupWidth = barWidth + offset * (groupCount - 1);
+ const betweenGroupPadding = 1 - groupWidth * (pointsCount / boundSize);
+ return betweenGroupPadding;
+}
+
+export default parseOffset;
diff --git a/src/components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/utils/parsePadding.ts b/src/components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/utils/parsePadding.ts
new file mode 100644
index 000000000000..5dfd3a06a770
--- /dev/null
+++ b/src/components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/utils/parsePadding.ts
@@ -0,0 +1,37 @@
+import lodashIsObject from 'lodash/isObject';
+import type {CartesianChartProps} from '@components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/types';
+import parseAttribute from './parseAttribute';
+
+type Padding = CartesianChartProps['padding'];
+
+/**
+ * Translate VictoryChart's `padding` attribute into victory-native's `padding` shape.
+ */
+function parsePadding(attribute: string): Padding {
+ const padding = parseAttribute(attribute);
+ if (typeof padding === 'number') {
+ return padding;
+ }
+ if (lodashIsObject(padding)) {
+ let left: number | undefined;
+ let right: number | undefined;
+ let top: number | undefined;
+ let bottom: number | undefined;
+ if ('left' in padding && typeof padding.left === 'number') {
+ left = padding.left;
+ }
+ if ('right' in padding && typeof padding.right === 'number') {
+ right = padding.right;
+ }
+ if ('top' in padding && typeof padding.top === 'number') {
+ top = padding.top;
+ }
+ if ('bottom' in padding && typeof padding.bottom === 'number') {
+ bottom = padding.bottom;
+ }
+ return {left, right, top, bottom};
+ }
+ return undefined;
+}
+
+export default parsePadding;
diff --git a/src/pages/inbox/report/ReportActionCompose/ComposerActionButton.tsx b/src/pages/inbox/report/ReportActionCompose/ComposerActionButton.tsx
index c0f694363919..e9147bd9afd7 100644
--- a/src/pages/inbox/report/ReportActionCompose/ComposerActionButton.tsx
+++ b/src/pages/inbox/report/ReportActionCompose/ComposerActionButton.tsx
@@ -1,3 +1,4 @@
+import React from 'react';
import ComposerActionMenu from './ComposerActionMenu';
import {useComposerEditState} from './ComposerContext';
import ComposerEditingButtons from './ComposerEditingButtons';