Skip to content

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.ts
index 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.ts
index 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 axis
await expect(page).toMatchThemeScreenshots();
});
test('switches to daily granularity', async () => {
+ // daily granularity, auto y-axis
await 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.png
index c99a51941a..d3146205a6 100644
Binary 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 differ
diff --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.png
index 21c2cacc4d..0b29e0972f 100644
Binary 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 differ
diff --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.png
index 7c11c38e6b..ab8b70cc0b 100644
Binary 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 differ
diff --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.png
index 50608c0c29..da959cf11f 100644
Binary 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 differ
diff --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.png
index 582632ce92..9a7c647259 100644
Binary 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 differ
diff --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.png
index f8cbe8ebe4..75ff5a5f15 100644
Binary 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 differ
diff --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.png
new file mode 100644
index 0000000000..2411ee3392
Binary 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 differ
diff --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.png
new file mode 100644
index 0000000000..0b29e0972f
Binary 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 differ
diff --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.png
new file mode 100644
index 0000000000..ab8b70cc0b
Binary 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 differ
diff --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.png
new file mode 100644
index 0000000000..5f5555dd76
Binary 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 differ
diff --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.png
new file mode 100644
index 0000000000..d1b27318f2
Binary 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 differ
diff --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.png
new file mode 100644
index 0000000000..47fc70f372
Binary 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 differ
diff --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.png
index 86e8227fd8..c407e9bb30 100644
Binary 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 differ
diff --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.png
index ed31b9725b..9092e9eb18 100644
Binary 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 differ
diff --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.png
index e491c8fe5b..1da7d5ab2b 100644
Binary 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 differ
diff --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.png
new file mode 100644
index 0000000000..d1a849f92b
Binary 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 differ
diff --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.png
new file mode 100644
index 0000000000..6664a79792
Binary 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 differ
diff --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.png
new file mode 100644
index 0000000000..341c02eb2f
Binary 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 differ
diff --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.png
new file mode 100644
index 0000000000..c407e9bb30
Binary 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 differ
diff --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.png
new file mode 100644
index 0000000000..9092e9eb18
Binary 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 differ
diff --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.png
new file mode 100644
index 0000000000..1da7d5ab2b
Binary 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 differ
diff --git a/packages/desktop-client/src/components/reports/reports/BalanceForecast.tsx b/packages/desktop-client/src/components/reports/reports/BalanceForecast.tsx
index 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.tsx
index 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>
<linearGradient
id={gradientId}
diff --git a/packages/loot-core/src/types/models/dashboard.ts b/packages/loot-core/src/types/models/dashboard.ts
index 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.md
new file mode 100644
index 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.