Skip to content

[Payment due @truph01] [NoQA] [Insights] Horizontal bar chart follow-ups: switch narrow layouts and grow height - #102321

Merged
aldo-expensify merged 15 commits into
Expensify:mainfrom
software-mansion-labs:@adamgrzybowski/horizontal-bar-charts-follow-ups
Oct 2, 2026
Merged

aldo-expensify merged 15 commits into
Expensify:mainfrom
software-mansion-labs:@adamgrzybowski/horizontal-bar-charts-follow-ups

Conversation

@adamgrzybowski

@adamgrzybowski adamgrzybowski commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Explanation of Change

  • On narrow layouts, bar charts switch to horizontal bars when category labels no longer fit rotated at 45°, instead of rotating to 90° and dropping some. The chart flips back to vertical as width grows.
  • Horizontal bar charts grow taller with more categories so every label stays visible.
  • Behind the Insights beta. With the beta off, behavior is unchanged.

Fixed Issues

$ #101435
PROPOSAL:

Tests

  • Verify that no errors appear in the JS console

Offline tests

Same as Tests

QA Steps

  1. Enable the Insights beta, then open a bar chart (e.g. Home → Spend over time → Top categories) and confirm it renders with category labels.
  2. Slowly narrow the window: confirm labels rotate as space shrinks and the chart flips to horizontal bars (categories on the left) once labels no longer fit, then widen it back and confirm it returns to vertical bars.
  3. In horizontal mode with many categories, confirm every category label is visible (none skipped) and the chart grows taller / scrolls to fit them.
  • 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 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 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)
  • 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)
  • 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 the PR adds or modifies the UI:
    • I asked an AI agent to review the changes for accessibility issues and addressed its findings.
    • I tested with a screen reader (VoiceOver on macOS) and verified all new/changed elements are reachable with a logical focus order.
    • I verified all new/changed elements have meaningful accessible names and roles.
    • I verified state changes are announced (e.g. checked/unchecked, expanded/collapsed, selected).
  • 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

@codecov

codecov Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ Changes either increased or maintained existing code coverage, great job!

Files with missing lines Coverage Δ
src/components/Charts/PieChart/PieChartContent.tsx 0.00% <ø> (ø)
src/components/Charts/VictoryTheme.ts 100.00% <100.00%> (ø)
src/components/Charts/barChartConstants.ts 100.00% <100.00%> (ø)
...rc/components/Charts/hooks/useChartLabelFormats.ts 94.44% <100.00%> (+0.32%) ⬆️
src/components/Charts/hooks/useChartLabelLayout.ts 100.00% <ø> (ø)
src/styles/index.ts 64.56% <ø> (ø)
src/components/Charts/BarChart/index.native.tsx 0.00% <0.00%> (ø)
src/components/Charts/BarChart/index.tsx 0.00% <0.00%> (ø)
src/components/Charts/utils/index.ts 73.19% <92.30%> (+1.76%) ⬆️
...es/home/InsightsSection/InsightsSectionContent.tsx 0.00% <0.00%> (ø)
... and 6 more
... and 6 files with indirect coverage changes

Comment thread src/components/Charts/BarChart/BarChartContent.tsx Outdated
Comment thread src/components/Charts/BarChart/BarChartContent.tsx
Comment thread Mobile-Expensify
@adamgrzybowski
adamgrzybowski marked this pull request as ready for review September 28, 2026 13:14
@adamgrzybowski
adamgrzybowski requested review from a team as code owners September 28, 2026 13:14
@melvin-bot
melvin-bot Bot requested review from joekaufmanexpensify and puneetlath and removed request for a team September 28, 2026 13:14
@melvin-bot

melvin-bot Bot commented Sep 28, 2026

Copy link
Copy Markdown

@puneetlath 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]

Comment thread src/components/Charts/hooks/useChartLabelLayout.ts Outdated
@adamgrzybowski

Copy link
Copy Markdown
Contributor Author

@situchan I think you wanted to help with the review

@situchan

Copy link
Copy Markdown
Contributor

@situchan I think you wanted to help with the review

yes thanks for tagging me

@puneetlath
puneetlath requested a review from situchan September 28, 2026 13:44
@JmillsExpensify
JmillsExpensify requested review from JmillsExpensify and removed request for joekaufmanexpensify September 28, 2026 13:57
@github-actions

Copy link
Copy Markdown
Contributor

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

@github-actions

This comment has been minimized.

@cristipaval
cristipaval requested review from aldo-expensify, cristipaval, luacmartins and truph01 and removed request for puneetlath and situchan September 28, 2026 14:10
@mhawryluk

mhawryluk commented Sep 30, 2026 •

Copy link
Copy Markdown
Member

@MelvinBot can you replace the text in the PR Author Checklist section of this PRs description with this?

Details - [x] I linked the correct issue in the `### Fixed Issues` section above - [x] I wrote clear testing steps that cover the changes made in this PR - [x] I added steps for local testing in the `Tests` section - [x] I added steps for the expected offline behavior in the `Offline steps` section - [x] I added steps for Staging and/or Production testing in the `QA steps` section - [x] I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct) - [x] 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) - [x] I tested this PR with a [High Traffic account](https://github.com/Expensify/App/blob/main/contributingGuides/CONTRIBUTING.md#high-traffic-accounts) against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability). - [x] I included screenshots or videos for tests on [all platforms](https://github.com/Expensify/App/blob/main/contributingGuides/CONTRIBUTING.md#make-sure-you-can-test-on-all-platforms) - [x] I ran the tests on **all platforms** & verified they passed on: - [x] Android: Native - [x] Android: mWeb Chrome - [x] iOS: Native - [x] iOS: mWeb Safari - [x] MacOS: Chrome / Safari - [x] 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) - [x] I followed proper code patterns (see [Reviewing the code](https://github.com/Expensify/App/blob/main/contributingGuides/PR_REVIEW_GUIDELINES.md#reviewing-the-code)) - [x] I verified that comments were added to code that is not self explanatory - [x] 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. - [x] 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) - [x] If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers - [x] I followed the guidelines as stated in the [Review Guidelines](https://github.com/Expensify/App/blob/main/contributingGuides/PR_REVIEW_GUIDELINES.md) - [x] 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) - [x] If a new CSS style is added I verified that: - [x] A similar style doesn't already exist - [x] The style can't be created with an existing [StyleUtils](https://github.com/Expensify/App/blob/main/src/styles/utils/index.ts) function (i.e. `StyleUtils.getBackgroundAndBorderStyle(theme.componentBG)`) - [x] If new assets were added or existing ones were modified, I verified that: - [x] The assets are optimized and compressed (for SVG files, run `npm run compress-svg`) - [x] The assets load correctly across all supported platforms. - [x] 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. - [x] 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) - [x] 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. - [x] 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. - [x] 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: - [x] I verified that all the inputs inside a form are aligned with each other. - [x] I added `Design` label and/or tagged `@Expensify/design` so the design team can review the changes. - [x] If the PR adds or modifies the UI: - [x] I asked an AI agent to review the changes for accessibility issues and addressed its findings. - [x] I tested with a screen reader (VoiceOver on macOS) and verified all new/changed elements are reachable with a logical focus order. - [x] I verified all new/changed elements have meaningful accessible names and roles. - [x] I verified state changes are announced (e.g. checked/unchecked, expanded/collapsed, selected). - [x] I added [unit tests](https://github.com/Expensify/App/blob/main/tests/README.md) for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow. - [x] 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.

@MelvinBot

Copy link
Copy Markdown
Contributor

I replaced the PR Author Checklist section with your text. The new "If the PR adds or modifies the UI" accessibility items are now included. The rest of the description is unchanged.


view run

@JmillsExpensify

Copy link
Copy Markdown
Contributor

I think that looks good, though in English at least, we should use "k" for thousands, not "K" (abbreviation for Kelvin).

@truph01

truph01 commented Sep 30, 2026

Copy link
Copy Markdown
Contributor

that's doable, the formatter supports compact notation. should I add it? and only for the horizontal variant?

We will do it in this PR, right? @mhawryluk

@dannymcclain

Copy link
Copy Markdown
Contributor

the formatter supports compact notation. should I add it? and only for the horizontal variant?

I would use compact notation all the time everywhere personally, but maybe that's just me.

@mhawryluk

Copy link
Copy Markdown
Member

that's doable, the formatter supports compact notation. should I add it? and only for the horizontal variant?

We will do it in this PR, right? @mhawryluk

I think so, doing it now

@mhawryluk

Copy link
Copy Markdown
Member

I think that looks good, though in English at least, we should use "k" for thousands, not "K" (abbreviation for Kelvin).

We will do it in this PR, right? @mhawryluk

I would use compact notation all the time everywhere personally, but maybe that's just me.

done, I switched the values on the chart value axes to the compact format. doesn't erase the need to skip labels when they would overlap, but it will make it happen less often @truph01

Zrzut ekranu 2026-10-1 o 10 50 19

@melvin-bot melvin-bot Bot changed the title [NoQA] [Insights] Horizontal bar chart follow-ups: switch narrow layouts and grow height [Payment due @truph01] [NoQA] [Insights] Horizontal bar chart follow-ups: switch narrow layouts and grow height Oct 2, 2026
@melvin-bot

melvin-bot Bot commented Oct 2, 2026

Copy link
Copy Markdown

🎯 @truph01, thanks for reviewing and testing this PR! 🎉

A payment issue will be created for your review once this PR is deployed to production.
E/E issue linked to the PR - no internal issue.

If payment is not needed (e.g., regression PR review fix etc), react with 👎 to this comment to prevent the payment issue from being created.

@situchan situchan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

Screen.Recording.2026-10-02.at.4.13.09.PM.mov

@MelvinBot

Copy link
Copy Markdown
Contributor

⏱️ Ran out of time before I could finish. This usually means the task was too complex or I got stuck exploring. Please try again with a more specific request or post in #melvinbot-ai.

Run details

@MelvinBot

Copy link
Copy Markdown
Contributor

Code quality review

The structure is solid. Constants are now shared, the geometry is pulled into tested pure helpers, and a barAreaHeight state round-trip is gone. I found one likely visual regression and four smaller cleanups.

1. Horizontal bars with 2–4 categories probably get clipped (please verify)
HorizontalBarChartContent.tsx:415 replaces the computed calculateMinDomainPadding(...) with a fixed top/bottom: 8. Line 348 also sets top: 0. Each bar is drawn ±thickness / 2 around its row center (line 363), and thickness = 0.3 * plotHeight / n. Using the 250px minimum height:

Rows Half thickness Old padding New padding
2 ~18.8px 23px 8px → about 11px off the canvas top
3 ~12.5px — 8px → about 4.5px clipped
4 ~9.4px — 8px → about 1.4px clipped

At 5 or more rows the bars fit. You can keep the computed padding as a floor, for example Math.max(8, calculateMinDomainPadding(plotHeight, n, HORIZONTAL_BAR_PADDING)). plotHeight is now known before render because getHorizontalChartHeight sets the height. This comes from reading the code. I did not reproduce it in the browser.

2. The dispatcher does label-layout work it can't use
BarChartContent.tsx:25-58 measures every label and runs useChartLabelLayout on every render. It does this even when canFallBackToHorizontalBars is false (beta off, or wide layouts that are already horizontal), and it adds a wrapper View. In BarChartContent, render the body directly unless canFallBackToHorizontalBars is true, and mount the dispatcher only in that case. Beta-off users then stay byte-for-byte on the old path, as the PR description promises.

3. .replace('K', 'k') is an English-only fix applied to every locale
useChartLabelFormats.ts:32 changes Intl output by string replacement. It works today, but it is a hidden coupling to CLDR output. Add a short comment explaining why (the "k" vs "K" request), or apply it only when the locale is English.

4. Comments that will mislead the next reader

  • ChartYAxisLabels.tsx:96 says "Left-aligned labels (horizontal bar chart)". The vertical bar chart and line chart also pass leftAlign, so their y-axis labels move to x = 0 too. If you intended that, update the comment. If not, it's a layout change for those charts.
  • useChartLabelLayout.test.ts:119 says "The hook no longer owns the fallback decision". That describes an earlier version of this PR, not the code.

5. The new useChartLabelLayout tests repeat existing ones
The three tests under "horizontal bar fallback signal" use the same inputs and assertions as the existing 0°/45°/90° tests at lines 87-116. I'd delete them. The orientation decision itself (labelRotation === 90 with canFallBackToHorizontalBars gives horizontal) has no test. A small test for that would add more value.

Already discussed, not repeated
  • situchan and mhawryluk both raised that the dispatcher and the vertical body each compute the label geometry. getVerticalBarLabelLayoutInputs now keeps the formula in one place, and the remaining duplicate work was accepted.
  • The submodule revert and the shared BASE_DOMAIN_PADDING comments are resolved.

@MelvinBot

Copy link
Copy Markdown
Contributor

Regression review

I found one likely visual bug and one scope issue. The PR says "With the beta off, behavior is unchanged", but several changes reach every user of the Search charts. I checked this by reading the code at b80ce89. I did not reproduce anything in the browser.

1. Likely bug: horizontal bars with 2–4 categories get clipped (beta only)
The computed vertical domain padding was replaced by a fixed 8px (HorizontalBarChartContent.tsx:415), and the top padding is now 0 (line 348). Each bar extends 0.15 × plotHeight / rows above and below its row center (line 363). At the 250px minimum height:

Categories Bar half-height Space above the top row now Result
2 ~18.8px 8px (was 23px) about 11px cut off at the top and bottom
3 ~12.5px 8px about 4.5px cut off
4 ~9.4px 8px about 1.4px cut off

At 5 or more categories the bars fit. To fix it, keep the computed value as a floor: Math.max(8, calculateMinDomainPadding(plotHeight, data.length, HORIZONTAL_BAR_PADDING)). To check it, filter a bar chart down to 2 categories on a wide layout.

2. Changes that also reach beta-off users
The Search chart view (Search/index.tsx:1327) is not behind the beta. Users there will see these changes. Please confirm each one is intended, then update the PR description and QA steps:

  • Compact value axis. Y-axis ticks on vertical bar and line charts change from "$100,000" to "$100k" (useChartLabelFormats.ts:32). Tooltips still show full values.
  • Y-axis labels shift about 8px left. On vertical bar and line charts, labels that used to start at x ≈ 2 × GLYPH_PADDING now start at x = 0 (ChartYAxisLabels.tsx:98). The gap between the labels and the plot grows by the same amount.
  • X-axis label spacing. labelPosition: 'inset' gives about 24px back to the plot. The bars and lines get taller, and the category labels move down (VerticalBarChartContent.tsx:257, LineChartContent.tsx:268).
  • Pie legend. Item margins moved to rowGap and columnGap (styles/index.ts:6848). The legend loses its trailing 8px of bottom space.
Minor and checked areas
  • A one-frame flash on narrow layouts. Before onLayout, containerWidth is 0, so the layout hook returns its default 0° rotation. The dispatcher first mounts the vertical chart, then remounts it as horizontal (BarChartContent.tsx:52). Only charts that end up horizontal are affected.
  • The geometry prediction matches. getVerticalBarPlotBounds assumes chartBounds.left = padding.left + labelGap. That matches victory-native, because the y-axis has no font, so maxYLabel is 0.
  • Compact rounding is safe here. Y ticks start at 0 with tickCount: 5. d3 steps are 1, 2, or 5 × 10ⁿ, so ticks never need three significant digits, and compact rounding won't mislabel them.
  • No overflow from the new label cap. measureTextWidth now measures labels longer than 500px correctly. The horizontal chart's label truncation and its left padding use the same categoryLabelMaxWidth.

@luacmartins luacmartins left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@aldo-expensify
aldo-expensify merged commit a17481e into Expensify:main Oct 2, 2026
39 of 41 checks passed
@github-actions

github-actions Bot commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

🚧 aldo-expensify has triggered a test Expensify/App build. You can view the workflow run here.

@OSBotify

OSBotify commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@OSBotify OSBotify mentioned this pull request Oct 4, 2026
59 tasks done
@OSBotify

OSBotify commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/aldo-expensify in version: 9.5.2-0 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

@MelvinBot

Copy link
Copy Markdown
Contributor

No help site update is needed. The horizontal bar layout only shows behind the Insights beta (isBetaEnabled(CONST.BETAS.INSIGHTS_PAGE)). It also changes chart layout, not a feature. The existing article still says Top categories "displays grouped results as a bar chart," and that stays true.


view run

@OSBotify

OSBotify commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/Julesssss in version: 9.5.2-4 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

Bundle Size Analysis (Sentry):

@melvin-bot

melvin-bot Bot commented Oct 5, 2026

Copy link
Copy Markdown

🤖 Payment issue created: #103101

@MelvinBot

Copy link
Copy Markdown
Contributor

I didn't create a reviewer payment issue. You authored this PR (11 of its 15 commits), so you weren't its reviewer. Your only review entry is a reply on your own PR. truph01 is the Contributor+ reviewer, and [Due for payment 2026-10-12] Payment issue for E/App PR#102321 already covers that payment.

If you think you're owed payment for this work, please ask the BugZero team member on the issue to review it.


view run

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.