Skip to content

[$250] Chart should maintain aspect ratio when window/screen size changes #92147

Closed

Description

@melvin-bot

Problem

The chart does not maintain its aspect ratio when the window (or screen) size changes. Instead, it shrinks in an awkward, non-proportional way. The expected behavior is that the chart should scale uniformly — like any other image — so that the entire chart shrinks proportionally as the viewport shrinks.

This is a general issue on web, but critical on mobile where screen real estate is limited and non-uniform scaling can make the chart unusable.

Expected behavior

When the window or screen size changes, the chart should scale proportionally (maintaining its aspect ratio), similar to how a standard <img> element would respond to a responsive container.

Actual behavior

The chart shrinks in a disproportionate/unexpected way when the viewport is reduced, rather than scaling uniformly.

Platforms affected

  • Web
  • Mobile (iOS / Android) — high priority

Notes

Maintaining aspect ratio is a core UX concern on mobile given the limited screen size. A responsive, aspect-ratio-preserving layout is the correct behavior.

Upwork Automation - Do Not Edit

Activity

  1. added
    ImprovementItem broken or needs improvement.
    BugSomething is broken. Auto assigns a BugZero manager.
    on May 30, 2026
  2. MelvinBot commented on May 30, 2026

    @MelvinBot
    Contributor

    ℹ️ This looks like a duplicate of #91515 (status: Reviewing), which tracks the same Victory Chart aspect-ratio bug introduced in #90253. The analysis below is provided in case it's useful while triaging.

    Proposal

    What is the root cause of that problem?

    The Victory Chart container has a fixed pixel height but a fluid width, so as the viewport shrinks the chart compresses horizontally while its height stays constant — aspect ratio is not preserved.

    Specifically, the chartContent style hard-codes height: 250 while the outer wrappers apply maxWidth: '100%':

    Mobile and web share the same code path (the .native.tsx variant just re-exports BaseVictoryChartRenderer), so the bug manifests identically — but it's more painful on mobile where the viewport is small and the squashing is more pronounced.

    What changes do you think we should make in order to solve the problem?

    Drive sizing by an aspect ratio derived from the <victorychart width="..." height="..."> HTML attributes, instead of a constant pixel height:

    1. In parseStyles.ts, when both width and height are provided on the <victorychart> element, emit aspectRatio: parsedWidth / parsedHeight into the parsed style (and stop emitting a fixed height).
    2. In VictoryChartContainer.tsx, let the parsed aspectRatio win over chartContent.height. Keep minHeight: CHART_CONTENT_MIN_HEIGHT as a floor so very narrow viewports don't collapse the chart entirely.
    3. If no width/height attributes are present, fall back to a sensible default aspect ratio (e.g. matching the current 680×430 ≈ 1.58) instead of fixed height.

    aspectRatio is supported by both React Native and the web. This makes the chart scale uniformly on resize without any transform tricks.

    What alternative solutions did you explore? (Optional)

    • transform: scale(s) on the outer wrapper — rejected: doesn't change layout flow on web, and the Skia canvas in victory-native's CartesianChart would still rasterize at the original size, producing blurry/clipped output.
    • SVG viewBox + preserveAspectRatio — not applicable: the rendering goes through victory-native's CartesianChart (Skia), not a raw SVG, so there's no viewBox to set at the top level.
    Data flow evidence
    1. Chat HTML contains <victorychart width=W height=H> (introduced in #90253)
    2. VictoryChartRenderer → BaseVictoryChartRenderer → VictoryChartContainer
    3. VictoryChartContainer renders nested Views: outer mw100 + chartContainer, inner mw100 + chartContent (fixed height 250px)
    4. parseStyles accepts explicit width/height numbers but does NOT compute aspect ratio — the fixed chartContent.height wins
    5. CartesianChart fills its parent View, so the Skia canvas's coordinate space gets non-uniformly remapped on resize, compressing bars/lines horizontally

    Related issues

    • #91515 — same aspect-ratio bug, currently in Reviewing. The contributor team should consider closing this issue as a duplicate.

    Next Steps for Contributor+ team:
    To accept: @MelvinBot implement [this](https://github.com/Expensify/App/issues/92147) to create a draft PR.
    To refine: @MelvinBot <your feedback>
    To reject: Explain why you are rejecting Melvin's proposal.

  3. added
    ExternalAdded to denote the issue can be worked on by a contributor
    on May 30, 2026
  4. added
    Help WantedApply this label when an issue is open to proposals by contributors
    on May 30, 2026
  5. melvin-bot commented on May 30, 2026

    @melvin-bot
    Author

    Triggered auto assignment to Contributor-plus team member for initial proposal review - @brunovjk (External)

  6. melvin-bot commented on May 30, 2026

    @melvin-bot
    Author
  7. changed the title [-]Chart should maintain aspect ratio when window/screen size changes[/-] [+][$250] Chart should maintain aspect ratio when window/screen size changes[/+] on May 30, 2026
  8. KJ21-ENG commented on May 30, 2026

    @KJ21-ENG
    Contributor

    🚨 Edited by proposal-police: This proposal was edited at 2026-05-30 23:59:40 UTC.

    Replaces my earlier proposal. The earlier draft targeted the search/home chart components. The verified root cause is in the HTML Victory chart renderer: numeric width and height are applied independently, so max-width clamps only the width and leaves the height fixed.

    Proposal

    What is the root cause of that problem?

    The affected chart path is the HTML Victory chart renderer, where custom <victorychart> blocks are registered as renderable HTML nodes and routed to VictoryChartRenderer:

    victorychart: HTMLElementModel.fromCustomModel({
    tagName: 'victorychart',
    contentModel: HTMLContentModel.block,
    }),
    victorybar: HTMLElementModel.fromCustomModel({
    tagName: 'victorybar',
    contentModel: HTMLContentModel.block,
    }),
    victoryline: HTMLElementModel.fromCustomModel({
    tagName: 'victoryline',
    contentModel: HTMLContentModel.block,
    }),
    victoryaxis: HTMLElementModel.fromCustomModel({
    tagName: 'victoryaxis',
    contentModel: HTMLContentModel.block,
    }),
    victorylabel: HTMLElementModel.fromCustomModel({
    tagName: 'victorylabel',
    contentModel: HTMLContentModel.textual,
    }),
    victorylegend: HTMLElementModel.fromCustomModel({
    tagName: 'victorylegend',
    contentModel: HTMLContentModel.block,
    }),
    victorygroup: HTMLElementModel.fromCustomModel({
    tagName: 'victorygroup',
    contentModel: HTMLContentModel.block,
    }),
    victorypie: HTMLElementModel.fromCustomModel({
    tagName: 'victorypie',
    contentModel: HTMLContentModel.block,
    }),

    victorychart: VictoryChartRenderer,
    };

    That renderer copies numeric width and height from the <victorychart> node directly onto the inner chart view:

    const parsedHeight = parseAttribute(tnode.attributes.height);
    if (typeof parsedHeight === 'number') {
    nodeStyles.height = parsedHeight;
    }
    const parsedWidth = parseAttribute(tnode.attributes.width);
    if (typeof parsedWidth === 'number') {
    nodeStyles.width = parsedWidth;
    }

    Those parsed styles are then passed through context and applied after the shared styles.chartContent and styles.mw100 styles:

    function VictoryChartProvider({tnode, children}: {tnode: TNode; children: React.ReactNode}) {
    const {regular: regularTypeface} = useChartDefaultTypeface();
    const {data, xKey, yKeys, xAxis, yAxis, domain, domainPadding, padding, isHorizontal, categories, labelItems, legendItems} = processVictoryChartTree(tnode, regularTypeface, null);
    const {nodeStyles: chartContentStyles, parentNodeStyles: chartContainerStyles} = parseStyles(tnode);

    <View style={[styles.chartContainer, styles.mw100, chartContainerStyles]}>
    <View style={[styles.chartContent, styles.mw100, chartContentStyles]}>{children}</View>

    So when a viewport becomes narrower than the original chart width, maxWidth: '100%' clamps only the width. The fixed numeric height remains unchanged, so Victory/Skia redraws into a narrower-but-equally-tall canvas instead of scaling the full chart rectangle proportionally.

    What changes do you think we should make in order to solve the problem?

    Change the Victory chart sizing contract so a numeric width/height pair is treated as an intrinsic size, not two independent responsive dimensions.

    Concretely, update parseStyles() after all attribute and style.data merging is complete. When the final node style has a positive numeric width and height, convert that pair into responsive image-style sizing: preserve the original width as the maximum rendered width, set the rendered width to fill the available container up to that maximum, remove the fixed height, and set aspectRatio to width / height. Leave single-dimension, percentage/string, and explicit parent styles unchanged.

    Add focused coverage for parseStyles() so a width=450 height=300 chart returns a style equivalent to width: '100%', maxWidth: 450, aspectRatio: 1.5, and no fixed height, while width-only and height-only charts keep their current behavior.

    Scope boundaries: touch src/components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/utils/parseStyles.ts and, only if needed for layout alignment, src/components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/components/VictoryChartContainer.tsx. This affects rendered HTML Victory charts on web, mWeb, desktop, iOS, and Android through the shared renderer. It does not change the search/home chart components in src/components/Charts, chart data parsing, Victory axis/domain settings, tooltip behavior, or backend/API behavior.

    What alternative solutions did you explore? (Optional)

    Updating the search chart components would not fix this HTML-rendered chart path; those components have their own dashboard layout and do not parse <victorychart width height> from report HTML.

    Only removing styles.mw100 would prevent width clamping, but then charts would overflow small screens. Scaling the whole chart with a transform would preserve visuals but would make layout height, hit testing, and tooltip coordinates fragile. Using aspectRatio from the intrinsic width/height pair fixes the layout at the source while keeping the existing Victory render and interaction code intact.

  9. ReaperOAK commented on May 30, 2026

    @ReaperOAK
    Contributor

    🚫 Duplicated proposal withdrawn by 🤖 ProposalPolice.

  10. github-actions commented on May 30, 2026

    @github-actions
    Contributor

    ⚠️ @ReaperOAK Your proposal is a duplicate of an already existing proposal and has been automatically withdrawn to prevent spam. Please review the existing proposals before submitting a new one.

  11. aswin-s commented on May 30, 2026

    @aswin-s
    Contributor

    🚫 Duplicated proposal withdrawn by 🤖 ProposalPolice.

  12. github-actions commented on May 30, 2026

    @github-actions
    Contributor

    ⚠️ @aswin-s Your proposal is a duplicate of an already existing proposal and has been automatically withdrawn to prevent spam. Please review the existing proposals before submitting a new one.

  13. trasnake87 commented on May 30, 2026

    @trasnake87
    Contributor

    Proposal

    The chart squashes horizontally instead of scaling proportionally because its wrapper resolves to a fixed pixel height against a fluid width — so when the viewport narrows, the width shrinks but the height cannot.

    Root cause

    victory-native v41 (^41.21.0) renders the chart into a Skia Canvas that fills the measured box of its parent View. The chart's on-screen dimensions are therefore exactly whatever Yoga resolves for the content wrapper in VictoryChartContainer. Two layered issues make that box non-proportional:

    1 - The content wrapper pins a fixed height against a fluid width.

    src/components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/components/VictoryChartContainer.tsx:9-13:

    <View style={[styles.chartContainer, styles.mw100, chartContainerStyles]}>
        <View style={[styles.chartContent, styles.mw100, chartContentStyles]}>{children}</View>
    </View>

    styles.chartContent hard-codes a height (src/styles/index.ts:6090-6092 → {height: CHART_CONTENT_MIN_HEIGHT}, with CHART_CONTENT_MIN_HEIGHT = 250 in src/components/Charts/VictoryTheme.ts:85), while styles.mw100 (src/styles/utils/sizing.ts:150-152 → {maxWidth: '100%'}) only ever clamps the width. Width is fluid; height is frozen.

    2 - The per-chart width/height attributes are applied as independent fixed pixels, with no aspect ratio tying them together.

    The backend emits <victorychart width="W" height="H" …>. Those attributes are turned into styles in src/components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/utils/parseStyles.ts:14-21:

    const parsedHeight = parseAttribute(tnode.attributes.height);
    if (typeof parsedHeight === 'number') {
        nodeStyles.height = parsedHeight;
    }
    const parsedWidth = parseAttribute(tnode.attributes.width);
    if (typeof parsedWidth === 'number') {
        nodeStyles.width = parsedWidth;
    }

    nodeStyles becomes chartContentStyles, the last entry in the inner View's style array (so it wins). The effective inner-View style resolves to {height: H, maxWidth: '100%', width: W}. maxWidth: '100%' clamps the width down to the parent, but there is no maxHeight and no aspectRatio, so H stays frozen. A 400×250 chart dropped into a 200px-wide column renders as a 200×250 box — precisely the "shrinks in an awkward, non-proportional way" reported. It is worst for <victorypie>, whose radius is min(width, height): the circle collapses to the smaller axis and leaves a tall empty band, which is why it reads as "unusable" on the narrow mobile viewport.

    Proposed fix

    Derive the aspect ratio from the intrinsic width/height in parseStyles, and let the height follow the resolved (clamped) width instead of pinning both axes independently. Replace lines 14-21 of parseStyles.ts:

    // src/components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/utils/parseStyles.ts
    const parsedHeight = parseAttribute(tnode.attributes.height);
    const parsedWidth = parseAttribute(tnode.attributes.width);
    
    if (typeof parsedWidth === 'number' && typeof parsedHeight === 'number' && parsedHeight > 0) {
        // Scale uniformly like an <img>: cap at the intrinsic size, then let aspectRatio derive
        // the height from whatever width the responsive container resolves to.
        // maxWidth/maxHeight must both be set because aspectRatio is computed first and the
        // max* values clamp the result (see expenseViewImageSmall in styles/index.ts).
        nodeStyles.maxWidth = parsedWidth;
        nodeStyles.maxHeight = parsedHeight;
        nodeStyles.aspectRatio = parsedWidth / parsedHeight;
        nodeStyles.height = 'auto';
    } else {
        if (typeof parsedHeight === 'number') {
            nodeStyles.height = parsedHeight;
        }
        if (typeof parsedWidth === 'number') {
            nodeStyles.width = parsedWidth;
        }
    }

    Because chartContentStyles is applied last in VictoryChartContainer, the height: 'auto' + aspectRatio override automatically neutralizes the leftover height: 250 from styles.chartContent for any dimensioned chart — no edit is needed there. The inner View now stretches to the available width (bounded by maxWidth), and Yoga derives the height from the ratio, so the box stays proportional at every viewport size. Walking the 400×250 example through the fix: a 200px-wide parent yields width = 200, height = 200 / (400/250) = 125 — aspect ratio preserved instead of 200×250.

    No .native divergence is required: web and native share BaseVictoryChartRenderer (index.native.tsx simply re-exports it), so the single parseStyles change fixes both platforms in one place.

    Why this approach

    This mirrors the established responsive-image pattern already used for receipts in this codebase — expenseViewImage and expenseViewImageSmall at src/styles/index.ts:4743-4754, which combine maxWidth + maxHeight + aspectRatio + height: 'auto' to make an image "scale uniformly like an <img>," the exact behavior the issue asks for. The inline comment there ("aspectRatio is calculated first and then maxWidth/maxHeight clamps the dimensions, thus both have to be specified") is the reason both maxWidth and maxHeight are set above rather than aspectRatio alone.

    Fixing it in parseStyles is preferable to hardcoding an aspectRatio on styles.chartContent, because the ratio is per-chart and only known from the node's width/height attributes — a static style value would force one ratio onto every chart. Wrapping the chart in a fixed-pixel box was also rejected: it reintroduces the same non-responsive behavior the issue is about. The change is purely client-side layout (no parser or data-path impact), and the existing chartContent.height continues to serve only as the fallback for the rare chart that ships without width/height, where no ratio can be derived.

  14. KJ21-ENG commented on May 30, 2026

    @KJ21-ENG
    Contributor

    Updated my proposal — root cause is the HTML Victory renderer applying numeric width/height independently, not the search chart components.

  15. 15antonian commented on May 31, 2026

    @15antonian

    🚫 Duplicated proposal withdrawn by 🤖 ProposalPolice.

  16. github-actions commented on May 31, 2026

    @github-actions
    Contributor

    ⚠️ @15antonian Your proposal is a duplicate of an already existing proposal and has been automatically withdrawn to prevent spam. Please review the existing proposals before submitting a new one.

  17. ahsan3219 commented on May 31, 2026

    @ahsan3219

    Proposal

    What is the root cause of the problem?

    The root cause lies in parseStyles.ts, where numeric width and height attributes from <victorychart> HTML nodes are applied as two independent fixed pixel values with no relationship between them. When maxWidth: '100%' (from styles.mw100) clamps the width to fit the viewport, there is nothing to proportionally reduce the height — it stays frozen at whatever pixel value was parsed from the height attribute, or falls back to the hardcoded CHART_CONTENT_MIN_HEIGHT = 250 from styles.chartContent.

    The inner View in VictoryChartContainer.tsx resolves its styles in this order:

    [styles.chartContent, styles.mw100, chartContentStyles]
    

    chartContentStyles (from parseStyles) wins, but it only carries {width: W, height: H}. So on a narrow viewport, the chart box becomes something like 200×300 instead of the correct proportional 200×125 — exactly the non-uniform squashing reported.

    What changes should be made to solve the problem?

    The fix should be contained entirely in parseStyles.ts. When both width and height attributes are present and valid numbers, instead of emitting two fixed pixel values, we should derive an aspectRatio and let height follow the resolved width naturally — the same pattern already used for receipt images in this codebase (expenseViewImageSmall in styles/index.ts uses maxWidth + maxHeight + aspectRatio + height: 'auto' for exactly this reason).

    Proposed change to parseStyles.ts (lines 14–21):

    const parsedHeight = parseAttribute(tnode.attributes.height);
    const parsedWidth = parseAttribute(tnode.attributes.width);
    
    if (typeof parsedWidth === 'number' && typeof parsedHeight === 'number' && parsedHeight > 0) {
        nodeStyles.maxWidth = parsedWidth;
        nodeStyles.maxHeight = parsedHeight;
        nodeStyles.aspectRatio = parsedWidth / parsedHeight;
        nodeStyles.height = 'auto';
    } else {
        if (typeof parsedHeight === 'number') {
            nodeStyles.height = parsedHeight;
        }
        if (typeof parsedWidth === 'number') {
            nodeStyles.width = parsedWidth;
        }
    }

    Because chartContentStyles is the last entry in the View's style array, height: 'auto' and aspectRatio override the hardcoded height: 250 from styles.chartContent automatically — no changes needed in VictoryChartContainer.tsx or styles/index.ts.

    Charts that ship without both width and height attributes keep their current behavior unchanged.

    What alternative solutions were explored?

    • Applying a transform: scale() on the wrapper was rejected — it does not affect layout flow on web, and the Skia canvas inside victory-native would rasterize at the original dimensions, causing blurry or clipped output.
    • Removing styles.mw100 entirely was rejected — charts would overflow narrow viewports instead of scaling down.
    • Hardcoding a fixed aspectRatio on styles.chartContent was rejected — the correct ratio is per-chart and only knowable from the node's width/height attributes at parse time.

    Since index.native.tsx simply re-exports BaseVictoryChartRenderer, this single change to parseStyles.ts fixes both web and mobile in one place with no platform divergence required.

  18. melvin-bot commented on May 31, 2026

    @melvin-bot
    Author

    📣 @ahsan3219! 📣
    Hey, it seems we don’t have your contributor details yet! You'll only have to do this once, and this is how we'll hire you on Upwork.
    Please follow these steps:

    1. Make sure you've read and understood the contributing guidelines.
    2. Get the email address used to login to your Expensify account. If you don't already have an Expensify account, create one here. If you have multiple accounts (e.g. one for testing), please use your main account email.
    3. Get the link to your Upwork profile. It's necessary because we only pay via Upwork. You can access it by logging in, and then clicking on your name. It'll look like this. If you don't already have an account, sign up for one here.
    4. Copy the format below and paste it in a comment on this issue. Replace the placeholder text with your actual details.
      Screen Shot 2022-11-16 at 4 42 54 PM
      Format:
    Contributor details
    Your Expensify account email: <REPLACE EMAIL HERE>
    Upwork Profile Link: <REPLACE LINK HERE>
    
  19. wildan-m commented on May 31, 2026

    @wildan-m
    Contributor

    🚫 Duplicated proposal withdrawn by 🤖 ProposalPolice.

  20. github-actions commented on May 31, 2026

    @github-actions
    Contributor

    ⚠️ @wildan-m Your proposal is a duplicate of an already existing proposal and has been automatically withdrawn to prevent spam. Please review the existing proposals before submitting a new one.

  21. quinthar commented on May 31, 2026

    @quinthar
    Contributor

    Whoops, this issue is a dupe of #91515; closing.

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

Metadata

Metadata

Labels

BugSomething is broken. Auto assigns a BugZero manager.DailyKSv2ExternalAdded to denote the issue can be worked on by a contributorHelp WantedApply this label when an issue is open to proposals by contributorsImprovementItem broken or needs improvement.mobile

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions