Skip to content

A local-first personal finance app

[AI] Improve Balance Forecast captions (#7957)

Sebastián Maluka86bcdae77b5
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 3b57fafb0a..78cc60ee3e 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 e5d193083f..59b86aca24 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 c56d2cc2bd..3ff7a9e549 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-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 118b5fd110..fd93794070 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 46be38e635..9860d5fdef 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 4928eefbf8..a855a8d64a 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/src/components/reports/reports/BalanceForecast.tsx b/packages/desktop-client/src/components/reports/reports/BalanceForecast.tsx
index f33cd3522a..8c166af09e 100644
--- a/packages/desktop-client/src/components/reports/reports/BalanceForecast.tsx
+++ b/packages/desktop-client/src/components/reports/reports/BalanceForecast.tsx
@@ -46,6 +46,7 @@ import { useDispatch } from '#redux';
import {
buildBalanceForecastChartData,
countForecastScheduledOccurrences,
+ getLowestChartDataPoint,
getZeroCrossingGradientOffset,
} from './balanceForecastChartData';
@@ -279,7 +280,8 @@ function BalanceForecastInner({ widget }: BalanceForecastInnerProps) {
return <LoadingIndicator />;
}
- const lowestPoint = forecastData?.lowestBalance;
+ const endingPoint = chartData.at(-1);
+ const lowestPoint = getLowestChartDataPoint(chartData);
const hasNegativeBalance = chartData.some(d => d.balance < 0);
const zeroCrossingGradientOffset = getZeroCrossingGradientOffset(chartData);
const todayReferenceDate =
@@ -344,7 +346,7 @@ function BalanceForecastInner({ widget }: BalanceForecastInnerProps) {
<div style={{ color: theme.errorText, marginBottom: 20 }}>
{errorMessage}
</div>
- ) : lowestPoint ? (
+ ) : endingPoint ? (
<View
style={{
textAlign: 'right',
@@ -358,17 +360,31 @@ function BalanceForecastInner({ widget }: BalanceForecastInnerProps) {
fontWeight: 400,
marginBottom: 5,
color:
- lowestPoint.balance < 0 ? theme.errorText : theme.pageText,
+ endingPoint.balance < 0 ? theme.errorText : theme.pageText,
}}
>
<PrivacyFilter>
- {format(lowestPoint.balance, 'financial')}
+ {format(endingPoint.balance, 'financial')}
</PrivacyFilter>
</View>
<View style={{ color: theme.pageTextLight }}>
- <Trans>Lowest Point</Trans>: {lowestPoint.date}
- {lowestPoint.accountName && <> ({lowestPoint.accountName})</>}
+ <Trans>Ending Balance</Trans>: {endingPoint.date}
</View>
+ {lowestPoint && lowestPoint.date !== endingPoint.date ? (
+ <View
+ style={{
+ color: theme.pageTextLight,
+ fontSize: 12,
+ marginTop: 4,
+ }}
+ >
+ <Trans>Lowest visible point</Trans>:{' '}
+ <PrivacyFilter>
+ {format(lowestPoint.balance, 'financial')}
+ </PrivacyFilter>{' '}
+ ({lowestPoint.date})
+ </View>
+ ) : null}
</View>
) : null}
diff --git a/packages/desktop-client/src/components/reports/reports/BalanceForecastCard.tsx b/packages/desktop-client/src/components/reports/reports/BalanceForecastCard.tsx
index a3d0d25d00..1e41fa1ab3 100644
--- a/packages/desktop-client/src/components/reports/reports/BalanceForecastCard.tsx
+++ b/packages/desktop-client/src/components/reports/reports/BalanceForecastCard.tsx
@@ -33,6 +33,7 @@ import { useFormat } from '#hooks/useFormat';
import {
buildBalanceForecastChartData,
countForecastScheduledOccurrences,
+ getLowestChartDataPoint,
getZeroCrossingGradientOffset,
} from './balanceForecastChartData';
@@ -106,9 +107,6 @@ export function BalanceForecastCard({
const onCardHover = () => setIsCardHovered(true);
const onCardHoverEnd = () => setIsCardHovered(false);
- const lowestPoint = forecastData?.lowestBalance;
- const hasNegative = lowestPoint && lowestPoint.balance < 0;
-
const chartRange = isPlaceholderData
? committedChartRange.current
: { start, end };
@@ -124,6 +122,9 @@ export function BalanceForecastCard({
end: chartRange.end,
granularity: 'Monthly',
});
+ const endingPoint = chartData.at(-1);
+ const lowestPoint = getLowestChartDataPoint(chartData);
+ const hasNegativeEndingBalance = endingPoint && endingPoint.balance < 0;
const hasNegativeBalance = chartData.some(d => d.balance < 0);
const zeroCrossingGradientOffset = getZeroCrossingGradientOffset(chartData);
const gradientId = `balance-forecast-card-line-gradient-${widgetId}`;
@@ -189,26 +190,42 @@ export function BalanceForecastCard({
/>
<DateRange start={start} end={end} />
</View>
- {lowestPoint && (
+ {endingPoint && (
<View style={{ textAlign: 'right' }}>
<Block
style={{
...styles.mediumText,
fontWeight: 500,
marginBottom: 5,
- color: hasNegative ? theme.errorText : theme.pageText,
+ color: hasNegativeEndingBalance
+ ? theme.errorText
+ : theme.pageText,
}}
>
<PrivacyFilter activationFilters={[!isCardHovered]}>
- <Trans>Lowest</Trans>:{' '}
- {format(lowestPoint.balance, 'financial')}
+ <Trans>Ending</Trans>:{' '}
+ {format(endingPoint.balance, 'financial')}
</PrivacyFilter>
</Block>
<PrivacyFilter activationFilters={[!isCardHovered]}>
<Block style={{ fontSize: 12, color: theme.pageTextLight }}>
- {lowestPoint.date}
+ {endingPoint.date}
</Block>
</PrivacyFilter>
+ {lowestPoint && lowestPoint.date !== endingPoint.date ? (
+ <PrivacyFilter activationFilters={[!isCardHovered]}>
+ <Block
+ style={{
+ fontSize: 12,
+ color: theme.pageTextLight,
+ marginTop: 4,
+ }}
+ >
+ <Trans>Low</Trans>:{' '}
+ {format(lowestPoint.balance, 'financial')}
+ </Block>
+ </PrivacyFilter>
+ ) : null}
</View>
)}
</View>
diff --git a/packages/desktop-client/src/components/reports/reports/balanceForecastChartData.test.ts b/packages/desktop-client/src/components/reports/reports/balanceForecastChartData.test.ts
index 1ab528f337..6ce4b1e6d9 100644
--- a/packages/desktop-client/src/components/reports/reports/balanceForecastChartData.test.ts
+++ b/packages/desktop-client/src/components/reports/reports/balanceForecastChartData.test.ts
@@ -3,6 +3,7 @@ import { describe, expect, it } from 'vitest';
import {
buildBalanceForecastChartData,
countForecastScheduledOccurrences,
+ getLowestChartDataPoint,
getZeroCrossingGradientOffset,
} from './balanceForecastChartData';
@@ -278,3 +279,19 @@ describe('getZeroCrossingGradientOffset', () => {
).toBeNull();
});
});
+
+describe('getLowestChartDataPoint', () => {
+ it('returns the lowest visible chart point', () => {
+ expect(
+ getLowestChartDataPoint([
+ { date: '2024-03', balance: 100 },
+ { date: '2024-04', balance: -50 },
+ { date: '2024-05', balance: 25 },
+ ]),
+ ).toEqual({ date: '2024-04', balance: -50 });
+ });
+
+ it('returns undefined for empty chart data', () => {
+ expect(getLowestChartDataPoint([])).toBeUndefined();
+ });
+});
diff --git a/packages/desktop-client/src/components/reports/reports/balanceForecastChartData.ts b/packages/desktop-client/src/components/reports/reports/balanceForecastChartData.ts
index 532e853868..baca7e2040 100644
--- a/packages/desktop-client/src/components/reports/reports/balanceForecastChartData.ts
+++ b/packages/desktop-client/src/components/reports/reports/balanceForecastChartData.ts
@@ -144,3 +144,13 @@ export function getZeroCrossingGradientOffset(chartData: ChartDataPoint[]) {
return (maxBalance / (maxBalance - minBalance)) * 100;
}
+
+export function getLowestChartDataPoint(chartData: ChartDataPoint[]) {
+ return chartData.reduce<ChartDataPoint | undefined>((lowestPoint, point) => {
+ if (!lowestPoint || point.balance < lowestPoint.balance) {
+ return point;
+ }
+
+ return lowestPoint;
+ }, undefined);
+}
diff --git a/upcoming-release-notes/7957.md b/upcoming-release-notes/7957.md
new file mode 100644
index 0000000000..c8fdf6fc9f
--- /dev/null
+++ b/upcoming-release-notes/7957.md
@@ -0,0 +1,6 @@
+---
+category: Enhancements
+authors: [samaluk]
+---
+
+Improve Balance Forecast captions with ending balance and lowest point context.