Skip to content

Add search pie chart component#81000

Merged
MonilBhavsar merged 43 commits intoExpensify:mainfrom
software-mansion-labs:add-search-pie-chart-component
Feb 25, 2026
Merged

Add search pie chart component#81000
MonilBhavsar merged 43 commits intoExpensify:mainfrom
software-mansion-labs:add-search-pie-chart-component

Conversation

@borys3kk
Copy link
Contributor

@borys3kk borys3kk commented Jan 30, 2026

Explanation of Change

This PR introduces the SearchPieChart component as part of the Insights project, enabling pie chart visualization in the search view when the user types view:pie with group-by.

New Charts Infrastructure:

  • Added a reusable PieChart component built on top of Victory Native and @shopify/react-native-skia, with platform-specific entry points for web and native.

Search Integration:

  • Added SearchChartView which fetches and transforms search data into chart-compatible format, grouping results by category and aggregating values for the pie slices
  • Chart is conditionally rendered in the Search component when queryJSON.view === 'pie'

Bar Chart:

  • Made BarChart/index.tsx React Compiler compliant

Fixed Issues

$ #81028

Tests

  • Render pie chart with type:expense group-by:category view:pie – verify slices display correctly with distinct colors and appropriate proportions

  • Hover over slice (web) – verify tooltip shows <category> • <amount> (<percentage>)

  • Click/tap on slice – verify navigation to filtered search type:expense category:"<selected>"

  • Verify that no errors appear in the JS console

Offline tests

QA Steps

same as tests

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

  • 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 verified there are no new alerts related to the canBeMissing param for useOnyx
  • 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
      • If any non-english text was added/modified, I used JaimeGPT to get English > Spanish translation. I then posted it in #expensify-open-source and it was approved by an internal Expensify engineer. Link to Slack message:
    • 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

Uploading image.png…

Android: mWeb Chrome image
iOS: Native Screenshot 2026-01-31 at 01 27 50
iOS: mWeb Safari image
MacOS: Chrome / Safari image

@borys3kk
Copy link
Contributor Author

cc: @mateuuszzzzz

@codecov
Copy link

codecov bot commented Jan 30, 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 Δ
src/CONST/index.ts 92.43% <ø> (+5.04%) ⬆️
src/components/Charts/constants.ts 100.00% <100.00%> (ø)
...rc/components/Charts/hooks/useChartInteractions.ts 1.88% <ø> (ø)
src/components/Charts/utils.ts 74.24% <100.00%> (+29.08%) ⬆️
src/components/Search/SearchBarChart.tsx 12.50% <ø> (ø)
src/components/Search/SearchLineChart.tsx 12.50% <ø> (ø)
src/styles/index.ts 46.35% <ø> (-0.53%) ⬇️
src/components/Charts/BarChart/BarChartContent.tsx 5.40% <0.00%> (ø)
src/components/Charts/BarChart/index.tsx 0.00% <0.00%> (ø)
...c/components/Charts/LineChart/LineChartContent.tsx 9.09% <0.00%> (ø)
... and 7 more
... and 143 files with indirect coverage changes

@github-actions
Copy link
Contributor

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

@github-actions

This comment has been minimized.

@melvin-bot
Copy link

melvin-bot bot commented Jan 30, 2026

Hey, I noticed you changed src/languages/en.ts in a PR from a fork. For security reasons, translations are not generated automatically for PRs from forks.

If you want to automatically generate translations for other locales, an Expensify employee will have to:

  1. Look at the code and make sure there are no malicious changes.
  2. Run the Generate static translations GitHub workflow. If you have write access and the K2 extension, you can simply click: [this button]

Alternatively, if you are an external contributor, you can run the translation script locally with your own OpenAI API key. To learn more, try running:

npx ts-node ./scripts/generateTranslations.ts --help

Typically, you'd want to translate only what you changed by running npx ts-node ./scripts/generateTranslations.ts --compare-ref main

@OSBotify
Copy link
Contributor

🦜 Polyglot Parrot! 🦜

Squawk! Looks like you added some shiny new English strings. Allow me to parrot them back to you in other tongues:

View the translation diff
diff --git a/src/languages/de.ts b/src/languages/de.ts
index a5904b5c..1fdc8103 100644
--- a/src/languages/de.ts
+++ b/src/languages/de.ts
@@ -7090,7 +7090,7 @@ Fordere Spesendetails wie Belege und Beschreibungen an, lege Limits und Standard
             allMatchingItemsSelected: 'Alle passenden Elemente ausgewählt',
         },
         topSpenders: 'Top-Ausgaben',
-        view: {label: 'Ansehen', table: 'Tabelle', bar: 'Bar'},
+        view: {label: 'Ansehen', table: 'Tabelle', bar: 'Bar', pie: 'Kuchen'},
         chartTitles: {
             [CONST.SEARCH.GROUP_BY.FROM]: 'Von',
             [CONST.SEARCH.GROUP_BY.CARD]: 'Karten',
diff --git a/src/languages/fr.ts b/src/languages/fr.ts
index 55297041..f378bb09 100644
--- a/src/languages/fr.ts
+++ b/src/languages/fr.ts
@@ -7102,7 +7102,7 @@ Exigez des informations de dépense comme les reçus et les descriptions, défin
             allMatchingItemsSelected: 'Tous les éléments correspondants sont sélectionnés',
         },
         topSpenders: 'Plus gros dépensiers',
-        view: {label: 'Afficher', table: 'Tableau', bar: 'Barre'},
+        view: {label: 'Afficher', table: 'Tableau', bar: 'Barre', pie: 'Camembert'},
         chartTitles: {
             [CONST.SEARCH.GROUP_BY.FROM]: 'De',
             [CONST.SEARCH.GROUP_BY.CARD]: 'Cartes',
diff --git a/src/languages/it.ts b/src/languages/it.ts
index 169e7064..e4b1f1ec 100644
--- a/src/languages/it.ts
+++ b/src/languages/it.ts
@@ -7079,7 +7079,7 @@ Richiedi dettagli di spesa come ricevute e descrizioni, imposta limiti e valori
             allMatchingItemsSelected: 'Tutti gli elementi corrispondenti selezionati',
         },
         topSpenders: 'Maggiori spenditori',
-        view: {label: 'Visualizza', table: 'Tabella', bar: 'Bar'},
+        view: {label: 'Visualizza', table: 'Tabella', bar: 'Bar', pie: 'Torta'},
         chartTitles: {
             [CONST.SEARCH.GROUP_BY.FROM]: 'Da',
             [CONST.SEARCH.GROUP_BY.CARD]: 'Carte',
diff --git a/src/languages/ja.ts b/src/languages/ja.ts
index c4669e8b..0e6d0f51 100644
--- a/src/languages/ja.ts
+++ b/src/languages/ja.ts
@@ -7017,7 +7017,7 @@ ${reportName}
             allMatchingItemsSelected: '一致する項目をすべて選択済み',
         },
         topSpenders: 'トップ支出者',
-        view: {label: '表示', table: 'テーブル', bar: 'バー'},
+        view: {label: '表示', table: 'テーブル', bar: 'バー', pie: '円グラフ'},
         chartTitles: {
             [CONST.SEARCH.GROUP_BY.FROM]: '差出人',
             [CONST.SEARCH.GROUP_BY.CARD]: 'カード',
diff --git a/src/languages/nl.ts b/src/languages/nl.ts
index e6bd121b..3a9d1156 100644
--- a/src/languages/nl.ts
+++ b/src/languages/nl.ts
@@ -7062,7 +7062,7 @@ Vraag verplichte uitgavedetails zoals bonnetjes en beschrijvingen, stel limieten
             allMatchingItemsSelected: 'Alle overeenkomende items geselecteerd',
         },
         topSpenders: 'Grootste uitgaven',
-        view: {label: 'Bekijken', table: 'Tabel', bar: 'Bar'},
+        view: {label: 'Bekijken', table: 'Tabel', bar: 'Bar', pie: 'Cirkeldiagram'},
         chartTitles: {
             [CONST.SEARCH.GROUP_BY.FROM]: 'Van',
             [CONST.SEARCH.GROUP_BY.CARD]: 'Kaarten',
diff --git a/src/languages/pl.ts b/src/languages/pl.ts
index 89532955..7e991feb 100644
--- a/src/languages/pl.ts
+++ b/src/languages/pl.ts
@@ -7049,7 +7049,7 @@ Wymagaj szczegółów wydatków, takich jak paragony i opisy, ustawiaj limity i
             allMatchingItemsSelected: 'Wybrano wszystkie pasujące elementy',
         },
         topSpenders: 'Najwięksi wydający',
-        view: {label: 'Zobacz', table: 'Tabela', bar: 'Pasek'},
+        view: {label: 'Zobacz', table: 'Tabela', bar: 'Pasek', pie: 'Wykres kołowy'},
         chartTitles: {
             [CONST.SEARCH.GROUP_BY.FROM]: 'Od',
             [CONST.SEARCH.GROUP_BY.CARD]: 'Karty',
diff --git a/src/languages/pt-BR.ts b/src/languages/pt-BR.ts
index 74bc594d..f8fcedc1 100644
--- a/src/languages/pt-BR.ts
+++ b/src/languages/pt-BR.ts
@@ -7051,7 +7051,7 @@ Exija detalhes de despesas como recibos e descrições, defina limites e padrõe
             allMatchingItemsSelected: 'Todos os itens correspondentes selecionados',
         },
         topSpenders: 'Maiores gastadores',
-        view: {label: 'Ver', table: 'Tabela', bar: 'Bar'},
+        view: {label: 'Ver', table: 'Tabela', bar: 'Bar', pie: 'Torta'},
         chartTitles: {
             [CONST.SEARCH.GROUP_BY.FROM]: 'De',
             [CONST.SEARCH.GROUP_BY.CARD]: 'Cartões',
diff --git a/src/languages/zh-hans.ts b/src/languages/zh-hans.ts
index 41c860b4..9f93b27e 100644
--- a/src/languages/zh-hans.ts
+++ b/src/languages/zh-hans.ts
@@ -6896,7 +6896,7 @@ ${reportName}
             allMatchingItemsSelected: '已选择所有匹配的项目',
         },
         topSpenders: '最高支出者',
-        view: {label: '查看', table: '表格', bar: '栏'},
+        view: {label: '查看', table: '表格', bar: '栏', pie: '派'},
         chartTitles: {
             [CONST.SEARCH.GROUP_BY.FROM]: '来自',
             [CONST.SEARCH.GROUP_BY.CARD]: '卡片',

Note

You can apply these changes to your branch by copying the patch to your clipboard, then running pbpaste | git apply 😉

View workflow run

@borys3kk borys3kk marked this pull request as ready for review January 31, 2026 00:51
@borys3kk borys3kk requested a review from a team as a code owner January 31, 2026 00:51
Copy link
Contributor

@jasperhuangg jasperhuangg left a comment

Choose a reason for hiding this comment

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

few minor comments, overall looking really good, nice job!

@@ -0,0 +1,46 @@
import React from 'react';
Copy link
Contributor

@jasperhuangg jasperhuangg Feb 20, 2026

Choose a reason for hiding this comment

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

Should we investigate the effect of using memoization on this and the other SearchXXXXChart components? Just thinking ahead because we might be embedding these components in chats in the future with VirtualCFO and the ReportScreen is a pretty render-heavy view.

Copy link
Contributor

@mateuuszzzzz mateuuszzzzz Feb 23, 2026

Choose a reason for hiding this comment

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

Yes, this is something we should definitely investigate. @mhawryluk has already started working on embedding charts in Consierge, so we should be able to test this on his branch.

Regarding memoization, all components and hooks are currently compiled with react-compiler except for one hook. We could definitely try to fix this

Copy link
Contributor

Choose a reason for hiding this comment

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

ah cool, so probably not as big of an issue as I assumed

MonilBhavsar
MonilBhavsar previously approved these changes Feb 23, 2026
Copy link
Contributor

@MonilBhavsar MonilBhavsar left a comment

Choose a reason for hiding this comment

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

looks nice, thanks!

@MonilBhavsar
Copy link
Contributor

Perf tests are failing, you might want to merge main

Copy link
Contributor

@jasperhuangg jasperhuangg left a comment

Choose a reason for hiding this comment

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

couple more comments

// Slices are sorted by absolute value (largest first) for color assignment,
// so slice indices don't match the original data array. We map back via
// originalIndex so the tooltip can display the original (possibly negative) value.
const processedSlices = processDataIntoSlices(data, PIE_CHART_START_ANGLE);
Copy link
Contributor

Choose a reason for hiding this comment

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

memoize this?

Copy link
Contributor

Choose a reason for hiding this comment

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

@mateuuszzzzz any idea on this?

Comment on lines +80 to +118
// Hover gesture
const hoverGesture = () =>
Gesture.Hover()
.onBegin((e) => {
'worklet';

isHovering.set(true);
cursorX.set(e.x);
cursorY.set(e.y);
tooltipPosition.set({x: e.x, y: e.y - TOOLTIP_BAR_GAP});
scheduleOnRN(updateActiveSlice, e.x, e.y);
})
.onUpdate((e) => {
'worklet';

cursorX.set(e.x);
cursorY.set(e.y);
tooltipPosition.set({x: e.x, y: e.y - TOOLTIP_BAR_GAP});
scheduleOnRN(updateActiveSlice, e.x, e.y);
})
.onEnd(() => {
'worklet';

isHovering.set(false);
scheduleOnRN(setActiveSliceIndex, -1);
});

// Tap gesture for click/tap navigation
const tapGesture = () =>
Gesture.Tap().onEnd((e) => {
'worklet';

const {radius, centerX, centerY} = pieGeometry;
const sliceIndex = findSliceAtPosition(e.x, e.y, centerX, centerY, radius, 0, processedSlices);

if (sliceIndex >= 0) {
scheduleOnRN(handleSlicePress, sliceIndex);
}
});
Copy link
Contributor

Choose a reason for hiding this comment

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

already called out by GH review but we should use useCallback

const pieGeometry = {radius: Math.min(canvasWidth, canvasHeight) / 2, centerX: canvasWidth / 2, centerY: canvasHeight / 2};

// Handle hover state updates
const updateActiveSlice = (x: number, y: number) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah a lot of stuff can be used with useCallback, can we fix every callback in this file?

Comment on lines +143 to +145
if (data.length === 0) {
return null;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Just checking if this is expected that we return null here? It seems like when we are loading data, we show a loading spinner. Is a placeholder going to render in this case elsewhere?

Copy link
Contributor

@mateuuszzzzz mateuuszzzzz Feb 24, 2026

Choose a reason for hiding this comment

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

Yeah, this is more of a defensive condition. In practice, Search will render the EmptySearchView component. However, this is something we might want to revisit once we create the PR for concierge chart embeddings, as we will likely use new lightweight components instead of the main heavy search component.

@mateuuszzzzz
Copy link
Contributor

I’ve merged main, let’s see if this fixes the performance tests. I had the same issue in another PR today, and merging main resolved it

// Slices are sorted by absolute value (largest first) for color assignment,
// so slice indices don't match the original data array. We map back via
// originalIndex so the tooltip can display the original (possibly negative) value.
const processedSlices = processDataIntoSlices(data, PIE_CHART_START_ANGLE);
Copy link
Contributor

Choose a reason for hiding this comment

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

@mateuuszzzzz any idea on this?

@MonilBhavsar MonilBhavsar merged commit 7a6393d into Expensify:main Feb 25, 2026
33 checks passed
@github-actions
Copy link
Contributor

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

@OSBotify
Copy link
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
Copy link
Contributor

🚀 Deployed to staging by https://github.com/MonilBhavsar in version: 9.3.26-0 🚀

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

@izarutskaya
Copy link

Hi @borys3kk Is it internal PR?

@puneetlath
Copy link
Contributor

@izarutskaya No, we should've had QA steps here. You can test this by making sure that the view: pie option shows up and renders a pie chart when used.

  • Render pie chart with type:expense group-by:category view:pie – verify slices display correctly with distinct colors and appropriate proportions
  • Hover over slice (web) – verify tooltip shows • ()
  • Click/tap on slice – verify navigation to filtered search type:expense category:""
image

@borys3kk let's try to make sure to always have QA steps on these PRs going forward. If it's the same as the test steps you can just write "same as tests".

@borys3kk
Copy link
Contributor Author

@izarutskaya No, we should've had QA steps here. You can test this by making sure that the view: pie option shows up and renders a pie chart when used.

  • Render pie chart with type:expense group-by:category view:pie – verify slices display correctly with distinct colors and appropriate proportions
  • Hover over slice (web) – verify tooltip shows • ()
  • Click/tap on slice – verify navigation to filtered search type:expense category:""
image @borys3kk let's try to make sure to always have QA steps on these PRs going forward. If it's the same as the test steps you can just write "same as tests".

Ahh, must have missed this when filling the checklist, updated the PR's description

@puneetlath
Copy link
Contributor

Thanks!

@OSBotify
Copy link
Contributor

🚀 Deployed to production by https://github.com/puneetlath in version: 9.3.26-8 🚀

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

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.