Skip to content

A local-first personal finance app

[AI] Compare named balance forecast lines (#9209)

Sebastián Maluk6c4114143463
diff --git a/packages/desktop-client/e2e/reports.test.ts b/packages/desktop-client/e2e/reports.test.ts
index d77de68ae8..6286645cfd 100644
--- a/packages/desktop-client/e2e/reports.test.ts
+++ b/packages/desktop-client/e2e/reports.test.ts
@@ -133,6 +133,124 @@ test.describe('Reports', () => {
await expect(page).toMatchThemeScreenshots();
});
+ test('compares named forecast lines and saves them to the dashboard', async () => {
+ test.setTimeout(90_000);
+ await expect(page.locator('.recharts-line-curve')).toHaveCount(1);
+ await page
+ .getByRole('button', { name: 'Compare lines', exact: true })
+ .click();
+ await page
+ .getByRole('textbox', { name: 'Line 1 name', exact: true })
+ .fill('Checking');
+
+ async function selectAccounts(lineNumber: number, names: string[]) {
+ const group = page.getByRole('group', {
+ name: `Forecast line ${lineNumber}`,
+ exact: true,
+ });
+ await group
+ .getByRole('button', { name: 'Filter', exact: true })
+ .click();
+ await page
+ .getByRole('menu')
+ .getByRole('button', { name: 'Account', exact: true })
+ .click();
+ await page
+ .getByRole('textbox', { name: 'Account', exact: true })
+ .press('Escape');
+ await page.getByRole('button', { name: 'one of', exact: true }).click();
+ for (const name of names) {
+ await page
+ .getByRole('textbox', { name: 'Account', exact: true })
+ .click();
+ await page.getByRole('option', { name, exact: true }).click();
+ }
+ await page
+ .getByRole('textbox', { name: 'Account', exact: true })
+ .press('Escape');
+ await page.getByRole('button', { name: 'Apply', exact: true }).click();
+ await expect(
+ group.getByRole('button', { name: /account/ }),
+ ).toBeVisible();
+ }
+
+ await selectAccounts(1, ['Capital One Checking']);
+ await page.getByRole('button', { name: 'Add line', exact: true }).click();
+ await page
+ .getByRole('textbox', { name: 'Line 2 name', exact: true })
+ .fill('Card');
+ await selectAccounts(2, ['HSBC']);
+ await page.getByRole('button', { name: 'Add line', exact: true }).click();
+ await page
+ .getByRole('textbox', { name: 'Line 3 name', exact: true })
+ .fill('Checking + card');
+ await selectAccounts(3, ['Capital One Checking', 'HSBC']);
+ await expect(page.locator('.recharts-line-curve')).toHaveCount(3);
+ await page.getByRole('button', { name: 'Add line', exact: true }).click();
+ await expect(
+ page.getByRole('button', { name: 'Add line', exact: true }),
+ ).toBeDisabled();
+ await page
+ .getByRole('button', { name: 'Remove line 4', exact: true })
+ .click();
+ await expect(
+ page.getByRole('button', { name: 'Add line', exact: true }),
+ ).toBeEnabled();
+ await page
+ .getByRole('button', { name: 'Save widget', exact: true })
+ .click();
+ await expect(
+ page.getByText('Dashboard widget successfully saved.', { exact: true }),
+ ).toBeVisible();
+ await page
+ .getByRole('button', { name: 'Hide line editor', exact: true })
+ .click();
+ await expect(page.locator('.recharts-line-curve')).toHaveCount(3);
+ const summary = page.getByRole('table');
+ const endingBalances = await summary
+ .locator('tbody tr td:first-of-type')
+ .allTextContents();
+ const [checking, cardBalance, combined] = endingBalances.map(value =>
+ Math.round(Number(value.replaceAll(',', '')) * 100),
+ );
+ expect(checking).not.toBe(cardBalance);
+ expect(combined).toBe(checking + cardBalance);
+ const beforeSave = await summary.innerText();
+ await page.reload();
+ await expect
+ .poll(() => page.getByRole('table').innerText())
+ .toBe(beforeSave);
+ await expect(page.locator('.recharts-line-curve')).toHaveCount(3);
+ await expect(page.getByRole('main')).toMatchThemeScreenshots();
+ await page
+ .getByRole('button', { name: 'Edit lines', exact: true })
+ .click();
+ await expect(
+ page.locator('#forecast-series-editor'),
+ ).toMatchThemeScreenshots();
+ await page
+ .getByRole('button', { name: 'Hide line editor', exact: true })
+ .click();
+ const widgetUrl = page.url();
+ await navigation.goToReportsPage();
+ const card = page.getByRole('button').filter({
+ has: page.getByRole('heading', { name: /^Balance Forecast/ }),
+ });
+ await page.locator('.react-grid-item').last().scrollIntoViewIfNeeded();
+ await expect(
+ card.getByRole('rowheader', { name: 'Checking + card', exact: true }),
+ ).toBeVisible();
+ await expect(card.locator('.recharts-line-curve')).toHaveCount(3);
+ await expect(card).toMatchThemeScreenshots();
+ await page.goto(widgetUrl);
+ await page
+ .getByRole('button', { name: 'Edit lines', exact: true })
+ .click();
+ await expect(
+ page.getByRole('textbox', { name: 'Line 2 name', exact: true }),
+ ).toHaveValue('Card');
+ });
+
test('loads tracking budget forecast report', async () => {
const settingsPage = await navigation.goToSettingsPage();
await settingsPage.useBudgetType('Tracking');
diff --git a/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-compares-named-forecast-lines-and-saves-them-to-the-dashboard-1-chromium-linux.png b/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-compares-named-forecast-lines-and-saves-them-to-the-dashboard-1-chromium-linux.png
new file mode 100644
index 0000000000..e8c0d0e54c
Binary files /dev/null and b/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-compares-named-forecast-lines-and-saves-them-to-the-dashboard-1-chromium-linux.png differ
diff --git a/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-compares-named-forecast-lines-and-saves-them-to-the-dashboard-2-chromium-linux.png b/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-compares-named-forecast-lines-and-saves-them-to-the-dashboard-2-chromium-linux.png
new file mode 100644
index 0000000000..b3d8763ded
Binary files /dev/null and b/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-compares-named-forecast-lines-and-saves-them-to-the-dashboard-2-chromium-linux.png differ
diff --git a/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-compares-named-forecast-lines-and-saves-them-to-the-dashboard-3-chromium-linux.png b/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-compares-named-forecast-lines-and-saves-them-to-the-dashboard-3-chromium-linux.png
new file mode 100644
index 0000000000..caf4d3adc1
Binary files /dev/null and b/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-compares-named-forecast-lines-and-saves-them-to-the-dashboard-3-chromium-linux.png differ
diff --git a/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-compares-named-forecast-lines-and-saves-them-to-the-dashboard-4-chromium-linux.png b/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-compares-named-forecast-lines-and-saves-them-to-the-dashboard-4-chromium-linux.png
new file mode 100644
index 0000000000..dd6b0c6de4
Binary files /dev/null and b/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-compares-named-forecast-lines-and-saves-them-to-the-dashboard-4-chromium-linux.png differ
diff --git a/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-compares-named-forecast-lines-and-saves-them-to-the-dashboard-5-chromium-linux.png b/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-compares-named-forecast-lines-and-saves-them-to-the-dashboard-5-chromium-linux.png
new file mode 100644
index 0000000000..11907ae741
Binary files /dev/null and b/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-compares-named-forecast-lines-and-saves-them-to-the-dashboard-5-chromium-linux.png differ
diff --git a/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-compares-named-forecast-lines-and-saves-them-to-the-dashboard-6-chromium-linux.png b/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-compares-named-forecast-lines-and-saves-them-to-the-dashboard-6-chromium-linux.png
new file mode 100644
index 0000000000..5313404b5b
Binary files /dev/null and b/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-compares-named-forecast-lines-and-saves-them-to-the-dashboard-6-chromium-linux.png differ
diff --git a/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-compares-named-forecast-lines-and-saves-them-to-the-dashboard-7-chromium-linux.png b/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-compares-named-forecast-lines-and-saves-them-to-the-dashboard-7-chromium-linux.png
new file mode 100644
index 0000000000..911d4036c8
Binary files /dev/null and b/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-compares-named-forecast-lines-and-saves-them-to-the-dashboard-7-chromium-linux.png differ
diff --git a/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-compares-named-forecast-lines-and-saves-them-to-the-dashboard-8-chromium-linux.png b/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-compares-named-forecast-lines-and-saves-them-to-the-dashboard-8-chromium-linux.png
new file mode 100644
index 0000000000..926c678247
Binary files /dev/null and b/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-compares-named-forecast-lines-and-saves-them-to-the-dashboard-8-chromium-linux.png differ
diff --git a/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-compares-named-forecast-lines-and-saves-them-to-the-dashboard-9-chromium-linux.png b/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-compares-named-forecast-lines-and-saves-them-to-the-dashboard-9-chromium-linux.png
new file mode 100644
index 0000000000..ed33824c62
Binary files /dev/null and b/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-compares-named-forecast-lines-and-saves-them-to-the-dashboard-9-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-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 d3146205a6..f7c56e5c3a 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 0b29e0972f..33fe61d861 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 ab8b70cc0b..0d51765b0d 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-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
index 5f5555dd76..b0e315a6a7 100644
Binary files a/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-switches-to-Zero-Based-Y-Axis-1-chromium-linux.png 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
index d1b27318f2..4fcdbe710b 100644
Binary files a/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-switches-to-Zero-Based-Y-Axis-2-chromium-linux.png 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
index 47fc70f372..74630bcfaa 100644
Binary files a/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-balance-forecast-switches-to-Zero-Based-Y-Axis-3-chromium-linux.png 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 c407e9bb30..901e38ee2e 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 9092e9eb18..c911548d5e 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 1da7d5ab2b..cffc13af46 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
index d1a849f92b..e276e33702 100644
Binary files 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 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
index 6664a79792..ad33ec12e9 100644
Binary files 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 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
index 341c02eb2f..6987dd650d 100644
Binary files 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 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/src/components/reports/reports/BalanceForecast.tsx b/packages/desktop-client/src/components/reports/reports/BalanceForecast.tsx
index c9312be6ac..45b2e4da85 100644
--- a/packages/desktop-client/src/components/reports/reports/BalanceForecast.tsx
+++ b/packages/desktop-client/src/components/reports/reports/BalanceForecast.tsx
@@ -16,7 +16,10 @@ import type {
RuleConditionEntity,
TimeFrame,
} from '@actual-app/core/types/models';
-import type { ForecastSource } from '@actual-app/core/types/models/forecast';
+import type {
+ ForecastSeries,
+ ForecastSource,
+} from '@actual-app/core/types/models/forecast';
import * as d from 'date-fns';
import {
CartesianGrid,
@@ -28,6 +31,7 @@ import {
XAxis,
YAxis,
} from 'recharts';
+import { v4 as uuidv4 } from 'uuid';
import { FinancialText } from '#components/FinancialText';
import { Page, PageHeader } from '#components/Page';
@@ -38,7 +42,7 @@ import { computePadding } from '#components/reports/graphs/util/computePadding';
import { Header } from '#components/reports/Header';
import { LoadingIndicator } from '#components/reports/LoadingIndicator';
import { useAccounts } from '#hooks/useAccounts';
-import { useBalanceForecast } from '#hooks/useBalanceForecast';
+import { useBalanceForecastSeries } from '#hooks/useBalanceForecast';
import { useDashboardWidget } from '#hooks/useDashboardWidget';
import { useFormat } from '#hooks/useFormat';
import { useLocale } from '#hooks/useLocale';
@@ -54,6 +58,11 @@ import {
getLowestChartDataPoint,
getZeroCrossingGradientOffset,
} from './balanceForecastChartData';
+import { buildForecastSeriesChart } from './balanceForecastSeries';
+import { ForecastSeriesEditor } from './ForecastSeriesEditor';
+import { getForecastSeriesStyle } from './ForecastSeriesKey';
+import { ForecastSeriesSummary } from './ForecastSeriesSummary';
+import { ForecastSeriesTooltip } from './ForecastSeriesTooltip';
export function BalanceForecast() {
const params = useParams();
@@ -126,6 +135,11 @@ function BalanceForecastInner({ widget }: BalanceForecastInnerProps) {
: 'schedules',
);
const isTrackingBudgetForecast = source === 'tracking-budget';
+ const [series, setSeries] = useState<ForecastSeries[] | undefined>(
+ widget?.meta?.series?.length ? widget.meta.series : undefined,
+ );
+ const [isEditingSeries, setIsEditingSeries] = useState(false);
+ const activeSeries = isTrackingBudgetForecast ? undefined : series;
useEffect(() => {
if (budgetType !== 'tracking' && source === 'tracking-budget') {
@@ -142,12 +156,13 @@ function BalanceForecastInner({ widget }: BalanceForecastInnerProps) {
const startDate = monthUtils.firstDayOfMonth(start);
const endDate = monthUtils.lastDayOfMonth(end);
const {
- data: forecastData,
+ data: forecasts,
error,
isFetching,
isPlaceholderData,
isPending: isLoading,
- } = useBalanceForecast({
+ } = useBalanceForecastSeries({
+ series: activeSeries,
accountIds: isTrackingBudgetForecast
? undefined
: widget
@@ -163,6 +178,7 @@ function BalanceForecastInner({ widget }: BalanceForecastInnerProps) {
source,
enabled: hasMonthOptions,
});
+ const forecastData = forecasts?.[0]?.forecast;
const errorMessage =
error instanceof Error
? error.message
@@ -189,6 +205,19 @@ function BalanceForecastInner({ widget }: BalanceForecastInnerProps) {
granularity: isTrackingBudgetForecast ? 'Monthly' : granularity,
yAxisBase,
source,
+ ...(series
+ ? {
+ series: series.map((line, index) => ({
+ ...line,
+ name:
+ line.name.trim() ||
+ t('Line {{number}}', { number: index + 1 }),
+ })),
+ accounts: series[0].accounts,
+ conditions: series[0].conditions,
+ conditionsOp: series[0].conditionsOp,
+ }
+ : {}),
timeFrame: {
start,
end,
@@ -306,12 +335,20 @@ function BalanceForecastInner({ widget }: BalanceForecastInnerProps) {
end: chartRange.end,
granularity,
});
+ const comparison = buildForecastSeriesChart({
+ forecasts,
+ series: activeSeries?.map((line, index) => ({
+ ...line,
+ name: line.name.trim() || t('Line {{number}}', { number: index + 1 }),
+ })),
+ start: chartRange.start,
+ end: chartRange.end,
+ granularity,
+ });
+ const visibleChartData = activeSeries ? comparison.chartData : chartData;
const formatYTick = (value: number) =>
getCustomTick(format(value, 'financial-no-decimals'), privacyMode);
- const yAxisLeftPadding = computePadding(
- chartData.map(point => point.balance),
- formatYTick,
- );
+ const yAxisLeftPadding = computePadding(comparison.balances, formatYTick);
const isUpdatingForecast = isFetching && isPlaceholderData;
const scheduledOccurrenceCount = countForecastScheduledOccurrences({
@@ -331,13 +368,13 @@ function BalanceForecastInner({ widget }: BalanceForecastInnerProps) {
const endingPoint = chartData.at(-1);
const lowestPoint = getLowestChartDataPoint(chartData);
- const hasNegativeBalance = chartData.some(d => d.balance < 0);
+ const hasNegativeBalance = comparison.balances.some(balance => balance < 0);
const zeroCrossingGradientOffset = getZeroCrossingGradientOffset(chartData);
const todayReferenceDate =
granularity === 'Daily'
? monthUtils.currentDay()
: monthUtils.currentMonth();
- const showsTodayReferenceLine = chartData.some(
+ const showsTodayReferenceLine = visibleChartData.some(
dataPoint => dataPoint.date === todayReferenceDate,
);
const headerInlineContent = (
@@ -370,6 +407,34 @@ function BalanceForecastInner({ widget }: BalanceForecastInnerProps) {
['Zero-Based', t('Zero-Based')],
]}
/>
+ {!isTrackingBudgetForecast && (
+ <Button
+ aria-expanded={isEditingSeries}
+ aria-controls="forecast-series-editor"
+ onPress={() => {
+ if (!series) {
+ setSeries([
+ {
+ id: uuidv4(),
+ name: t('Line {{number}}', { number: 1 }),
+ accounts: widget?.meta?.accounts,
+ conditions,
+ conditionsOp,
+ },
+ ]);
+ }
+ setIsEditingSeries(!isEditingSeries);
+ }}
+ >
+ {isEditingSeries ? (
+ <Trans>Hide line editor</Trans>
+ ) : series ? (
+ <Trans>Edit lines</Trans>
+ ) : (
+ <Trans>Compare lines</Trans>
+ )}
+ </Button>
+ )}
</>
);
const headerChildren = widget ? (
@@ -383,7 +448,7 @@ function BalanceForecastInner({ widget }: BalanceForecastInnerProps) {
header={<PageHeader title={<Trans>Balance Forecast</Trans>} />}
padding={0}
>
- {isTrackingBudgetForecast ? (
+ {isTrackingBudgetForecast || activeSeries ? (
<Header
allMonths={allMonths}
start={start}
@@ -397,6 +462,9 @@ function BalanceForecastInner({ widget }: BalanceForecastInnerProps) {
mode={mode}
onChangeDates={onChangeDates}
showFutureRange
+ granularities={
+ isTrackingBudgetForecast ? undefined : ['month', 'day']
+ }
hideModeToggle
inlineContent={headerInlineContent}
>
@@ -435,14 +503,21 @@ function BalanceForecastInner({ widget }: BalanceForecastInnerProps) {
backgroundColor: theme.tableBackground,
padding: 20,
paddingTop: 0,
- flex: '1 0 auto',
+ flex: activeSeries ? 1 : '1 0 auto',
overflowY: 'auto',
}}
>
+ {activeSeries && isEditingSeries && (
+ <ForecastSeriesEditor series={activeSeries} onChange={setSeries} />
+ )}
{errorMessage ? (
<div style={{ color: theme.errorText, marginBottom: 20 }}>
{errorMessage}
</div>
+ ) : activeSeries ? (
+ <View style={{ paddingTop: 16, flexShrink: 0 }}>
+ <ForecastSeriesSummary lines={comparison.lines} />
+ </View>
) : endingPoint ? (
<View
style={{
@@ -489,7 +564,7 @@ function BalanceForecastInner({ widget }: BalanceForecastInnerProps) {
) : null}
<div style={{ flex: 1, minHeight: 300 }}>
- {errorMessage ? null : chartData.length > 0 ? (
+ {errorMessage ? null : visibleChartData.length > 0 ? (
<>
<Container>
{(width, height) => (
@@ -497,7 +572,7 @@ function BalanceForecastInner({ widget }: BalanceForecastInnerProps) {
<LineChart
width={width}
height={height}
- data={chartData}
+ data={visibleChartData}
margin={{
top: 10,
right: 10,
@@ -542,9 +617,11 @@ function BalanceForecastInner({ widget }: BalanceForecastInnerProps) {
tick={{ fill: theme.pageText }}
tickLine={{ stroke: theme.pageText }}
interval={
- granularity === 'Daily'
- ? Math.ceil(chartData.length / 10)
- : 0
+ activeSeries
+ ? 'preserveStartEnd'
+ : granularity === 'Daily'
+ ? Math.ceil(visibleChartData.length / 10)
+ : 0
}
tickFormatter={value => {
if (granularity === 'Daily') {
@@ -573,6 +650,14 @@ function BalanceForecastInner({ widget }: BalanceForecastInnerProps) {
isAnimationActive={false}
content={({ active, payload }) => {
if (active && payload && payload.length) {
+ if (activeSeries) {
+ return (
+ <ForecastSeriesTooltip
+ date={payload[0].payload.date}
+ lines={comparison.lines}
+ />
+ );
+ }
return (
<div
style={{
@@ -617,15 +702,32 @@ function BalanceForecastInner({ widget }: BalanceForecastInnerProps) {
{hasNegativeBalance && (
<ReferenceLine y={0} stroke={theme.pageTextSubdued} />
)}
- <Line
- type="monotone"
- dataKey="balance"
- stroke="url(#balance-forecast-line-gradient)"
- strokeWidth={2}
- dot={false}
- activeDot={{ r: 6 }}
- opacity={isUpdatingForecast ? 0.45 : 1}
- />
+ {activeSeries ? (
+ comparison.lines.map((line, index) => (
+ <Line
+ key={line.id}
+ name={line.name}
+ dataKey={line.dataKey}
+ type="monotone"
+ {...getForecastSeriesStyle(index)}
+ strokeWidth={2}
+ dot={false}
+ activeDot={{ r: 6 }}
+ isAnimationActive={false}
+ opacity={isUpdatingForecast ? 0.45 : 1}
+ />
+ ))
+ ) : (
+ <Line
+ type="monotone"
+ dataKey="balance"
+ stroke="url(#balance-forecast-line-gradient)"
+ strokeWidth={2}
+ dot={false}
+ activeDot={{ r: 6 }}
+ opacity={isUpdatingForecast ? 0.45 : 1}
+ />
+ )}
</LineChart>
</ResponsiveContainer>
)}
@@ -637,7 +739,12 @@ function BalanceForecastInner({ widget }: BalanceForecastInnerProps) {
color: theme.pageTextLight,
}}
>
- {isTrackingBudgetForecast ? (
+ {activeSeries ? (
+ <Trans>
+ Each line includes its own matching transactions and
+ upcoming schedules. Lines are not added together.
+ </Trans>
+ ) : isTrackingBudgetForecast ? (
<Trans>
Tracking budget forecast uses on-budget balance plus monthly
budgeted income minus budgeted expenses.
@@ -685,7 +792,13 @@ function BalanceForecastInner({ widget }: BalanceForecastInnerProps) {
<div
style={{ marginTop: 20, fontSize: 12, color: theme.pageTextLight }}
>
- {hasFilters ? (
+ {activeSeries ? (
+ <Trans>
+ Transaction filters show a running total of matches, not
+ necessarily an account balance. Transfers between selected
+ accounts offset each other when both sides match.
+ </Trans>
+ ) : hasFilters ? (
<Trans>
This forecast shows the running total of matching posted
transactions, plus upcoming scheduled transactions in the
diff --git a/packages/desktop-client/src/components/reports/reports/BalanceForecastCard.tsx b/packages/desktop-client/src/components/reports/reports/BalanceForecastCard.tsx
index aea466d470..7997d0cbde 100644
--- a/packages/desktop-client/src/components/reports/reports/BalanceForecastCard.tsx
+++ b/packages/desktop-client/src/components/reports/reports/BalanceForecastCard.tsx
@@ -27,7 +27,7 @@ import { LoadingIndicator } from '#components/reports/LoadingIndicator';
import { ReportCard } from '#components/reports/ReportCard';
import { ReportCardName } from '#components/reports/ReportCardName';
import { calculateTimeRange } from '#components/reports/reportRanges';
-import { useBalanceForecast } from '#hooks/useBalanceForecast';
+import { useBalanceForecastSeries } from '#hooks/useBalanceForecast';
import { useFormat } from '#hooks/useFormat';
import { useSyncedPref } from '#hooks/useSyncedPref';
@@ -37,6 +37,10 @@ import {
getLowestChartDataPoint,
getZeroCrossingGradientOffset,
} from './balanceForecastChartData';
+import { buildForecastSeriesChart } from './balanceForecastSeries';
+import { getForecastSeriesStyle } from './ForecastSeriesKey';
+import { ForecastSeriesSummary } from './ForecastSeriesSummary';
+import { ForecastSeriesTooltip } from './ForecastSeriesTooltip';
type BalanceForecastCardProps = {
widgetId: string;
@@ -63,6 +67,8 @@ export function BalanceForecastCard({
: 'schedules';
const isTrackingBudgetForecast = source === 'tracking-budget';
const granularity = meta?.granularity || 'Monthly';
+ const series =
+ !isTrackingBudgetForecast && meta?.series?.length ? meta.series : undefined;
const [nameMenuOpen, setNameMenuOpen] = useState(false);
const [isCardHovered, setIsCardHovered] = useState(false);
@@ -87,12 +93,13 @@ export function BalanceForecastCard({
const yAxisBase = meta?.yAxisBase ?? 'Auto';
const {
- data: forecastData,
+ data: forecasts,
error,
isFetching,
isPlaceholderData,
isPending: isLoading,
- } = useBalanceForecast({
+ } = useBalanceForecastSeries({
+ series,
accountIds: isTrackingBudgetForecast ? undefined : selectedAccountIds,
conditions: isTrackingBudgetForecast ? undefined : meta?.conditions,
conditionsOp: isTrackingBudgetForecast ? undefined : meta?.conditionsOp,
@@ -103,6 +110,7 @@ export function BalanceForecastCard({
: meta?.accounts === undefined,
source,
});
+ const forecastData = forecasts?.[0]?.forecast;
const errorMessage =
error instanceof Error
? error.message
@@ -130,15 +138,26 @@ export function BalanceForecastCard({
end: chartRange.end,
granularity,
});
+ const comparison = buildForecastSeriesChart({
+ forecasts,
+ series: series?.map((line, index) => ({
+ ...line,
+ name: line.name.trim() || t('Line {{number}}', { number: index + 1 }),
+ })),
+ start: chartRange.start,
+ end: chartRange.end,
+ granularity,
+ });
+ const visibleChartData = series ? comparison.chartData : chartData;
const endingPoint = chartData.at(-1);
const lowestPoint = getLowestChartDataPoint(chartData);
const hasNegativeEndingBalance = endingPoint && endingPoint.balance < 0;
- const hasNegativeBalance = chartData.some(d => d.balance < 0);
+ const hasNegativeBalance = comparison.balances.some(balance => balance < 0);
const zeroCrossingGradientOffset = getZeroCrossingGradientOffset(chartData);
const gradientId = `balance-forecast-card-line-gradient-${widgetId}`;
const isUpdatingForecast = isFetching && isPlaceholderData;
const todayReferenceDate = monthUtils.currentMonth();
- const showsTodayReferenceLine = chartData.some(
+ const showsTodayReferenceLine = visibleChartData.some(
dataPoint => dataPoint.date === todayReferenceDate,
);
@@ -164,7 +183,9 @@ export function BalanceForecastCard({
onPointerEnter={onCardHover}
onPointerLeave={onCardHoverEnd}
>
- <View style={{ flexDirection: 'row', padding: 20 }}>
+ <View
+ style={{ flexDirection: 'row', padding: series ? '12px 20px' : 20 }}
+ >
<View style={{ flex: 1 }}>
<ReportCardName
name={meta?.name || t('Balance Forecast')}
@@ -180,7 +201,7 @@ export function BalanceForecastCard({
/>
<DateRange start={start} end={end} />
</View>
- {endingPoint && (
+ {!series && endingPoint && (
<View style={{ textAlign: 'right' }}>
<Block
style={{
@@ -220,6 +241,16 @@ export function BalanceForecastCard({
)}
</View>
+ {series && !errorMessage && (
+ <View style={{ padding: '0 20px', minHeight: 0, flexShrink: 1 }}>
+ <ForecastSeriesSummary
+ lines={comparison.lines}
+ compact
+ isHovered={isCardHovered}
+ />
+ </View>
+ )}
+
{isLoading && !normalizedForecastData ? (
<LoadingIndicator />
) : errorMessage ? (
@@ -234,16 +265,21 @@ export function BalanceForecastCard({
{errorMessage}
</Block>
</View>
- ) : forecastData && forecastData.dataPoints.length > 0 ? (
+ ) : visibleChartData.length > 0 ? (
<>
- <Container style={{ height: 'auto', flex: 1 }}>
+ <Container
+ style={{
+ height: 'auto',
+ flex: 1,
+ minHeight: series ? 60 : undefined,
+ }}
+ >
{(width, height) => (
<ResponsiveContainer>
<LineChart
width={width}
height={height}
- data={chartData}
-
+ data={visibleChartData}
margin={{ top: 5, right: 5, left: 5, bottom: 5 }}
>
<YAxis
@@ -286,6 +322,14 @@ export function BalanceForecastCard({
isAnimationActive={false}
content={({ active, payload }) => {
if (active && payload && payload.length) {
+ if (series) {
+ return (
+ <ForecastSeriesTooltip
+ date={payload[0].payload.date}
+ lines={comparison.lines}
+ />
+ );
+ }
return (
<div
style={{
@@ -323,61 +367,80 @@ export function BalanceForecastCard({
{hasNegativeBalance && (
<ReferenceLine y={0} stroke={theme.pageTextSubdued} />
)}
- <Line
- type="monotone"
- dataKey="balance"
- stroke={`url(#${gradientId})`}
- strokeWidth={2}
- dot={false}
- activeDot={{ r: 4 }}
- opacity={isUpdatingForecast ? 0.45 : 1}
- />
+ {series ? (
+ comparison.lines.map((line, index) => (
+ <Line
+ key={line.id}
+ name={line.name}
+ dataKey={line.dataKey}
+ type="monotone"
+ {...getForecastSeriesStyle(index)}
+ strokeWidth={2}
+ dot={false}
+ activeDot={{ r: 4 }}
+ isAnimationActive={false}
+ opacity={isUpdatingForecast ? 0.45 : 1}
+ />
+ ))
+ ) : (
+ <Line
+ type="monotone"
+ dataKey="balance"
+ stroke={`url(#${gradientId})`}
+ strokeWidth={2}
+ dot={false}
+ activeDot={{ r: 4 }}
+ opacity={isUpdatingForecast ? 0.45 : 1}
+ />
+ )}
</LineChart>
</ResponsiveContainer>
)}
</Container>
- <Block
- style={{
- padding: '0 20px 16px',
- fontSize: 12,
- color: theme.pageTextLight,
- }}
- >
- {isTrackingBudgetForecast ? (
- <Trans>
- Forecast = starting balance + budgeted income - budgeted
- expenses
- </Trans>
- ) : scheduledOccurrenceCount === 0 ? (
- hasFilters ? (
+ {!series && (
+ <Block
+ style={{
+ padding: '0 20px 16px',
+ fontSize: 12,
+ color: theme.pageTextLight,
+ }}
+ >
+ {isTrackingBudgetForecast ? (
<Trans>
- Filtered running total only; no scheduled occurrences in
- this range
+ Forecast = starting balance + budgeted income - budgeted
+ expenses
</Trans>
+ ) : scheduledOccurrenceCount === 0 ? (
+ hasFilters ? (
+ <Trans>
+ Filtered running total only; no scheduled occurrences in
+ this range
+ </Trans>
+ ) : (
+ <Trans>No scheduled transactions in this range</Trans>
+ )
) : (
- <Trans>No scheduled transactions in this range</Trans>
- )
- ) : (
- <>
- <Trans count={scheduledOccurrenceCount}>
- {{ count: scheduledOccurrenceCount }} scheduled transactions
- included
- </Trans>
- {hasFilters ? (
- <>
- {' '}
- <Trans>(filtered running total)</Trans>
- </>
- ) : null}
- </>
- )}
- {isUpdatingForecast ? (
- <>
- {' '}
- <Trans>Updating...</Trans>
- </>
- ) : null}
- </Block>
+ <>
+ <Trans count={scheduledOccurrenceCount}>
+ {{ count: scheduledOccurrenceCount }} scheduled
+ transactions included
+ </Trans>
+ {hasFilters ? (
+ <>
+ {' '}
+ <Trans>(filtered running total)</Trans>
+ </>
+ ) : null}
+ </>
+ )}
+ {isUpdatingForecast ? (
+ <>
+ {' '}
+ <Trans>Updating...</Trans>
+ </>
+ ) : null}
+ </Block>
+ )}
</>
) : (
<View style={{ height: 120, padding: 20 }}>
diff --git a/packages/desktop-client/src/components/reports/reports/ForecastSeriesEditor.tsx b/packages/desktop-client/src/components/reports/reports/ForecastSeriesEditor.tsx
new file mode 100644
index 0000000000..bd0dab95ac
--- /dev/null
+++ b/packages/desktop-client/src/components/reports/reports/ForecastSeriesEditor.tsx
@@ -0,0 +1,197 @@
+import { Trans, useTranslation } from 'react-i18next';
+
+import { Button } from '@actual-app/components/button';
+import { Input } from '@actual-app/components/input';
+import { theme } from '@actual-app/components/theme';
+import { View } from '@actual-app/components/view';
+import type { RuleConditionEntity } from '@actual-app/core/types/models';
+import type { ForecastSeries } from '@actual-app/core/types/models/forecast';
+import { v4 as uuidv4 } from 'uuid';
+
+import { AppliedFilters } from '#components/filters/AppliedFilters';
+import { FilterButton } from '#components/filters/FiltersMenu';
+import { PrivacyFilter } from '#components/PrivacyFilter';
+import { useAccounts } from '#hooks/useAccounts';
+
+import { MAX_FORECAST_SERIES } from './balanceForecastSeries';
+import { ForecastSeriesKey } from './ForecastSeriesKey';
+
+export function ForecastSeriesEditor({
+ series,
+ onChange,
+}: {
+ series: ForecastSeries[];
+ onChange: (series: ForecastSeries[]) => void;
+}) {
+ const { t } = useTranslation();
+ const { data: accounts = [] } = useAccounts();
+
+ function updateLine(id: string, changes: Partial<ForecastSeries>) {
+ onChange(
+ series.map(line => (line.id === id ? { ...line, ...changes } : line)),
+ );
+ }
+
+ return (
+ <View
+ id="forecast-series-editor"
+ style={{ gap: 12, padding: '16px 0', flexShrink: 0 }}
+ >
+ {series.map((line, index) => (
+ <View
+ key={line.id}
+ role="group"
+ aria-label={t('Forecast line {{number}}', { number: index + 1 })}
+ style={{
+ gap: 8,
+ paddingBottom: 12,
+ borderBottom: `1px solid ${theme.tableBorder}`,
+ }}
+ >
+ <View
+ style={{
+ flexDirection: 'row',
+ alignItems: 'center',
+ flexWrap: 'wrap',
+ gap: 8,
+ }}
+ >
+ <ForecastSeriesKey
+ index={index}
+ name={t('Line {{number}}', { number: index + 1 })}
+ />
+ <Input
+ aria-label={t('Line {{number}} name', { number: index + 1 })}
+ value={line.name}
+ maxLength={80}
+ onChange={event =>
+ updateLine(line.id, { name: event.target.value })
+ }
+ style={{ width: 200, maxWidth: '100%' }}
+ />
+ <FilterButton
+ compact={false}
+ hover={false}
+ onApply={(
+ filter:
+ | RuleConditionEntity
+ | {
+ conditions: RuleConditionEntity[];
+ conditionsOp: 'and' | 'or';
+ }
+ | null,
+ ) => {
+ if (filter === null) {
+ updateLine(line.id, { conditions: [] });
+ } else if ('conditions' in filter) {
+ updateLine(line.id, {
+ conditions: filter.conditions,
+ conditionsOp: filter.conditionsOp,
+ });
+ } else {
+ updateLine(line.id, {
+ conditions: [...line.conditions, filter],
+ });
+ }
+ }}
+ />
+ <Button
+ variant="bare"
+ isDisabled={series.length === 1}
+ aria-label={t('Remove line {{number}}', { number: index + 1 })}
+ onPress={() =>
+ onChange(series.filter(item => item.id !== line.id))
+ }
+ >
+ <Trans>Remove</Trans>
+ </Button>
+ </View>
+ {line.accounts !== undefined && (
+ <View
+ style={{
+ flexDirection: 'row',
+ alignItems: 'center',
+ flexWrap: 'wrap',
+ gap: 8,
+ }}
+ >
+ <span>
+ <Trans>Saved account selection</Trans>:{' '}
+ <PrivacyFilter>
+ {accounts
+ .filter(account => line.accounts?.includes(account.id))
+ .map(account => account.name)
+ .join(', ') || t('No accounts')}
+ </PrivacyFilter>
+ </span>
+ <Button
+ variant="bare"
+ onPress={() => updateLine(line.id, { accounts: undefined })}
+ >
+ <Trans>Clear account limit</Trans>
+ </Button>
+ </View>
+ )}
+ {line.conditions.length ? (
+ <AppliedFilters
+ conditions={line.conditions}
+ conditionsOp={line.conditionsOp}
+ onUpdate={(oldFilter, newFilter) =>
+ updateLine(line.id, {
+ conditions: line.conditions.map(filter =>
+ filter === oldFilter ? newFilter : filter,
+ ),
+ })
+ }
+ onDelete={deleted =>
+ updateLine(line.id, {
+ conditions: line.conditions.filter(
+ filter => filter !== deleted,
+ ),
+ })
+ }
+ onConditionsOpChange={conditionsOp =>
+ updateLine(line.id, { conditionsOp })
+ }
+ />
+ ) : (
+ <span style={{ color: theme.pageTextLight }}>
+ <Trans>No transaction filters</Trans>
+ </span>
+ )}
+ </View>
+ ))}
+ <View
+ style={{
+ flexDirection: 'row',
+ alignItems: 'center',
+ gap: 12,
+ flexWrap: 'wrap',
+ }}
+ >
+ <Button
+ isDisabled={series.length >= MAX_FORECAST_SERIES}
+ onPress={() =>
+ onChange([
+ ...series,
+ {
+ id: uuidv4(),
+ name: t('Line {{number}}', { number: series.length + 1 }),
+ conditions: [],
+ conditionsOp: 'and',
+ },
+ ])
+ }
+ >
+ <Trans>Add line</Trans>
+ </Button>
+ <span style={{ color: theme.pageTextLight }}>
+ <Trans>
+ Compare up to four lines. To combine accounts, select them in one
+ line's filters.
+ </Trans>
+ </span>
+ </View>
+ </View>
+ );
+}
diff --git a/packages/desktop-client/src/components/reports/reports/ForecastSeriesKey.tsx b/packages/desktop-client/src/components/reports/reports/ForecastSeriesKey.tsx
new file mode 100644
index 0000000000..cf4790d116
--- /dev/null
+++ b/packages/desktop-client/src/components/reports/reports/ForecastSeriesKey.tsx
@@ -0,0 +1,43 @@
+import { theme } from '@actual-app/components/theme';
+import { View } from '@actual-app/components/view';
+
+import { PrivacyFilter } from '#components/PrivacyFilter';
+
+export function ForecastSeriesKey({
+ index,
+ name,
+}: {
+ index: number;
+ name: string;
+}) {
+ const style = getForecastSeriesStyle(index);
+ return (
+ <View
+ style={{
+ flexDirection: 'row',
+ alignItems: 'center',
+ gap: 8,
+ minWidth: 0,
+ }}
+ >
+ <svg width={24} height={12} aria-hidden="true" style={{ flexShrink: 0 }}>
+ <line x1={0} y1={6} x2={24} y2={6} strokeWidth={2} {...style} />
+ </svg>
+ <PrivacyFilter>
+ <span style={{ overflowWrap: 'anywhere' }}>{name}</span>
+ </PrivacyFilter>
+ </View>
+ );
+}
+
+export function getForecastSeriesStyle(index: number) {
+ return {
+ stroke: [
+ theme.reportsChartFill,
+ theme.reportsBlue,
+ theme.reportsRed,
+ theme.reportsGray,
+ ][index % 4],
+ strokeDasharray: [undefined, '8 4', '3 3', '10 3 2 3'][index % 4],
+ };
+}
diff --git a/packages/desktop-client/src/components/reports/reports/ForecastSeriesSummary.tsx b/packages/desktop-client/src/components/reports/reports/ForecastSeriesSummary.tsx
new file mode 100644
index 0000000000..f18b031251
--- /dev/null
+++ b/packages/desktop-client/src/components/reports/reports/ForecastSeriesSummary.tsx
@@ -0,0 +1,126 @@
+import { Trans } from 'react-i18next';
+
+import { theme } from '@actual-app/components/theme';
+import { View } from '@actual-app/components/view';
+
+import { FinancialText } from '#components/FinancialText';
+import { PrivacyFilter } from '#components/PrivacyFilter';
+import { useFormat } from '#hooks/useFormat';
+
+import type { ForecastChartLine } from './balanceForecastSeries';
+import { ForecastSeriesKey } from './ForecastSeriesKey';
+
+export function ForecastSeriesSummary({
+ lines,
+ compact = false,
+ isHovered = false,
+}: {
+ lines: ForecastChartLine[];
+ compact?: boolean;
+ isHovered?: boolean;
+}) {
+ const format = useFormat();
+ return (
+ <View style={{ overflow: 'auto', marginBottom: compact ? 4 : 16 }}>
+ <table
+ style={{ width: '100%', borderCollapse: 'collapse', fontSize: 12 }}
+ >
+ <thead>
+ <tr style={{ color: theme.pageTextLight }}>
+ <th
+ scope="col"
+ style={{
+ textAlign: 'left',
+ fontWeight: 400,
+ paddingBottom: compact ? 4 : 8,
+ }}
+ >
+ <Trans>Line</Trans>
+ </th>
+ <th
+ scope="col"
+ style={{
+ textAlign: 'right',
+ fontWeight: 400,
+ paddingBottom: compact ? 4 : 8,
+ }}
+ >
+ <Trans>Ending Balance</Trans>
+ </th>
+ {!compact && (
+ <th
+ scope="col"
+ style={{
+ textAlign: 'right',
+ fontWeight: 400,
+ paddingBottom: 8,
+ }}
+ >
+ <Trans>Lowest visible point</Trans>
+ </th>
+ )}
+ </tr>
+ </thead>
+ <tbody>
+ {lines.map((line, index) => (
+ <tr key={line.id}>
+ <th
+ scope="row"
+ style={{
+ textAlign: 'left',
+ fontWeight: 400,
+ padding: compact ? '2px 12px 2px 0' : '4px 12px 4px 0',
+ }}
+ >
+ <ForecastSeriesKey index={index} name={line.name} />
+ </th>
+ <td
+ style={{
+ textAlign: 'right',
+ whiteSpace: 'nowrap',
+ padding: compact ? '2px 0' : '4px 0',
+ }}
+ >
+ {line.endingPoint ? (
+ <FinancialText>
+ <PrivacyFilter
+ activationFilters={compact ? [!isHovered] : undefined}
+ >
+ {format(line.endingPoint.balance, 'financial')}
+ </PrivacyFilter>
+ </FinancialText>
+ ) : (
+ <Trans>No data</Trans>
+ )}
+ </td>
+ {!compact && (
+ <td
+ style={{
+ textAlign: 'right',
+ whiteSpace: 'nowrap',
+ padding: '4px 0 4px 16px',
+ }}
+ >
+ {line.lowestPoint ? (
+ <>
+ <FinancialText>
+ <PrivacyFilter>
+ {format(line.lowestPoint.balance, 'financial')}
+ </PrivacyFilter>
+ </FinancialText>{' '}
+ <span style={{ color: theme.pageTextLight }}>
+ ({line.lowestPoint.date})
+ </span>
+ </>
+ ) : (
+ <Trans>No data</Trans>
+ )}
+ </td>
+ )}
+ </tr>
+ ))}
+ </tbody>
+ </table>
+ </View>
+ );
+}
diff --git a/packages/desktop-client/src/components/reports/reports/ForecastSeriesTooltip.tsx b/packages/desktop-client/src/components/reports/reports/ForecastSeriesTooltip.tsx
new file mode 100644
index 0000000000..fb43c2c982
--- /dev/null
+++ b/packages/desktop-client/src/components/reports/reports/ForecastSeriesTooltip.tsx
@@ -0,0 +1,54 @@
+import { theme } from '@actual-app/components/theme';
+
+import { FinancialText } from '#components/FinancialText';
+import { PrivacyFilter } from '#components/PrivacyFilter';
+import { useFormat } from '#hooks/useFormat';
+
+import type { ForecastChartLine } from './balanceForecastSeries';
+import { ForecastSeriesKey } from './ForecastSeriesKey';
+
+export function ForecastSeriesTooltip({
+ date,
+ lines,
+}: {
+ date: string;
+ lines: ForecastChartLine[];
+}) {
+ const format = useFormat();
+ return (
+ <div
+ style={{
+ borderRadius: 2,
+ boxShadow: '0 1px 6px rgba(0, 0, 0, .20)',
+ backgroundColor: theme.menuBackground,
+ color: theme.menuItemText,
+ padding: 10,
+ }}
+ >
+ <strong>{date}</strong>
+ {lines.map((line, index) => {
+ const point = line.points.find(point => point.date === date);
+ return (
+ point && (
+ <div
+ key={line.id}
+ style={{
+ display: 'flex',
+ justifyContent: 'space-between',
+ gap: 16,
+ marginTop: 8,
+ }}
+ >
+ <ForecastSeriesKey index={index} name={line.name} />
+ <FinancialText>
+ <PrivacyFilter>
+ {format(point.balance, 'financial')}
+ </PrivacyFilter>
+ </FinancialText>
+ </div>
+ )
+ );
+ })}
+ </div>
+ );
+}
diff --git a/packages/desktop-client/src/components/reports/reports/balanceForecastSeries.test.ts b/packages/desktop-client/src/components/reports/reports/balanceForecastSeries.test.ts
new file mode 100644
index 0000000000..4fc7685279
--- /dev/null
+++ b/packages/desktop-client/src/components/reports/reports/balanceForecastSeries.test.ts
@@ -0,0 +1,127 @@
+import type {
+ ForecastResult,
+ ForecastSeries,
+} from '@actual-app/core/types/models/forecast';
+import { describe, expect, it } from 'vitest';
+
+import { buildForecastSeriesChart } from './balanceForecastSeries';
+
+function forecast(points: Array<[string, number, string?]>): ForecastResult {
+ return {
+ dataPoints: points.map(([date, balance, accountId = 'account']) => ({
+ date,
+ balance,
+ accountId,
+ accountName: accountId,
+ transactions: [],
+ })),
+ lowestBalance: {
+ date: '2026-10-01',
+ balance: 0,
+ accountId: '',
+ accountName: '',
+ },
+ forecastStartDate: '2026-10-01',
+ forecastEndDate: '2026-11-30',
+ };
+}
+
+const series: ForecastSeries[] = [
+ { id: 'checking', name: 'Cash', conditions: [], conditionsOp: 'and' },
+ { id: 'card', name: 'Card', conditions: [], conditionsOp: 'and' },
+];
+
+describe('buildForecastSeriesChart', () => {
+ it('keeps signed balances independent and carries each line into the visible daily range', () => {
+ const result = buildForecastSeriesChart({
+ series,
+ start: '2026-10-02',
+ end: '2026-10-04',
+ granularity: 'Daily',
+ forecasts: [
+ {
+ id: 'checking',
+ forecast: forecast([
+ ['2026-10-01', 12000],
+ ['2026-10-03', 8000],
+ ]),
+ },
+ {
+ id: 'card',
+ forecast: forecast([
+ ['2026-10-01', -3000],
+ ['2026-10-04', -5000],
+ ]),
+ },
+ ],
+ });
+ expect(result.chartData).toEqual([
+ { date: '2026-10-02', balance: 12000, series1: -3000 },
+ { date: '2026-10-03', balance: 8000, series1: -3000 },
+ { date: '2026-10-04', balance: 8000, series1: -5000 },
+ ]);
+ expect(result.lines.map(line => line.lowestPoint)).toEqual([
+ { date: '2026-10-03', balance: 8000 },
+ { date: '2026-10-04', balance: -5000 },
+ ]);
+ });
+
+ it('shows combined account results from the engine without summing overlapping lines', () => {
+ const result = buildForecastSeriesChart({
+ series,
+ start: '2026-10',
+ end: '2026-11',
+ granularity: 'Monthly',
+ forecasts: [
+ {
+ id: 'checking',
+ forecast: forecast([
+ ['2026-10-31', 10000],
+ ['2026-11-30', 6000],
+ ]),
+ },
+ {
+ id: 'card',
+ forecast: forecast([
+ ['2026-10-31', -4000],
+ ['2026-11-30', 0],
+ ]),
+ },
+ {
+ id: 'both',
+ forecast: forecast([
+ ['2026-10-31', 10000, 'checking'],
+ ['2026-10-31', -4000, 'card'],
+ ['2026-11-30', 6000, 'checking'],
+ ['2026-11-30', 0, 'card'],
+ ]),
+ },
+ ],
+ });
+ expect(result.chartData).toEqual([
+ { date: '2026-10', balance: 10000, series1: -4000, series2: 6000 },
+ { date: '2026-11', balance: 6000, series1: 0, series2: 6000 },
+ ]);
+ });
+
+ it('retains empty lines as no data and identifies names by id, including duplicate names', () => {
+ const result = buildForecastSeriesChart({
+ series: series.map(line => ({ ...line, name: 'Same name' })),
+ start: '2026-10',
+ end: '2026-10',
+ granularity: 'Monthly',
+ forecasts: [
+ { id: 'card', forecast: forecast([]) },
+ { id: 'checking', forecast: forecast([['2026-10-31', 10000]]) },
+ ],
+ });
+ expect(
+ result.lines.map(line => [line.id, line.name, line.endingPoint]),
+ ).toEqual([
+ ['card', 'Same name', undefined],
+ ['checking', 'Same name', { date: '2026-10', balance: 10000 }],
+ ]);
+ expect(result.chartData).toEqual([{ date: '2026-10', series1: 10000 }]);
+ expect(result.balances).toEqual([10000]);
+ });
+});
diff --git a/packages/desktop-client/src/components/reports/reports/balanceForecastSeries.ts b/packages/desktop-client/src/components/reports/reports/balanceForecastSeries.ts
new file mode 100644
index 0000000000..3000e4007a
--- /dev/null
+++ b/packages/desktop-client/src/components/reports/reports/balanceForecastSeries.ts
@@ -0,0 +1,64 @@
+import type {
+ ForecastResult,
+ ForecastSeries,
+} from '@actual-app/core/types/models/forecast';
+
+import {
+ buildBalanceForecastChartData,
+ getLowestChartDataPoint,
+} from './balanceForecastChartData';
+
+export const MAX_FORECAST_SERIES = 4;
+
+export function buildForecastSeriesChart({
+ forecasts,
+ series,
+ start,
+ end,
+ granularity,
+}: {
+ forecasts: Array<{ id: string; forecast: ForecastResult }> | undefined;
+ series?: ForecastSeries[];
+ start: string;
+ end: string;
+ granularity: 'Daily' | 'Monthly';
+}) {
+ const lines = (forecasts ?? []).map(({ id, forecast }, index) => {
+ const options = { forecastData: forecast, start, end, granularity };
+ const points = buildBalanceForecastChartData(options);
+ return {
+ id,
+ name: series?.find(line => line.id === id)?.name ?? '',
+ dataKey: index === 0 ? 'balance' : `series${index}`,
+ points,
+ endingPoint: points.at(-1),
+ lowestPoint: getLowestChartDataPoint(points),
+ };
+ });
+
+ // Align by date, not array position. An empty series stays absent instead
+ // of drawing a zero balance or borrowing another series' values.
+ const pointsByDate = new Map<
+ string,
+ { date: string; [key: string]: string | number }
+ >();
+ for (const line of lines) {
+ for (const point of line.points) {
+ const row = pointsByDate.get(point.date) ?? { date: point.date };
+ row[line.dataKey] = point.balance;
+ pointsByDate.set(point.date, row);
+ }
+ }
+
+ return {
+ lines,
+ chartData: [...pointsByDate.values()].sort((a, b) =>
+ a.date.localeCompare(b.date),
+ ),
+ balances: lines.flatMap(line => line.points.map(point => point.balance)),
+ };
+}
+
+export type ForecastChartLine = ReturnType<
+ typeof buildForecastSeriesChart
+>['lines'][number];
diff --git a/packages/desktop-client/src/hooks/useBalanceForecast.test.ts b/packages/desktop-client/src/hooks/useBalanceForecast.test.ts
index 2955ca9f55..023b960bcf 100644
--- a/packages/desktop-client/src/hooks/useBalanceForecast.test.ts
+++ b/packages/desktop-client/src/hooks/useBalanceForecast.test.ts
@@ -1,6 +1,26 @@
-import { describe, expect, it } from 'vitest';
+import {
+ clearServer,
+ initServer,
+} from '@actual-app/core/platform/client/connection';
+import type {
+ ForecastResult,
+ ForecastSeries,
+} from '@actual-app/core/types/models/forecast';
+import { renderHook, waitFor } from '@testing-library/react';
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
-import { buildBalanceForecastRequest } from './useBalanceForecast';
+import { TestProviders } from '#mocks';
+
+import {
+ buildBalanceForecastRequest,
+ buildBalanceForecastSeriesRequests,
+ useBalanceForecastSeries,
+} from './useBalanceForecast';
+
+vi.mock(
+ '@actual-app/core/platform/client/connection',
+ () => import('#mocks/connection'),
+);
describe('buildBalanceForecastRequest', () => {
it('keeps schedule forecast filters and account selection', () => {
@@ -52,3 +72,246 @@ describe('buildBalanceForecastRequest', () => {
});
});
});
+
+describe('buildBalanceForecastSeriesRequests', () => {
+ const params = {
+ startDate: '2026-10-01',
+ endDate: '2026-12-31',
+ accountIds: ['legacy-account'],
+ conditionsOp: 'and' as const,
+ conditions: [
+ { field: 'account' as const, op: 'is' as const, value: 'legacy-account' },
+ ],
+ includeAccountlessSchedules: false,
+ };
+
+ it('keeps legacy widgets and empty series identical to a single forecast', () => {
+ for (const series of [undefined, []]) {
+ expect(buildBalanceForecastSeriesRequests(series, params)).toEqual([
+ { id: 'balance', request: buildBalanceForecastRequest(params) },
+ ]);
+ }
+ });
+
+ it('uses independent account restrictions and OR filters without inheriting legacy filters', () => {
+ const result = buildBalanceForecastSeriesRequests(
+ [
+ {
+ id: 'one',
+ name: 'One',
+ accounts: [],
+ conditions: [],
+ conditionsOp: 'and',
+ },
+ {
+ id: 'two',
+ name: 'Two',
+ conditions: [
+ { field: 'account', op: 'is', value: 'card' },
+ { field: 'notes', op: 'contains', value: 'subscription' },
+ ],
+ conditionsOp: 'or',
+ },
+ ],
+ params,
+ );
+ expect(result[0].request).toEqual({
+ startDate: params.startDate,
+ endDate: params.endDate,
+ source: 'schedules',
+ accountIds: [],
+ conditions: [],
+ conditionsOp: 'and',
+ includeAccountlessSchedules: false,
+ });
+ expect(result[1].request).toEqual({
+ startDate: params.startDate,
+ endDate: params.endDate,
+ source: 'schedules',
+ conditions: [
+ { field: 'account', op: 'is', value: 'card' },
+ { field: 'notes', op: 'contains', value: 'subscription' },
+ ],
+ conditionsOp: 'or',
+ includeAccountlessSchedules: true,
+ });
+ });
+
+ it('leaves tracking forecasts as one whole-budget forecast', () => {
+ const trackingParams = {
+ startDate: params.startDate,
+ endDate: params.endDate,
+ source: 'tracking-budget' as const,
+ };
+ expect(
+ buildBalanceForecastSeriesRequests(
+ [
+ {
+ id: 'one',
+ name: 'Cash',
+ accounts: ['checking'],
+ conditions: [],
+ conditionsOp: 'and',
+ },
+ ],
+ trackingParams,
+ ),
+ ).toEqual([
+ { id: 'balance', request: buildBalanceForecastRequest(trackingParams) },
+ ]);
+ });
+});
+
+describe('useBalanceForecastSeries while refetching', () => {
+ const params = { startDate: '2024-03-01', endDate: '2024-03-31' };
+ const series: ForecastSeries[] = ['checking', 'card'].map(id => ({
+ id,
+ name: id,
+ accounts: [id],
+ conditions: [],
+ conditionsOp: 'and',
+ }));
+ const forecast: ForecastResult = {
+ dataPoints: [
+ {
+ date: params.endDate,
+ balance: 10000,
+ accountId: 'checking',
+ accountName: 'Checking',
+ transactions: [],
+ },
+ ],
+ lowestBalance: {
+ date: params.endDate,
+ balance: 10000,
+ accountId: 'checking',
+ accountName: 'Checking',
+ },
+ forecastStartDate: params.startDate,
+ forecastEndDate: params.endDate,
+ };
+ const updatedForecast: ForecastResult = {
+ ...forecast,
+ dataPoints: forecast.dataPoints.map(point => ({
+ ...point,
+ balance: 20000,
+ })),
+ lowestBalance: { ...forecast.lowestBalance, balance: 20000 },
+ };
+
+ beforeEach(() => {
+ initServer({ 'forecast/generate': async () => forecast });
+ });
+
+ afterEach(async () => {
+ await clearServer();
+ });
+
+ it.each([
+ {
+ change: 'legacy account selections',
+ initial: { ...params, accountIds: ['checking'] },
+ updated: { ...params, accountIds: ['card'] },
+ },
+ {
+ change: 'legacy transaction filters',
+ initial: params,
+ updated: {
+ ...params,
+ conditions: [{ field: 'amount', op: 'gt', value: 0 }],
+ },
+ },
+ {
+ change: 'named line account selections and filters',
+ initial: { ...params, series },
+ updated: {
+ ...params,
+ series: series.map(line => ({
+ ...line,
+ accounts: ['savings'],
+ conditions: [{ field: 'amount', op: 'gt', value: 0 }],
+ })),
+ },
+ },
+ {
+ change: 'the date range',
+ initial: params,
+ updated: { ...params, endDate: '2024-04-30' },
+ },
+ ] satisfies Array<{
+ change: string;
+ initial: Parameters<typeof useBalanceForecastSeries>[0];
+ updated: Parameters<typeof useBalanceForecastSeries>[0];
+ }>)(
+ 'keeps the report visible when changing $change',
+ async ({ initial, updated }) => {
+ const { result, rerender } = renderHook(
+ (props: Parameters<typeof useBalanceForecastSeries>[0]) =>
+ useBalanceForecastSeries(props),
+ { initialProps: initial, wrapper: TestProviders },
+ );
+ await waitFor(() => expect(result.current.isSuccess).toBe(true));
+ const previousData = result.current.data;
+
+ let completeForecast: (value: ForecastResult) => void = vi.fn();
+ const pendingForecast = new Promise<ForecastResult>(resolve => {
+ completeForecast = resolve;
+ });
+ initServer({ 'forecast/generate': () => pendingForecast });
+ rerender(updated);
+
+ expect(result.current.isFetching).toBe(true);
+ expect(result.current.isPending).toBe(false);
+ expect(result.current.isPlaceholderData).toBe(true);
+ expect(result.current.data).toBe(previousData);
+
+ completeForecast(updatedForecast);
+ await waitFor(() => expect(result.current.isFetching).toBe(false));
+ expect(result.current.isPlaceholderData).toBe(false);
+ expect(result.current.data?.map(line => line.forecast)).toEqual(
+ previousData?.map(() => updatedForecast),
+ );
+ },
+ );
+
+ it.each([
+ {
+ change: 'adding a line',
+ nextSeries: [
+ ...series,
+ { ...series[0], id: 'combined', accounts: ['checking', 'card'] },
+ ],
+ },
+ { change: 'removing a line', nextSeries: series.slice(0, 1) },
+ { change: 'reordering lines', nextSeries: [...series].reverse() },
+ {
+ change: 'replacing a line',
+ nextSeries: series.map(line => ({ ...line, id: `${line.id}-new` })),
+ },
+ ])('discards previous results when $change', async ({ nextSeries }) => {
+ const { result, rerender } = renderHook(
+ (lines: ForecastSeries[]) =>
+ useBalanceForecastSeries({ ...params, series: lines }),
+ { initialProps: series, wrapper: TestProviders },
+ );
+ await waitFor(() => expect(result.current.isSuccess).toBe(true));
+
+ let completeForecast: (value: ForecastResult) => void = vi.fn();
+ const pendingForecast = new Promise<ForecastResult>(resolve => {
+ completeForecast = resolve;
+ });
+ initServer({ 'forecast/generate': () => pendingForecast });
+ rerender(nextSeries);
+
+ expect(result.current.isFetching).toBe(true);
+ expect(result.current.isPending).toBe(true);
+ expect(result.current.isPlaceholderData).toBe(false);
+ expect(result.current.data).toBeUndefined();
+
+ completeForecast(updatedForecast);
+ await waitFor(() => expect(result.current.isSuccess).toBe(true));
+ expect(result.current.data).toEqual(
+ nextSeries.map(({ id }) => ({ id, forecast: updatedForecast })),
+ );
+ });
+});
diff --git a/packages/desktop-client/src/hooks/useBalanceForecast.ts b/packages/desktop-client/src/hooks/useBalanceForecast.ts
index 96f9bca5da..b8ef5b1c88 100644
--- a/packages/desktop-client/src/hooks/useBalanceForecast.ts
+++ b/packages/desktop-client/src/hooks/useBalanceForecast.ts
@@ -1,10 +1,10 @@
import { send } from '@actual-app/core/platform/client/connection';
import type { RuleConditionEntity } from '@actual-app/core/types/models';
import type {
- ForecastResult,
+ ForecastSeries,
ForecastSource,
} from '@actual-app/core/types/models/forecast';
-import { keepPreviousData, useQuery } from '@tanstack/react-query';
+import { useQuery } from '@tanstack/react-query';
type UseBalanceForecastParams = {
accountIds?: string[];
@@ -39,43 +39,54 @@ export function buildBalanceForecastRequest({
);
}
-export function useBalanceForecast({
- accountIds,
- conditions,
- conditionsOp,
- startDate,
- endDate,
- includeAccountlessSchedules,
- source = 'schedules',
+export function useBalanceForecastSeries({
+ series,
enabled = true,
-}: UseBalanceForecastParams) {
+ ...params
+}: UseBalanceForecastParams & { series?: ForecastSeries[] }) {
+ const requests = buildBalanceForecastSeriesRequests(series, params);
+
return useQuery({
- queryKey: [
- 'balance-forecast',
- {
- accountIds: accountIds ?? null,
- conditions: conditions ?? null,
- conditionsOp: conditionsOp ?? 'and',
- startDate,
- endDate,
- includeAccountlessSchedules: includeAccountlessSchedules ?? false,
- source,
- },
- ],
- queryFn: async (): Promise<ForecastResult> =>
- send(
- 'forecast/generate',
- buildBalanceForecastRequest({
- accountIds,
- conditions,
- conditionsOp,
- startDate,
- endDate,
- includeAccountlessSchedules,
- source,
- }),
+ queryKey: ['balance-forecast-series', requests],
+ queryFn: () =>
+ Promise.all(
+ requests.map(async ({ id, request }) => ({
+ id,
+ forecast: await send('forecast/generate', request),
+ })),
),
- placeholderData: keepPreviousData,
+ // Keep the whole comparison visible while its dates or filters change.
+ // Drop previous results when line IDs or their order change.
+ placeholderData: (previous, previousQuery) => {
+ const previousRequests = previousQuery?.queryKey[1];
+ if (!Array.isArray(previousRequests)) {
+ return undefined;
+ }
+ return requests.length === previousRequests.length &&
+ requests.every(({ id }, index) => id === previousRequests[index].id)
+ ? previous
+ : undefined;
+ },
enabled,
});
}
+
+export function buildBalanceForecastSeriesRequests(
+ series: ForecastSeries[] | undefined,
+ params: UseBalanceForecastParams,
+) {
+ if (!series?.length || params.source === 'tracking-budget') {
+ return [{ id: 'balance', request: buildBalanceForecastRequest(params) }];
+ }
+
+ return series.map(line => ({
+ id: line.id,
+ request: buildBalanceForecastRequest({
+ ...params,
+ accountIds: line.accounts,
+ conditions: line.conditions,
+ conditionsOp: line.conditionsOp,
+ includeAccountlessSchedules: line.accounts === undefined,
+ }),
+ }));
+}
diff --git a/packages/loot-core/src/types/models/dashboard.ts b/packages/loot-core/src/types/models/dashboard.ts
index 797ef835ca..6e0994383d 100644
--- a/packages/loot-core/src/types/models/dashboard.ts
+++ b/packages/loot-core/src/types/models/dashboard.ts
@@ -1,4 +1,4 @@
-import type { ForecastSource } from './forecast';
+import type { ForecastSeries, ForecastSource } from './forecast';
import type { CustomReportEntity } from './reports';
import type { RuleConditionEntity } from './rule';
@@ -493,5 +493,6 @@ export type BalanceForecastWidget = AbstractWidget<
granularity?: 'Daily' | 'Monthly';
yAxisBase?: 'Zero-Based' | 'Auto';
source?: ForecastSource;
+ series?: ForecastSeries[];
} | null
>;
diff --git a/packages/loot-core/src/types/models/forecast.ts b/packages/loot-core/src/types/models/forecast.ts
index 5269d8949f..dc5f456ab5 100644
--- a/packages/loot-core/src/types/models/forecast.ts
+++ b/packages/loot-core/src/types/models/forecast.ts
@@ -1,5 +1,15 @@
+import type { RuleConditionEntity } from './rule';
+
export type ForecastSource = 'schedules' | 'tracking-budget';
+export type ForecastSeries = {
+ id: string;
+ name: string;
+ accounts?: string[];
+ conditions: RuleConditionEntity[];
+ conditionsOp: 'and' | 'or';
+};
+
export type ForecastDataPoint = {
date: string;
balance: number;
diff --git a/upcoming-release-notes/compare-balance-forecast-lines.md b/upcoming-release-notes/compare-balance-forecast-lines.md
new file mode 100644
index 0000000000..ce250f6a40
--- /dev/null
+++ b/upcoming-release-notes/compare-balance-forecast-lines.md
@@ -0,0 +1,6 @@
+---
+category: Enhancements
+authors: [samaluk]
+---
+
+Compare up to four named balance forecast lines with separate account and transaction filters, and save them to your dashboard