A local-first personal finance app
Support Zero Based Axis in Balance Forecast Report(s) (#9129)
Ryan Jinnette8fba0e87cf7a
diff --git a/packages/desktop-client/e2e/page-models/reports-page.ts b/packages/desktop-client/e2e/page-models/reports-page.tsindex ff9afe85d4..87e324f5b0 100644--- a/packages/desktop-client/e2e/page-models/reports-page.ts+++ b/packages/desktop-client/e2e/page-models/reports-page.ts@@ -135,6 +135,16 @@ export class ReportsPage {.waitFor({ state: 'visible' });}+ async selectYAxisBase(yAxisBase: string) {+ await this.pageContent.getByRole('button', { name: 'Auto' }).click();+ const option = this.page.getByRole('button', { name: yAxisBase });+ await option.waitFor({ state: 'visible' });+ await option.click();+ await this.pageContent+ .getByRole('button', { name: yAxisBase })+ .waitFor({ state: 'visible' });+ }+async selectForecastSource(source: 'Scheduled transactions' | 'Tracking budget',) {diff --git a/packages/desktop-client/e2e/reports.test.ts b/packages/desktop-client/e2e/reports.test.tsindex b29e609b6a..d77de68ae8 100644--- a/packages/desktop-client/e2e/reports.test.ts+++ b/packages/desktop-client/e2e/reports.test.ts@@ -110,12 +110,26 @@ test.describe('Reports', () => {});test('loads balance forecast report with monthly granularity', async () => {+ // monthly granularity, auto y axisawait expect(page).toMatchThemeScreenshots();});test('switches to daily granularity', async () => {+ // daily granularity, auto y-axisawait reportsPage.selectForecastGranularity('Daily');+ await expect(page).toMatchThemeScreenshots();+ });++ test('switches to Zero-Based Y-Axis', async () => {+ // monthly granularity, zero-based y-axis+ await reportsPage.selectYAxisBase('Zero-Based');+ await expect(page).toMatchThemeScreenshots();+ });+ test('switches to daily granularity and Zero-Based Y-Axis', async () => {+ // daily granularity, zero-based y-axis+ await reportsPage.selectForecastGranularity('Daily');+ await reportsPage.selectYAxisBase('Zero-Based');await expect(page).toMatchThemeScreenshots();});diff --git a/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-loads-balance-forecast-report-with-monthly-granularity-1-chromium-linux.png b/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-loads-balance-forecast-report-with-monthly-granularity-1-chromium-linux.pngindex c99a51941a..d3146205a6 100644Binary files a/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-loads-balance-forecast-report-with-monthly-granularity-1-chromium-linux.png and b/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-loads-balance-forecast-report-with-monthly-granularity-1-chromium-linux.png differdiff --git a/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-loads-balance-forecast-report-with-monthly-granularity-2-chromium-linux.png b/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-loads-balance-forecast-report-with-monthly-granularity-2-chromium-linux.pngindex 21c2cacc4d..0b29e0972f 100644Binary files a/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-loads-balance-forecast-report-with-monthly-granularity-2-chromium-linux.png and b/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-loads-balance-forecast-report-with-monthly-granularity-2-chromium-linux.png differdiff --git a/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-loads-balance-forecast-report-with-monthly-granularity-3-chromium-linux.png b/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-loads-balance-forecast-report-with-monthly-granularity-3-chromium-linux.pngindex 7c11c38e6b..ab8b70cc0b 100644Binary files a/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-loads-balance-forecast-report-with-monthly-granularity-3-chromium-linux.png and b/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-loads-balance-forecast-report-with-monthly-granularity-3-chromium-linux.png differdiff --git a/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-loads-tracking-budget-forecast-report-1-chromium-linux.png b/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-loads-tracking-budget-forecast-report-1-chromium-linux.pngindex 50608c0c29..da959cf11f 100644Binary files a/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-loads-tracking-budget-forecast-report-1-chromium-linux.png and b/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-loads-tracking-budget-forecast-report-1-chromium-linux.png differdiff --git a/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-loads-tracking-budget-forecast-report-2-chromium-linux.png b/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-loads-tracking-budget-forecast-report-2-chromium-linux.pngindex 582632ce92..9a7c647259 100644Binary files a/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-loads-tracking-budget-forecast-report-2-chromium-linux.png and b/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-loads-tracking-budget-forecast-report-2-chromium-linux.png differdiff --git a/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-loads-tracking-budget-forecast-report-3-chromium-linux.png b/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-loads-tracking-budget-forecast-report-3-chromium-linux.pngindex f8cbe8ebe4..75ff5a5f15 100644Binary files a/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-loads-tracking-budget-forecast-report-3-chromium-linux.png and b/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-loads-tracking-budget-forecast-report-3-chromium-linux.png differdiff --git a/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-switches-to-Auto-Y-Axis-1-chromium-linux.png b/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-switches-to-Auto-Y-Axis-1-chromium-linux.pngnew file mode 100644index 0000000000..2411ee3392Binary files /dev/null and b/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-switches-to-Auto-Y-Axis-1-chromium-linux.png differdiff --git a/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-switches-to-Auto-Y-Axis-2-chromium-linux.png b/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-switches-to-Auto-Y-Axis-2-chromium-linux.pngnew file mode 100644index 0000000000..0b29e0972fBinary files /dev/null and b/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-switches-to-Auto-Y-Axis-2-chromium-linux.png differdiff --git a/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-switches-to-Auto-Y-Axis-3-chromium-linux.png b/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-switches-to-Auto-Y-Axis-3-chromium-linux.pngnew file mode 100644index 0000000000..ab8b70cc0bBinary files /dev/null and b/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-switches-to-Auto-Y-Axis-3-chromium-linux.png differdiff --git a/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-switches-to-Zero-Based-Y-Axis-1-chromium-linux.png b/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-switches-to-Zero-Based-Y-Axis-1-chromium-linux.pngnew file mode 100644index 0000000000..5f5555dd76Binary files /dev/null and b/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-switches-to-Zero-Based-Y-Axis-1-chromium-linux.png differdiff --git a/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-switches-to-Zero-Based-Y-Axis-2-chromium-linux.png b/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-switches-to-Zero-Based-Y-Axis-2-chromium-linux.pngnew file mode 100644index 0000000000..d1b27318f2Binary files /dev/null and b/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-switches-to-Zero-Based-Y-Axis-2-chromium-linux.png differdiff --git a/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-switches-to-Zero-Based-Y-Axis-3-chromium-linux.png b/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-switches-to-Zero-Based-Y-Axis-3-chromium-linux.pngnew file mode 100644index 0000000000..47fc70f372Binary files /dev/null and b/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-switches-to-Zero-Based-Y-Axis-3-chromium-linux.png differdiff --git a/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-switches-to-daily-granularity-1-chromium-linux.png b/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-switches-to-daily-granularity-1-chromium-linux.pngindex 86e8227fd8..c407e9bb30 100644Binary files a/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-switches-to-daily-granularity-1-chromium-linux.png and b/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-switches-to-daily-granularity-1-chromium-linux.png differdiff --git a/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-switches-to-daily-granularity-2-chromium-linux.png b/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-switches-to-daily-granularity-2-chromium-linux.pngindex ed31b9725b..9092e9eb18 100644Binary files a/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-switches-to-daily-granularity-2-chromium-linux.png and b/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-switches-to-daily-granularity-2-chromium-linux.png differdiff --git a/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-switches-to-daily-granularity-3-chromium-linux.png b/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-switches-to-daily-granularity-3-chromium-linux.pngindex e491c8fe5b..1da7d5ab2b 100644Binary files a/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-switches-to-daily-granularity-3-chromium-linux.png and b/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-switches-to-daily-granularity-3-chromium-linux.png differdiff --git a/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-switches-to-daily-granularity-and-Zero-Based-Y-Axis-1-chromium-linux.png b/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-switches-to-daily-granularity-and-Zero-Based-Y-Axis-1-chromium-linux.pngnew file mode 100644index 0000000000..d1a849f92bBinary files /dev/null and b/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-switches-to-daily-granularity-and-Zero-Based-Y-Axis-1-chromium-linux.png differdiff --git a/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-switches-to-daily-granularity-and-Zero-Based-Y-Axis-2-chromium-linux.png b/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-switches-to-daily-granularity-and-Zero-Based-Y-Axis-2-chromium-linux.pngnew file mode 100644index 0000000000..6664a79792Binary files /dev/null and b/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-switches-to-daily-granularity-and-Zero-Based-Y-Axis-2-chromium-linux.png differdiff --git a/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-switches-to-daily-granularity-and-Zero-Based-Y-Axis-3-chromium-linux.png b/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-switches-to-daily-granularity-and-Zero-Based-Y-Axis-3-chromium-linux.pngnew file mode 100644index 0000000000..341c02eb2fBinary files /dev/null and b/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-switches-to-daily-granularity-and-Zero-Based-Y-Axis-3-chromium-linux.png differdiff --git a/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-switches-to-daily-granularity-and-auto-Y-Axis-1-chromium-linux.png b/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-switches-to-daily-granularity-and-auto-Y-Axis-1-chromium-linux.pngnew file mode 100644index 0000000000..c407e9bb30Binary files /dev/null and b/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-switches-to-daily-granularity-and-auto-Y-Axis-1-chromium-linux.png differdiff --git a/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-switches-to-daily-granularity-and-auto-Y-Axis-2-chromium-linux.png b/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-switches-to-daily-granularity-and-auto-Y-Axis-2-chromium-linux.pngnew file mode 100644index 0000000000..9092e9eb18Binary files /dev/null and b/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-switches-to-daily-granularity-and-auto-Y-Axis-2-chromium-linux.png differdiff --git a/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-switches-to-daily-granularity-and-auto-Y-Axis-3-chromium-linux.png b/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-switches-to-daily-granularity-and-auto-Y-Axis-3-chromium-linux.pngnew file mode 100644index 0000000000..1da7d5ab2bBinary files /dev/null and b/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-switches-to-daily-granularity-and-auto-Y-Axis-3-chromium-linux.png differdiff --git a/packages/desktop-client/src/components/reports/reports/BalanceForecast.tsx b/packages/desktop-client/src/components/reports/reports/BalanceForecast.tsxindex 92c6fecd91..c9312be6ac 100644--- a/packages/desktop-client/src/components/reports/reports/BalanceForecast.tsx+++ b/packages/desktop-client/src/components/reports/reports/BalanceForecast.tsx@@ -117,6 +117,9 @@ function BalanceForecastInner({ widget }: BalanceForecastInnerProps) {const [granularity, setGranularity] = useState<'Daily' | 'Monthly'>(widget?.meta?.granularity ?? 'Monthly',);+ const [yAxisBase, setYaxisbase] = useState<'Auto' | 'Zero-Based'>(+ widget?.meta?.yAxisBase ?? 'Auto',+ );const [source, setSource] = useState<ForecastSource>(widget?.meta?.source === 'tracking-budget' && budgetType === 'tracking'? 'tracking-budget'@@ -184,6 +187,7 @@ function BalanceForecastInner({ widget }: BalanceForecastInnerProps) {startDate: start,endDate: end,granularity: isTrackingBudgetForecast ? 'Monthly' : granularity,+ yAxisBase,source,timeFrame: {start,@@ -357,6 +361,15 @@ function BalanceForecastInner({ widget }: BalanceForecastInnerProps) {['Daily', t('Daily')],]}/>+ <Select+ value={yAxisBase}+ onChange={setYaxisbase}+ disabled={isTrackingBudgetForecast}+ options={[+ ['Auto', t('Auto')],+ ['Zero-Based', t('Zero-Based')],+ ]}+ /></>);const headerChildren = widget ? (@@ -544,7 +557,13 @@ function BalanceForecastInner({ widget }: BalanceForecastInnerProps) {}}/><YAxis- domain={['auto', 'auto']}+ // if hasNegativeBalance, the builtin behavior of recharts (allowDataOverflow = false), prevents data from being hidden "under" the axis+ // also explicitly stated for future contributors+ domain={[+ yAxisBase === 'Zero-Based' ? 0 : 'auto',+ 'auto',+ ]} //+ allowDataOverflow={false}tickFormatter={formatYTick}tick={{ fill: theme.pageText }}tickLine={{ stroke: theme.pageText }}diff --git a/packages/desktop-client/src/components/reports/reports/BalanceForecastCard.tsx b/packages/desktop-client/src/components/reports/reports/BalanceForecastCard.tsxindex 01d0c9daec..aea466d470 100644--- a/packages/desktop-client/src/components/reports/reports/BalanceForecastCard.tsx+++ b/packages/desktop-client/src/components/reports/reports/BalanceForecastCard.tsx@@ -17,6 +17,7 @@ import {ReferenceLine,ResponsiveContainer,Tooltip,+ YAxis,} from 'recharts';import { PrivacyFilter } from '#components/PrivacyFilter';@@ -83,6 +84,8 @@ export function BalanceForecastCard({const startDate = monthUtils.firstDayOfMonth(start);const endDate = monthUtils.lastDayOfMonth(end);+ const yAxisBase = meta?.yAxisBase ?? 'Auto';+const {data: forecastData,error,@@ -240,8 +243,14 @@ export function BalanceForecastCard({width={width}height={height}data={chartData}+margin={{ top: 5, right: 5, left: 5, bottom: 5 }}>+ <YAxis+ hide // do not show the axis labels (balance)+ domain={[yAxisBase === 'Zero-Based' ? 0 : 'auto', 'auto']}+ allowDataOverflow={false} // false by default but explicit > implicit+ /><defs><linearGradientid={gradientId}diff --git a/packages/loot-core/src/types/models/dashboard.ts b/packages/loot-core/src/types/models/dashboard.tsindex 83e87dfb15..797ef835ca 100644--- a/packages/loot-core/src/types/models/dashboard.ts+++ b/packages/loot-core/src/types/models/dashboard.ts@@ -491,6 +491,7 @@ export type BalanceForecastWidget = AbstractWidget<conditionsOp?: 'and' | 'or';timeFrame?: TimeFrame;granularity?: 'Daily' | 'Monthly';+ yAxisBase?: 'Zero-Based' | 'Auto';source?: ForecastSource;} | null>;diff --git a/upcoming-release-notes/balance-forecast-zero-based-axis.md b/upcoming-release-notes/balance-forecast-zero-based-axis.mdnew file mode 100644index 0000000000..bbddd729a4--- /dev/null+++ b/upcoming-release-notes/balance-forecast-zero-based-axis.md@@ -0,0 +1,6 @@+---+category: Enhancements+authors: [rjinnette]+---++Add support to choose a Zero-Based y-axis or auto-generated y-axis in the balance forecast screen and widget.