Skip to content

Fix scaling behavior for aspect ratio, labels, and legends#91540

Open
daledah wants to merge 14 commits into
Expensify:mainfrom
daledah:fix/91515
Open

Fix scaling behavior for aspect ratio, labels, and legends#91540
daledah wants to merge 14 commits into
Expensify:mainfrom
daledah:fix/91515

Conversation

@daledah
Copy link
Copy Markdown
Contributor

@daledah daledah commented May 24, 2026

Explanation of Change

Fixed Issues

$ #91515
PROPOSAL:

Tests

  1. Open report
  2. Add comment
  3. Note reportID and reportActionID
  4. Run code
const html = `<victorychart domain="{x: [0.5, 12.5], y: [0, 2000]}" domainpadding="{x: 18, y: 0}" height="430" width="680" padding="{top: 126, bottom: 108, left: 96, right: 32}" style="{parent: { backgroundColor: '#F7F2EF', borderRadius: 16, width: '100%', maxWidth: 680}}"><victorylabel x="32" y="40" text='Monthly spend' style="{ fill: '#002E22', fontSize: 17, fontWeight: 700, fontFamily: 'Expensify Neue', }"/><victorylabel x="32" y="62" text='As of: May 6, 12:49 PM PT' style="{ fill: '#73857E', fontSize: 11, fontWeight: 400, fontFamily: 'Expensify Neue', }"/><victorybar barwidth="11" cornerradius="{top: 6, bottom: 6}" style="{data: {fill: '#1E90F2'}}" data="[ {x: 1.13, y: 1080}, {x: 2.13, y: 1225}, {x: 3.13, y: 1375}, {x: 4.13, y: 1600}, {x: 5.13, y: 1630}, {x: 6.13, y: 1725}, {x: 7.13, y: 1400}, {x: 8.13, y: 1685}, {x: 9.13, y: 1725}, {x: 10.13, y: 1800}, {x: 11.13, y: 1800}, {x: 12.13, y: 1800}, ]" labels="[ 'Jan 2025: $1,080', 'Feb 2025: $1,225', 'Mar 2025: $1,375', 'Apr 2025: $1,600', 'May 2025: $1,630', 'Jun 2025: $1,725', 'Jul 2025: $1,400', 'Aug 2025: $1,685', 'Sep 2025: $1,725', 'Oct 2025: $1,800', 'Nov 2025: $1,800', 'Dec 2025: $1,800', ]"/><victorybar barwidth="11" cornerradius="{top: 6, bottom: 6}" style="{data: {fill: '#13C96B'}}" data="[ {x: 0.87, y: 1200}, {x: 1.87, y: 1320}, {x: 2.87, y: 1570}, ]" labels="['Jan 2026: $1,200', 'Feb 2026: $1,320', 'Mar 2026: $1,570']"/><victorybar barwidth="11" cornerradius="{top: 6, bottom: 6}" style="{data: {fill: '#FF6A00'}}" data="[{x: 3.87, y: 1820}]" labels="['Apr 2026: $1,820']"/><victoryaxis tickvalues="[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]" tickformat="['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']" style="{ axis: {stroke: '#E6E1DA', strokeWidth: 1}, ticks: {stroke: 'transparent'}, tickLabels: { fill: '#73857E', fontSize: 11, fontWeight: 500, fontFamily: 'Expensify Neue', padding: 16, }, }"/><victoryaxis dependentaxis tickvalues="[0, 500, 1000, 1500, 2000]" tickformat="['$0', '$500', '$1,000', '$1,500', '$2,000']" style="{ axis: {stroke: 'transparent'}, ticks: {stroke: 'transparent'}, grid: {stroke: '#E6E1DA', strokeWidth: 1}, tickLabels: { fill: '#73857E', fontSize: 11, fontWeight: 500, fontFamily: 'Expensify Neue', padding: 28, }, }"/><victorylegend x="150" y="378" orientation="horizontal" gutter="34" symbolspacer="10" style="{ labels: { fill: '#002E22', fontSize: 13, fontWeight: 500, fontFamily: 'Expensify Neue', }, }" data="[ {name: '2026 spend', symbol: {type: 'circle', fill: '#13C96B', size: 6}}, {name: '2025 spend', symbol: {type: 'circle', fill: '#1E90F2', size: 6}}, {name: 'Last month', symbol: {type: 'circle', fill: '#FF6A00', size: 6}}, ]"/></victorychart>`;

Onyx.merge("reportActions_[report ID]", {
    "[report action ID]": { message: [{ html, type: "COMMENT" }] },
});
  1. Verify the chart looks same as in https://virtual-cfo-charts.netlify.app/
  2. Resize the screen
  3. Verify that: the chart scales uniformly while preserving its aspect ratio and all labels and legends are re-drawn at new coordinates computed by multiplying the base coordinates by the scale factor.
  • Verify that no errors appear in the JS console

Offline tests

Same as tests

QA Steps

// TODO: These must be filled out, or the issue title must include "[No QA]."
Same as tests

  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.ts or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If new assets were added or existing ones were modified, I verified that:
    • The assets are optimized and compressed (for SVG files, run npm run compress-svg)
    • The assets load correctly across all supported platforms.
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari
Screen.Recording.2026-05-25.at.15.23.37.mov

@daledah
Copy link
Copy Markdown
Contributor Author

daledah commented May 24, 2026

@codex review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9017c386f0

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@codecov
Copy link
Copy Markdown

codecov Bot commented May 24, 2026

Codecov Report

❌ Looks like you've decreased code coverage for some files. Please write tests to increase, or at least maintain, the existing level of code coverage. See our documentation here for how to interpret this table.

Files with missing lines Coverage Δ
...ChartRenderer/components/VictoryChartContainer.tsx 4.54% <0.00%> (-9.75%) ⬇️
... and 9 files with indirect coverage changes

@daledah
Copy link
Copy Markdown
Contributor Author

daledah commented May 24, 2026

@codex review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 197f8b465b

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@daledah
Copy link
Copy Markdown
Contributor Author

daledah commented May 25, 2026

@codex review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3e34df108e

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@daledah daledah marked this pull request as ready for review May 25, 2026 08:37
@daledah daledah requested review from a team as code owners May 25, 2026 08:37
@melvin-bot melvin-bot Bot requested review from heyjennahay and situchan and removed request for a team May 25, 2026 08:37
@melvin-bot
Copy link
Copy Markdown

melvin-bot Bot commented May 25, 2026

@situchan Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@melvin-bot melvin-bot Bot removed the request for review from a team May 25, 2026 08:37
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 741a80dbe0

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@luacmartins
Copy link
Copy Markdown
Contributor

@situchan let's prioritize this review please!

@situchan
Copy link
Copy Markdown
Contributor

yes on it

@github-actions
Copy link
Copy Markdown
Contributor

🚧 @luacmartins has triggered a test Expensify/App build. You can view the workflow run here.

@github-actions

This comment has been minimized.

Copy link
Copy Markdown
Contributor

@situchan situchan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add some tests to make codecov happey

@MelvinBot
Copy link
Copy Markdown
Contributor

Code Review

The overall approach — scale context provided at the container level, passed as explicit props into the Skia Canvas tree — is architecturally sound. A few issues to address:


1. aspectRatio is ignored because height is never cleared (bug)

In VictoryChartContainer.tsx, the explicit-dimensions style merges chartContentStyles (which contains the original numeric height from parseStyles) and then adds aspectRatio:

[styles.chartContent, chartContentStyles, {width: chartWidth, aspectRatio: designWidth / designHeight}]

React Native ignores aspectRatio when both width and height are set. Since chartContentStyles already contains height: 430 (from the HTML attribute), height never shrinks when the container narrows. This means scale.y is always 1.0, and Y-positioned labels/legends won't scale vertically to match the chart — they'll drift out of alignment.

Fix: Override height to undefined (or 'auto') in the explicit-dimensions style so aspectRatio can drive the height:

[styles.chartContent, chartContentStyles, {width: chartWidth, height: undefined, aspectRatio: designWidth / designHeight}]

2. initialMeasurement naming is misleading but behavior is fine

The name suggests it's captured once, but setInitialMeasurement runs on every layout event. The naming could cause confusion for future readers. Consider renaming to lastMeasurement or containerMeasurement.


3. Codecov coverage

Per the reviewer comment from situchan: the new VictoryChartScaleContext and the scaling logic in VictoryChartContainer could use unit tests — especially for the scale computation and the chartWidth clamping logic. Extracting the pure computation (scale factor from dimensions, chart width from container/window) into testable utilities would help.


Summary

Issue 1 is a functional bug that will prevent vertical scaling from working. Issues 2–3 are non-blocking improvements. The rest of the implementation (prop-drilling scale into Skia components, uniform scale for font sizes, horizontal scroll threshold) looks correct.

@situchan
Copy link
Copy Markdown
Contributor

When resize window, blank chat shows before new resized chat is rendered. And sometimes chart glitches.

resize.mov

@situchan
Copy link
Copy Markdown
Contributor

Not scrollable on native. Works on mobile web.

iOS:

Screen.Recording.2026-05-25.at.9.11.23.PM.mov

resized web:

Screen.Recording.2026-05-25.at.9.11.48.PM.mov

@daledah
Copy link
Copy Markdown
Contributor Author

daledah commented May 26, 2026

@shawnborton @situchan does this look better?

Screen.Recording.2026-05-26.at.16.16.29.mov

@shawnborton
Copy link
Copy Markdown
Contributor

Hmm no, it doesn't look good to me:

  • the animation feels super super choppy
  • the resizing should only happen when the chart is too wide for the container. It has a max-width of 680px, and then from there it should shrink with the container. It seems like in your video, there is still room on the right yet the chart is shrinking.

Can you please review my POC and see the expected behavior from there? We also have existing charts in the product that can adjust their width fluidly as well.

@luacmartins
Copy link
Copy Markdown
Contributor

@daledah please prioritize this PR when you're online since we have a deadline of Jun 1 for it

@daledah
Copy link
Copy Markdown
Contributor Author

daledah commented May 27, 2026

the resizing should only happen when the chart is too wide for the container. It has a max-width of 680px, and then from there it should shrink with the container. It seems like in your video, there is still room on the right yet the chart is shrinking.

i fixed

@github-actions
Copy link
Copy Markdown
Contributor

🚧 @shawnborton has triggered a test Expensify/App build. You can view the workflow run here.

@github-actions

This comment has been minimized.

@daledah
Copy link
Copy Markdown
Contributor Author

daledah commented May 27, 2026

Not scrollable on native. Works on mobile web.

@MelvinBot, please check this comment and share any ideas you might have

@MelvinBot
Copy link
Copy Markdown
Contributor

The scroll issue on native is caused by victory-native's CartesianChart wrapping its content in a GestureHandlerRootView with a GestureDetector that registers a Pan gesture (used for chart press/tooltip interactions). On native, this pan gesture competes with the parent horizontal ScrollView's scroll gesture and wins, consuming the touch events. On web, browser-native overflow scrolling takes precedence, so it works there.

Possible fixes:

  1. waitFor / simultaneousHandlers on the inner gesture: If CartesianChart exposes a gestureHandlerConfig prop, you could pass waitFor referencing the outer ScrollView's gesture handler so the chart's pan gesture yields to the scroll. However, victory-native may not expose enough control here.

  2. Wrap the ScrollView with GestureHandlerRootView and use a native ScrollView from react-native-gesture-handler: Import ScrollView from react-native-gesture-handler instead of the RN one. RNGH's ScrollView is gesture-handler-aware and coordinates with nested GestureDetector components, which should allow the horizontal scroll to work alongside the chart gestures.

  3. Disable chart gestures when scrolling is needed: Since the chart press interaction requires activateAfterLongPress(100), the pan gesture should theoretically fail on quick horizontal swipes. If the CartesianChart accepts a chartPressConfig prop, you could set pan.failOffsetX to a small value (e.g., [-5, 5]) so horizontal swipes fail the chart gesture and propagate to the ScrollView.

I'd start with option 2 — replacing the ScrollView import with react-native-gesture-handler's version — as it's the most standard way to solve nested gesture conflicts in RN and requires minimal code change.

@shawnborton
Copy link
Copy Markdown
Contributor

@daledah are you testing your changes? It is still scaling even when it has plenty of room on the right side:

CleanShot.2026-05-27.at.09.33.40.mp4

@daledah
Copy link
Copy Markdown
Contributor Author

daledah commented May 27, 2026

@daledah are you testing your changes? It is still scaling even when it has plenty of room on the right side:

@shawnborton That's quite strange. This is the result on my side when testing with https://91540.pr-testing.expensify.com ^. I'll double-check it.

web-resize.mp4

@shawnborton
Copy link
Copy Markdown
Contributor

Oh interesting, that looks better but why does the chart scroll horizontally? Again, can you look at the POC link we provided? That has the behavior we want, I think.

@daledah
Copy link
Copy Markdown
Contributor Author

daledah commented May 27, 2026

Thanks s77rt, I've updated the code to only scale the top padding inside the chart. Here are the results after the update with the html on OP cc @shawnborton

web-resize.mp4

@shawnborton
Copy link
Copy Markdown
Contributor

The graph itself is definitely not scaling correctly, you can see that the bars overlap and that the font sizes aren't changing:
CleanShot 2026-05-27 at 11 46 41@2x

Can you please review the POC I created?

@daledah
Copy link
Copy Markdown
Contributor Author

daledah commented May 27, 2026

web-resize.mp4

@shawnborton Could you check again? I think it looks very similar to the POC you shared.

@s77rt
Copy link
Copy Markdown
Member

s77rt commented May 27, 2026

@daledah Can you test on native too? (just to make sure the styles.mw100 style is respected, the yoga layout engine is not 100% same as web)

@github-actions
Copy link
Copy Markdown
Contributor

🚧 @shawnborton has triggered a test Expensify/App build. You can view the workflow run here.

@shawnborton
Copy link
Copy Markdown
Contributor

This is looking much better.

But what's interesting... it seems like the border radius is not scaling with the chart. Why don't we have the background color and border radius baked into the chart object so it also scales down?

Otherwise it seems like we're simply wrapping this...
CleanShot 2026-05-27 at 13 02 47@2x

@daledah
Copy link
Copy Markdown
Contributor Author

daledah commented May 28, 2026

But what's interesting... it seems like the border radius is not scaling with the chart. Why don't we have the background color and border radius baked into the chart object so it also scales down?

i updated

web-resize.mp4

@daledah
Copy link
Copy Markdown
Contributor Author

daledah commented May 28, 2026

@daledah Can you test on native too? (just to make sure the styles.mw100 style is respected, the yoga layout engine is not 100% same as web)

Still trying to find a solution for the native. @s77rt @situchan do you have any ideas on how to fix it?

@shawnborton
Copy link
Copy Markdown
Contributor

Cool, let me know when this is ready for another round of testing or builds.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants