Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
a3a7941
fallback tickCount to number of tickValues
s77rt Oct 21, 2026
b3c2c02
remove tickCount patch
s77rt Oct 21, 2026
5c46dad
clean up
s77rt Oct 21, 2026
efa838b
fix declaration
s77rt Oct 21, 2026
9aa3b76
compensate for padding
s77rt Oct 21, 2026
6bef6ad
fix axisSIze line height
s77rt Oct 22, 2026
5b49826
guard on tickCount
s77rt Oct 22, 2026
b757f35
add axis sizes to padding resolver
s77rt Oct 22, 2026
c7be0d8
fix overwriting padding
s77rt Oct 22, 2026
811aa94
lint and add comment
s77rt Oct 22, 2026
8e0dc5f
compute lineheight same as victory-native does
s77rt Oct 22, 2026
7cf90da
update golden
s77rt Oct 22, 2026
81e5979
Revert "update golden"
s77rt Oct 22, 2026
964a7c0
Reapply "update golden"
s77rt Oct 22, 2026
da138fc
Merge branch 'main' into victory-native-remove-tickCount-patch
s77rt Oct 22, 2026
47c059a
fix typo
s77rt Oct 22, 2026
4ac1006
take axis size into account when computing dynamic height
s77rt Oct 22, 2026
98cb2ef
Merge branch 'main' into victory-native-remove-tickCount-patch
s77rt Oct 26, 2026
8eb0aba
Revert "Reapply "update golden""
s77rt Oct 26, 2026
cb95071
fallback tickCount to 0
s77rt Oct 26, 2026
5d576c9
always shrink the left padding - as in main
s77rt Oct 26, 2026
d3b4793
apply padding shrink clamp on horizontal charts only
s77rt Oct 26, 2026
31668e1
copy padding
s77rt Oct 26, 2026
a16aa25
compute dynamic height using design padding
s77rt Oct 26, 2026
82ac01b
differentiate between left and right axis shrink guard
s77rt Oct 26, 2026
11b8ebe
lint
s77rt Oct 26, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 0 additions & 16 deletions patches/victory-native/details.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,3 @@
- Upstream PR/issue: Not yet. This is urgent patch with deadline.
- E/App issue: https://github.com/Expensify/App/issues/91883
- PR introducing patch: https://github.com/Expensify/App/pull/91659


### [victory-native+42.0.1+002+tickCount-4121.patch](victory-native+42.0.1+002+tickCount-4121.patch)

- Reason:

```
After updating to v42 the tickCount broke.
This was caused by this commit https://github.com/FormidableLabs/victory-native-xl/pull/664/changes/fcd8affe655878d0bf95ab87c087eab428d4f62d
which fixed some bug but caused us another bug. This small patch reverts it. This is a temporary solution not a real fix.
The fix should address both bugs.
```

- Upstream PR/issue: Not yet.
- E/App issue: https://github.com/Expensify/App/issues/91883
- PR introducing patch: https://github.com/Expensify/App/pull/100186

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ type VictoryChartProviderProps = {

/** Supplies parsed chart config to chart sub-components. Callers must parse and validate the tnode first. */
function VictoryChartProvider({tnode, processedResult, type, children}: VictoryChartProviderProps) {
const {data, xKey, yKeys, xAxis, yAxis, domain, domainPadding, padding, isHorizontal, categories, labelItems, legendItems, pointMetadata} = processedResult;
const {data, xKey, yKeys, xAxis, yAxis, domain, domainPadding, designPadding, padding, isHorizontal, categories, labelItems, legendItems, pointMetadata} = processedResult;
const {nodeStyles: chartContentStyles, parentNodeStyles: chartContainerStyles} = parseStyles(tnode);
const parsedDesignHeight = typeof chartContentStyles.height === 'number' ? chartContentStyles.height : undefined;
const itemCount = categories?.length ?? Object.keys(data).length;
const effectiveChartHeight = computeDynamicChartHeight({
designHeight: parsedDesignHeight,
isHorizontal,
itemCount,
padding,
designPadding,
});
const heightDelta = parsedDesignHeight !== undefined && effectiveChartHeight !== undefined ? parsedDesignHeight - effectiveChartHeight : 0;
const effectiveChartContentStyles = heightDelta > 0 ? {...chartContentStyles, height: effectiveChartHeight} : chartContentStyles;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ function processVictoryChartTree(tnode: TNode, typeface: SkTypeface | null, root
let domain: ProcessNodeResult['domain'];
let domainPadding: ProcessNodeResult['domainPadding'];
let padding: ProcessNodeResult['padding'];
let leftAxisLabelPadding: ProcessNodeResult['leftAxisLabelPadding'];
let leftAxisSize: ProcessNodeResult['leftAxisSize'];
let rightAxisSize: ProcessNodeResult['rightAxisSize'];
let bottomAxisSize: ProcessNodeResult['bottomAxisSize'];
let topAxisSize: ProcessNodeResult['topAxisSize'];
let isHorizontal: ProcessNodeResult['isHorizontal'];
let categories: ProcessNodeResult['categories'];
const labelItems: ProcessNodeResult['labelItems'] = [];
Expand Down Expand Up @@ -52,8 +55,17 @@ function processVictoryChartTree(tnode: TNode, typeface: SkTypeface | null, root
if (result.padding) {
padding = result.padding;
}
if (result.leftAxisLabelPadding !== undefined) {
leftAxisLabelPadding = result.leftAxisLabelPadding;
if (result.leftAxisSize !== undefined) {
leftAxisSize = result.leftAxisSize;
}
if (result.rightAxisSize !== undefined) {
rightAxisSize = result.rightAxisSize;
}
if (result.bottomAxisSize !== undefined) {
bottomAxisSize = result.bottomAxisSize;
}
if (result.topAxisSize !== undefined) {
topAxisSize = result.topAxisSize;
}
if (result.isHorizontal) {
isHorizontal = result.isHorizontal;
Expand Down Expand Up @@ -81,8 +93,12 @@ function processVictoryChartTree(tnode: TNode, typeface: SkTypeface | null, root
yAxis,
domain,
domainPadding,
designPadding: padding,
padding,
leftAxisLabelPadding,
leftAxisSize,
rightAxisSize,
bottomAxisSize,
topAxisSize,
isHorizontal,
categories,
labelItems,
Expand All @@ -109,8 +125,17 @@ function processVictoryChartTree(tnode: TNode, typeface: SkTypeface | null, root
if (childResult.padding) {
padding = childResult.padding;
}
if (childResult.leftAxisLabelPadding !== undefined) {
leftAxisLabelPadding = childResult.leftAxisLabelPadding;
if (childResult.leftAxisSize !== undefined) {
leftAxisSize = childResult.leftAxisSize;
}
if (childResult.rightAxisSize !== undefined) {
rightAxisSize = childResult.rightAxisSize;
}
if (childResult.bottomAxisSize !== undefined) {
bottomAxisSize = childResult.bottomAxisSize;
}
if (childResult.topAxisSize !== undefined) {
topAxisSize = childResult.topAxisSize;
Comment thread
s77rt marked this conversation as resolved.
Resolved
}
if (childResult.isHorizontal) {
isHorizontal = childResult.isHorizontal;
Expand All @@ -131,8 +156,12 @@ function processVictoryChartTree(tnode: TNode, typeface: SkTypeface | null, root
yAxis,
domain,
domainPadding,
padding: resolvePadding(padding, leftAxisLabelPadding),
leftAxisLabelPadding,
designPadding: padding,
padding: resolvePadding(padding, xAxis, yAxis, leftAxisSize, rightAxisSize, bottomAxisSize, topAxisSize, isHorizontal),
leftAxisSize,
rightAxisSize,
bottomAxisSize,
topAxisSize,
isHorizontal,
categories,
labelItems,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {LEFT_AXIS_LABEL_OFFSET_MAX} from '@components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/constants';
import type {PartialProcessNodeResult, ProcessNodeResult} from '@components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/types';
import type {CartesianChartProps, PartialProcessNodeResult, ProcessNodeResult} from '@components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/types';
import getFontGlyphWidth from '@components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/utils/getFontGlyphWidth';
import {
parseAttributeAsNumber,
Expand All @@ -11,20 +11,26 @@ import parseRawAxisStyle from '@components/HTMLEngineProvider/HTMLRenderers/Vict

import type {SkFont, SkTypeface} from '@shopify/react-native-skia';
import type {TNode} from 'react-native-render-html';
import type {XAxisSide, YAxisSide} from 'victory-native';

import {Skia} from '@shopify/react-native-skia';

/**
* The widest rendered label on a left-side y-axis, plus its offset from the axis line —
* i.e. how much horizontal space the axis actually needs for its labels. Used to shrink
* the chart's `padding.left` when the configured value is more than the content needs.
* For y-axis this returns the widest rendered label plus its offset from the axis line
* For x-axis this returns the label line height plus its offset from the axis line
*/
function computeLeftAxisLabelPadding(axisSide: 'left' | 'right', labels: Array<string | number> | undefined, font: SkFont | null, labelOffset: number | undefined): number | undefined {
if (axisSide !== 'left' || !font || !labels?.length) {
function computeAxisSize(axisSide: XAxisSide | YAxisSide, labels: Array<string | number> | undefined, font: SkFont | null, labelOffset: number | undefined): number | undefined {
if (!font || !labels?.length) {
return undefined;
}
if (axisSide === 'bottom' || axisSide === 'top') {
// victory-native uses the font size as the line height
// https://github.com/FormidableLabs/victory-native-xl/blob/de84ff1f3098a2072f8c52ac801ce08141fdb46a/lib/src/utils/textLayout.ts#L18-L42
const lineHeight = font.getSize();
return Math.ceil(lineHeight + 2 * (labelOffset ?? 0));
}
const maxLabelWidth = Math.max(...labels.map((label) => getFontGlyphWidth(String(label), font)));
return maxLabelWidth + (labelOffset ?? 0);
return Math.ceil(maxLabelWidth + (labelOffset ?? 0));
}

/**
Expand All @@ -35,9 +41,9 @@ function parseVictoryAxisNode(tnode: TNode, typeface: SkTypeface | null, rootPro
const isHorizontal = rootProcessedResult?.isHorizontal;
const isDependentAxis = 'dependentaxis' in tnode.attributes && tnode.attributes.dependentaxis !== 'false';
const orientation = parseAttributeAsString(tnode.attributes.orientation);
const tickCount = parseAttributeAsNumber(tnode.attributes.tickcount) ?? 0;
const rawTickValues = parseAttributeAsNumberArray(tnode.attributes.tickvalues);
const tickValues = Array.isArray(rawTickValues) ? rawTickValues : undefined;
const tickCount = parseAttributeAsNumber(tnode.attributes.tickcount) ?? tickValues?.length ?? 0;
const rawTickFormat = parseAttributeAsStringArray(tnode.attributes.tickformat);
const tickFormat = Array.isArray(rawTickFormat) ? rawTickFormat : undefined;
const formatLabel = (label: string | number) => tickFormat?.[tickValues?.indexOf(Number(label)) ?? -1] ?? String(label);
Expand All @@ -46,74 +52,112 @@ function parseVictoryAxisNode(tnode: TNode, typeface: SkTypeface | null, rootPro
// 0 width intentionally avoids drawing grid lines, preserving VictoryChart compatibility
const lineWidth = style?.grid?.strokeWidth !== undefined ? Number(style.grid.strokeWidth) : 0;
const labelColor = style?.tickLabels?.fill !== undefined ? String(style.tickLabels.fill) : undefined;
const labelOffset = style?.tickLabels?.padding !== undefined ? Number(style.tickLabels.padding) : undefined;
const fontSize = style?.tickLabels?.fontSize !== undefined ? Number(style.tickLabels.fontSize) : undefined;
const font = typeface && fontSize ? Skia.Font(typeface, fontSize) : null;
const labelsForMeasurement = tickValues?.map(formatLabel) ?? tickFormat;
const rawLabelOffset = style?.tickLabels?.padding !== undefined ? Number(style.tickLabels.padding) : undefined;

if (isDependentAxis) {
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,
},
],
};
}
if (isHorizontal) {
const axisSide = orientation === 'top' ? 'right' : 'left';
const resolvedLabelOffset = axisSide === 'left' && labelOffset !== undefined ? Math.min(labelOffset, LEFT_AXIS_LABEL_OFFSET_MAX) : labelOffset;
return {
yAxis: [
{
tickCount,
tickValues,
formatYLabel: formatLabel,
axisSide,
lineColor,
lineWidth,
labelColor,
labelOffset: resolvedLabelOffset,
font,
},
],
leftAxisLabelPadding: computeLeftAxisLabelPadding(axisSide, labelsForMeasurement, font, resolvedLabelOffset),
let axisSide: XAxisSide | YAxisSide | undefined;
let labelOffset: number | undefined;
let xAxis: CartesianChartProps['xAxis'] | undefined;
let yAxis: CartesianChartProps['yAxis'] | undefined;

let leftAxisSize: number | undefined;
let rightAxisSize: number | undefined;
let bottomAxisSize: number | undefined;
let topAxisSize: number | undefined;

if (isDependentAxis && isHorizontal) {
axisSide = orientation === 'right' ? 'top' : 'bottom';
labelOffset = rawLabelOffset;
xAxis = {
tickCount,
tickValues,
formatXLabel: formatLabel,
axisSide,
lineColor,
lineWidth,
labelColor,
labelOffset,
font,
};
}
return {
xAxis: {
} else if (isDependentAxis && !isHorizontal) {
axisSide = orientation === 'right' ? 'right' : 'left';
labelOffset = rawLabelOffset;
yAxis = [
{
tickCount,
tickValues,
formatYLabel: formatLabel,
axisSide,
lineColor,
lineWidth,
labelColor,
labelOffset,
font,
},
];
} else if (!isDependentAxis && isHorizontal) {
axisSide = orientation === 'top' ? 'right' : 'left';
labelOffset = axisSide === 'left' && rawLabelOffset !== undefined ? Math.min(rawLabelOffset, LEFT_AXIS_LABEL_OFFSET_MAX) : rawLabelOffset;
yAxis = [
{
tickCount,
tickValues,
formatYLabel: formatLabel,
axisSide,
lineColor,
lineWidth,
labelColor,
labelOffset,
font,
},
];
} else if (!isDependentAxis && !isHorizontal) {
axisSide = orientation === 'top' ? 'top' : 'bottom';
labelOffset = rawLabelOffset;
xAxis = {
tickCount,
tickValues,
formatXLabel: formatLabel,
axisSide: orientation === 'top' ? 'top' : 'bottom',
axisSide,
lineColor,
lineWidth,
labelColor,
labelOffset,
font,
},
};
}

// The axis size is used to reduce the size of the padding since the axis labels consume part of the drawing window
// and we need to compensate for that otherwise the chart will look smaller
if (axisSide) {
const axisSize = computeAxisSize(axisSide, labelsForMeasurement, font, labelOffset);
switch (axisSide) {
case 'left':
leftAxisSize = axisSize;
break;
case 'right':
rightAxisSize = axisSize;
break;
case 'bottom':
bottomAxisSize = axisSize;
break;
case 'top':
topAxisSize = axisSize;
break;
default:
break;
}
}

return {
xAxis,
yAxis,
leftAxisSize,
rightAxisSize,
bottomAxisSize,
topAxisSize,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,12 @@ type ProcessNodeResult = {
yAxis: CartesianChartProps['yAxis'];
domain: CartesianChartProps['domain'];
domainPadding: CartesianChartProps['domainPadding'];
designPadding: CartesianChartProps['padding'];
padding: CartesianChartProps['padding'];
// Pixel width the left y-axis actually needs for its widest label, used to shrink `padding.left` when it's larger than the content requires.
leftAxisLabelPadding: number | undefined;
leftAxisSize: number | undefined;
rightAxisSize: number | undefined;
bottomAxisSize: number | undefined;
topAxisSize: number | undefined;
isHorizontal: boolean | undefined;
categories: string[] | undefined;
labelItems: LabelItem[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,20 @@ type ComputeDynamicChartHeightParams = {
designHeight: number | undefined;
isHorizontal: boolean | undefined;
itemCount: number;
padding: Padding;
designPadding: Padding;
};

/**
* Derives a shorter canvas height for horizontal bar charts that have fewer rows than the
* backend's fixed five-row reference height, keeping row spacing consistent.
*/
function computeDynamicChartHeight({designHeight, isHorizontal, itemCount, padding}: ComputeDynamicChartHeightParams): number | undefined {
function computeDynamicChartHeight({designHeight, isHorizontal, itemCount, designPadding}: ComputeDynamicChartHeightParams): number | undefined {
if (!isHorizontal || designHeight === undefined || itemCount <= 0 || itemCount >= HORIZONTAL_BAR_REFERENCE_ROW_COUNT) {
return designHeight;
}

const paddingTop = getPaddingValue(padding, 'top', DEFAULT_HORIZONTAL_BAR_PADDING.top);
const paddingBottom = getPaddingValue(padding, 'bottom', DEFAULT_HORIZONTAL_BAR_PADDING.bottom);
const paddingTop = getPaddingValue(designPadding, 'top', DEFAULT_HORIZONTAL_BAR_PADDING.top);
const paddingBottom = getPaddingValue(designPadding, 'bottom', DEFAULT_HORIZONTAL_BAR_PADDING.bottom);
const referencePlotHeight = HORIZONTAL_BAR_REFERENCE_HEIGHT - paddingTop - paddingBottom;

if (referencePlotHeight <= 0) {
Expand Down
Loading
Loading