Skip to content

A local-first personal finance app

enhancement: add interval selector for net worth report (#5282)

Sai Pratyush Cherukuri202af094af4d
diff --git a/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-loads-cash-flow-graph-and-checks-visuals-1-chromium-linux.png b/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-loads-cash-flow-graph-and-checks-visuals-1-chromium-linux.png
index 35d0ace16a..4fcf6ba96c 100644
Binary files a/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-loads-cash-flow-graph-and-checks-visuals-1-chromium-linux.png and b/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-loads-cash-flow-graph-and-checks-visuals-1-chromium-linux.png differ
diff --git a/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-loads-cash-flow-graph-and-checks-visuals-2-chromium-linux.png b/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-loads-cash-flow-graph-and-checks-visuals-2-chromium-linux.png
index 377cd61eab..81c5da63c1 100644
Binary files a/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-loads-cash-flow-graph-and-checks-visuals-2-chromium-linux.png and b/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-loads-cash-flow-graph-and-checks-visuals-2-chromium-linux.png differ
diff --git a/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-loads-cash-flow-graph-and-checks-visuals-3-chromium-linux.png b/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-loads-cash-flow-graph-and-checks-visuals-3-chromium-linux.png
index 79440f9edf..a63477204d 100644
Binary files a/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-loads-cash-flow-graph-and-checks-visuals-3-chromium-linux.png and b/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-loads-cash-flow-graph-and-checks-visuals-3-chromium-linux.png differ
diff --git a/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-loads-net-worth-and-cash-flow-reports-1-chromium-linux.png b/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-loads-net-worth-and-cash-flow-reports-1-chromium-linux.png
index cb450ca1ba..2271409569 100644
Binary files a/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-loads-net-worth-and-cash-flow-reports-1-chromium-linux.png and b/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-loads-net-worth-and-cash-flow-reports-1-chromium-linux.png differ
diff --git a/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-loads-net-worth-and-cash-flow-reports-2-chromium-linux.png b/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-loads-net-worth-and-cash-flow-reports-2-chromium-linux.png
index f6d0698375..02b4733734 100644
Binary files a/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-loads-net-worth-and-cash-flow-reports-2-chromium-linux.png and b/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-loads-net-worth-and-cash-flow-reports-2-chromium-linux.png differ
diff --git a/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-loads-net-worth-and-cash-flow-reports-3-chromium-linux.png b/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-loads-net-worth-and-cash-flow-reports-3-chromium-linux.png
index 304a1d2c90..da8c688ecc 100644
Binary files a/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-loads-net-worth-and-cash-flow-reports-3-chromium-linux.png and b/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-loads-net-worth-and-cash-flow-reports-3-chromium-linux.png differ
diff --git a/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-loads-net-worth-graph-and-checks-visuals-1-chromium-linux.png b/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-loads-net-worth-graph-and-checks-visuals-1-chromium-linux.png
index ec1c35bcb9..4a1fd09263 100644
Binary files a/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-loads-net-worth-graph-and-checks-visuals-1-chromium-linux.png and b/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-loads-net-worth-graph-and-checks-visuals-1-chromium-linux.png differ
diff --git a/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-loads-net-worth-graph-and-checks-visuals-2-chromium-linux.png b/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-loads-net-worth-graph-and-checks-visuals-2-chromium-linux.png
index 51a5a8aba5..a4c4263fd3 100644
Binary files a/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-loads-net-worth-graph-and-checks-visuals-2-chromium-linux.png and b/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-loads-net-worth-graph-and-checks-visuals-2-chromium-linux.png differ
diff --git a/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-loads-net-worth-graph-and-checks-visuals-3-chromium-linux.png b/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-loads-net-worth-graph-and-checks-visuals-3-chromium-linux.png
index 56a1ab8eb6..8bea5d0f07 100644
Binary files a/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-loads-net-worth-graph-and-checks-visuals-3-chromium-linux.png and b/packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-loads-net-worth-graph-and-checks-visuals-3-chromium-linux.png differ
diff --git a/packages/desktop-client/src/components/reports/Header.tsx b/packages/desktop-client/src/components/reports/Header.tsx
index 1f2c0ce520..f3cdc0fd93 100644
--- a/packages/desktop-client/src/components/reports/Header.tsx
+++ b/packages/desktop-client/src/components/reports/Header.tsx
@@ -49,6 +49,7 @@ type HeaderProps = {
typeof AppliedFilters
>['onConditionsOpChange'];
children?: ReactNode;
+ inlineContent?: ReactNode;
};
export function Header({
@@ -67,6 +68,7 @@ export function Header({
onDeleteFilter,
onConditionsOpChange,
children,
+ inlineContent,
}: HeaderProps) {
const locale = useLocale();
const { t } = useTranslation();
@@ -88,162 +90,171 @@ export function Header({
flexShrink: 0,
}}
>
- <SpaceBetween
- direction={isNarrowWidth ? 'vertical' : 'horizontal'}
+ <View
style={{
+ display: 'grid',
alignItems: isNarrowWidth ? 'flex-start' : 'center',
}}
>
- <SpaceBetween gap={isNarrowWidth ? 5 : undefined}>
- {mode && (
- <Button
- variant={mode === 'static' ? 'normal' : 'primary'}
- onPress={() => {
- const newMode = mode === 'static' ? 'sliding-window' : 'static';
- const [newStart, newEnd] = calculateTimeRange({
- start,
- end,
- mode: newMode,
- });
+ <View
+ style={{
+ display: 'flex',
+ flexWrap: 'wrap',
+ flexDirection: 'row',
+ }}
+ >
+ <SpaceBetween gap={isNarrowWidth ? 5 : undefined}>
+ {mode && (
+ <Button
+ variant={mode === 'static' ? 'normal' : 'primary'}
+ onPress={() => {
+ const newMode =
+ mode === 'static' ? 'sliding-window' : 'static';
+ const [newStart, newEnd] = calculateTimeRange({
+ start,
+ end,
+ mode: newMode,
+ });
+
+ onChangeDates(newStart, newEnd, newMode);
+ }}
+ >
+ {mode === 'static' ? t('Static') : t('Live')}
+ </Button>
+ )}
+
+ <SpaceBetween gap={5}>
+ <Select
+ onChange={newValue =>
+ onChangeDates(
+ ...validateStart(
+ allMonths[allMonths.length - 1].name,
+ newValue,
+ end,
+ ),
+ )
+ }
+ value={start}
+ defaultLabel={monthUtils.format(start, 'MMMM, yyyy', locale)}
+ options={allMonths.map(({ name, pretty }) => [name, pretty])}
+ />
+ <View>{t('to')}</View>
+ <Select
+ onChange={newValue =>
+ onChangeDates(
+ ...validateEnd(
+ allMonths[allMonths.length - 1].name,
+ start,
+ newValue,
+ ),
+ )
+ }
+ value={end}
+ options={allMonths.map(({ name, pretty }) => [name, pretty])}
+ style={{ marginRight: 10 }}
+ />
+ </SpaceBetween>
+ </SpaceBetween>
- onChangeDates(newStart, newEnd, newMode);
- }}
+ <SpaceBetween gap={3}>
+ {show1Month && (
+ <Button
+ variant="bare"
+ onPress={() => onChangeDates(...getLatestRange(1))}
+ >
+ <Trans>1 month</Trans>
+ </Button>
+ )}
+ <Button
+ variant="bare"
+ onPress={() => onChangeDates(...getLatestRange(2))}
>
- {mode === 'static' ? t('Static') : t('Live')}
+ <Trans>3 months</Trans>
</Button>
- )}
-
- <SpaceBetween gap={5}>
- <Select
- onChange={newValue =>
+ <Button
+ variant="bare"
+ onPress={() => onChangeDates(...getLatestRange(5))}
+ >
+ <Trans>6 months</Trans>
+ </Button>
+ <Button
+ variant="bare"
+ onPress={() => onChangeDates(...getLatestRange(11))}
+ >
+ <Trans>1 year</Trans>
+ </Button>
+ <Button
+ variant="bare"
+ onPress={() =>
onChangeDates(
- ...validateStart(
- allMonths[allMonths.length - 1].name,
- newValue,
- end,
+ ...convertToMonth(
+ ...getLiveRange(
+ 'Year to date',
+ earliestTransaction,
+ true,
+ firstDayOfWeekIdx,
+ ),
+ 'yearToDate',
),
)
}
- value={start}
- defaultLabel={monthUtils.format(start, 'MMMM, yyyy', locale)}
- options={allMonths.map(({ name, pretty }) => [name, pretty])}
- />
- <View>{t('to')}</View>
- <Select
- onChange={newValue =>
+ >
+ <Trans>Year to date</Trans>
+ </Button>
+ <Button
+ variant="bare"
+ onPress={() =>
onChangeDates(
- ...validateEnd(
- allMonths[allMonths.length - 1].name,
- start,
- newValue,
+ ...convertToMonth(
+ ...getLiveRange(
+ 'Last year',
+ earliestTransaction,
+ false,
+ firstDayOfWeekIdx,
+ ),
+ 'lastYear',
),
)
}
- value={end}
- options={allMonths.map(({ name, pretty }) => [name, pretty])}
- style={{ marginRight: 10 }}
- />
- </SpaceBetween>
- </SpaceBetween>
-
- <SpaceBetween gap={3}>
- {show1Month && (
+ >
+ <Trans>Last year</Trans>
+ </Button>
<Button
variant="bare"
- onPress={() => onChangeDates(...getLatestRange(1))}
+ onPress={() =>
+ onChangeDates(
+ ...getFullRange(allMonths[allMonths.length - 1].name),
+ )
+ }
>
- <Trans>1 month</Trans>
+ <Trans>All time</Trans>
</Button>
- )}
- <Button
- variant="bare"
- onPress={() => onChangeDates(...getLatestRange(2))}
- >
- <Trans>3 months</Trans>
- </Button>
- <Button
- variant="bare"
- onPress={() => onChangeDates(...getLatestRange(5))}
- >
- <Trans>6 months</Trans>
- </Button>
- <Button
- variant="bare"
- onPress={() => onChangeDates(...getLatestRange(11))}
- >
- <Trans>1 year</Trans>
- </Button>
- <Button
- variant="bare"
- onPress={() =>
- onChangeDates(
- ...convertToMonth(
- ...getLiveRange(
- 'Year to date',
- earliestTransaction,
- true,
- firstDayOfWeekIdx,
- ),
- 'yearToDate',
- ),
- )
- }
- >
- <Trans>Year to date</Trans>
- </Button>
- <Button
- variant="bare"
- onPress={() =>
- onChangeDates(
- ...convertToMonth(
- ...getLiveRange(
- 'Last year',
- earliestTransaction,
- false,
- firstDayOfWeekIdx,
- ),
- 'lastYear',
- ),
- )
- }
- >
- <Trans>Last year</Trans>
- </Button>
- <Button
- variant="bare"
- onPress={() =>
- onChangeDates(
- ...getFullRange(allMonths[allMonths.length - 1].name),
- )
- }
- >
- <Trans>All time</Trans>
- </Button>
- {filters && (
- <FilterButton
- compact={isNarrowWidth}
- onApply={onApply}
- hover={false}
- exclude={undefined}
- />
- )}
- </SpaceBetween>
+ {filters && (
+ <FilterButton
+ compact={isNarrowWidth}
+ onApply={onApply}
+ hover={false}
+ exclude={undefined}
+ />
+ )}
+ </SpaceBetween>
+ <SpaceBetween gap={0}>{inlineContent}</SpaceBetween>
+ </View>
- {children ? (
+ {children && (
<View
style={{
- flex: 1,
+ gridColumn: 2,
flexDirection: 'row',
- justifyContent: 'flex-end',
+ justifySelf: 'flex-end',
+ alignSelf: 'flex-start',
}}
>
{children}
</View>
- ) : (
- <View style={{ flex: 1 }} />
)}
- </SpaceBetween>
+ </View>
{filters && filters.length > 0 && (
<View style={{ marginTop: 5 }}>
diff --git a/packages/desktop-client/src/components/reports/graphs/NetWorthGraph.tsx b/packages/desktop-client/src/components/reports/graphs/NetWorthGraph.tsx
index ba822d431b..0aa8eee843 100644
--- a/packages/desktop-client/src/components/reports/graphs/NetWorthGraph.tsx
+++ b/packages/desktop-client/src/components/reports/graphs/NetWorthGraph.tsx
@@ -1,11 +1,12 @@
// @ts-strict-ignore
-import React, { useId } from 'react';
+import React, { useId, useMemo } from 'react';
import { useTranslation } from 'react-i18next';
import { AlignedText } from '@actual-app/components/aligned-text';
import { type CSSProperties } from '@actual-app/components/styles';
import { theme } from '@actual-app/components/theme';
import { css } from '@emotion/css';
+import { parse, getDay } from 'date-fns';
import {
AreaChart,
Area,
@@ -40,6 +41,7 @@ type NetWorthGraphProps = {
};
compact?: boolean;
showTooltip?: boolean;
+ interval?: string;
};
export function NetWorthGraph({
@@ -47,11 +49,16 @@ export function NetWorthGraph({
graphData,
compact = false,
showTooltip = true,
+ interval = 'Monthly',
}: NetWorthGraphProps) {
const { t } = useTranslation();
const privacyMode = usePrivacyMode();
const id = useId();
+ // Use more aggressive smoothening for high-frequency data
+ const interpolationType =
+ interval === 'Daily' || interval === 'Weekly' ? 'basis' : 'monotone';
+
const tickFormatter = tick => {
const res = privacyMode
? '...'
@@ -77,6 +84,19 @@ export function NetWorthGraph({
const off = gradientOffset();
const gradientId = `splitColor-${id}`;
+ // Generate weekly tick positions when viewing Daily data
+ const weeklyTicks = useMemo(() => {
+ if (interval !== 'Daily') {
+ return undefined;
+ }
+ return graphData.data
+ .filter(point => {
+ const date = parse(point.x, 'yy-MM-dd', new Date());
+ return getDay(date) === 1; // Monday
+ })
+ .map(point => point.x);
+ }, [interval, graphData.data]);
+
type PayloadItem = {
payload: {
date: string;
@@ -165,6 +185,7 @@ export function NetWorthGraph({
hide={compact}
tick={{ fill: theme.pageText }}
tickLine={{ stroke: theme.pageText }}
+ ticks={weeklyTicks}
/>
<YAxis
dataKey="y"
@@ -197,14 +218,16 @@ export function NetWorthGraph({
</defs>
<Area
- type="monotone"
+ type={interpolationType}
dot={false}
activeDot={false}
animationDuration={0}
dataKey="y"
stroke={theme.reportsBlue}
+ strokeWidth={2}
fill={`url(#${gradientId})`}
fillOpacity={1}
+ connectNulls={true}
/>
</AreaChart>
</div>
diff --git a/packages/desktop-client/src/components/reports/reports/NetWorth.tsx b/packages/desktop-client/src/components/reports/reports/NetWorth.tsx
index 13da57dd67..cdfebf2162 100644
--- a/packages/desktop-client/src/components/reports/reports/NetWorth.tsx
+++ b/packages/desktop-client/src/components/reports/reports/NetWorth.tsx
@@ -1,10 +1,13 @@
-import React, { useState, useEffect, useMemo } from 'react';
+import React, { useState, useEffect, useMemo, useRef } from 'react';
import { Trans, useTranslation } from 'react-i18next';
import { useParams } from 'react-router';
import { Button } from '@actual-app/components/button';
import { useResponsive } from '@actual-app/components/hooks/useResponsive';
+import { SvgCalendar } from '@actual-app/components/icons/v1';
+import { Menu } from '@actual-app/components/menu';
import { Paragraph } from '@actual-app/components/paragraph';
+import { Popover } from '@actual-app/components/popover';
import { styles } from '@actual-app/components/styles';
import { theme } from '@actual-app/components/theme';
import { View } from '@actual-app/components/view';
@@ -27,6 +30,7 @@ import { Change } from '@desktop-client/components/reports/Change';
import { NetWorthGraph } from '@desktop-client/components/reports/graphs/NetWorthGraph';
import { Header } from '@desktop-client/components/reports/Header';
import { LoadingIndicator } from '@desktop-client/components/reports/LoadingIndicator';
+import { ReportOptions } from '@desktop-client/components/reports/ReportOptions';
import { calculateTimeRange } from '@desktop-client/components/reports/reportRanges';
import { createSpreadsheet as netWorthSpreadsheet } from '@desktop-client/components/reports/spreadsheets/net-worth-spreadsheet';
import { useReport } from '@desktop-client/components/reports/useReport';
@@ -87,6 +91,10 @@ function NetWorthInner({ widget }: NetWorthInnerProps) {
const [start, setStart] = useState(initialStart);
const [end, setEnd] = useState(initialEnd);
const [mode, setMode] = useState(initialMode);
+ const [interval, setInterval] = useState(widget?.meta?.interval || 'Monthly');
+
+ const [_firstDayOfWeekIdx] = useSyncedPref('firstDayOfWeekIdx');
+ const firstDayOfWeekIdx = _firstDayOfWeekIdx || '0';
const reportParams = useMemo(
() =>
@@ -97,8 +105,19 @@ function NetWorthInner({ widget }: NetWorthInnerProps) {
conditions,
conditionsOp,
locale,
+ interval,
+ firstDayOfWeekIdx,
),
- [start, end, accounts, conditions, conditionsOp, locale],
+ [
+ start,
+ end,
+ accounts,
+ conditions,
+ conditionsOp,
+ locale,
+ interval,
+ firstDayOfWeekIdx,
+ ],
);
const data = useReport('net_worth', reportParams);
useEffect(() => {
@@ -147,6 +166,7 @@ function NetWorthInner({ widget }: NetWorthInnerProps) {
...(widget.meta ?? {}),
conditions,
conditionsOp,
+ interval,
timeFrame: {
start,
end,
@@ -184,8 +204,6 @@ function NetWorthInner({ widget }: NetWorthInnerProps) {
};
const [earliestTransaction, _] = useState('');
- const [_firstDayOfWeekIdx] = useSyncedPref('firstDayOfWeekIdx');
- const firstDayOfWeekIdx = _firstDayOfWeekIdx || '0';
if (!allMonths || !data) {
return null;
@@ -232,6 +250,9 @@ function NetWorthInner({ widget }: NetWorthInnerProps) {
onDeleteFilter={onDeleteFilter}
conditionsOp={conditionsOp}
onConditionsOpChange={onConditionsOpChange}
+ inlineContent={
+ <IntervalSelector interval={interval} onChange={setInterval} />
+ }
>
{widget && (
<Button variant="primary" onPress={onSaveWidget}>
@@ -268,6 +289,7 @@ function NetWorthInner({ widget }: NetWorthInnerProps) {
<NetWorthGraph
graphData={data.graphData}
showTooltip={!isNarrowWidth}
+ interval={interval}
/>
<View style={{ marginTop: 30, userSelect: 'none' }}>
@@ -290,3 +312,51 @@ function NetWorthInner({ widget }: NetWorthInnerProps) {
</Page>
);
}
+
+// Interval selector component with icon-only trigger similar to filter button
+function IntervalSelector({
+ interval,
+ onChange,
+}: {
+ interval: 'Daily' | 'Weekly' | 'Monthly' | 'Yearly';
+ onChange: (val: 'Daily' | 'Weekly' | 'Monthly' | 'Yearly') => void;
+}) {
+ const triggerRef = useRef<HTMLButtonElement | null>(null);
+ const [isOpen, setIsOpen] = useState(false);
+
+ const currentLabel =
+ ReportOptions.interval.find(opt => opt.key === interval)?.description ??
+ interval;
+
+ return (
+ <>
+ <Button
+ ref={triggerRef}
+ variant="bare"
+ onPress={() => setIsOpen(true)}
+ aria-label="Change interval"
+ >
+ <SvgCalendar style={{ width: 12, height: 12 }} />
+ <span style={{ marginLeft: 5 }}>{currentLabel}</span>
+ </Button>
+
+ <Popover
+ triggerRef={triggerRef}
+ placement="bottom start"
+ isOpen={isOpen}
+ onOpenChange={() => setIsOpen(false)}
+ >
+ <Menu
+ onMenuSelect={item => {
+ onChange(item as 'Daily' | 'Weekly' | 'Monthly' | 'Yearly');
+ setIsOpen(false);
+ }}
+ items={ReportOptions.interval.map(({ key, description }) => ({
+ name: key as 'Daily' | 'Weekly' | 'Monthly' | 'Yearly',
+ text: description,
+ }))}
+ />
+ </Popover>
+ </>
+ );
+}
diff --git a/packages/desktop-client/src/components/reports/reports/NetWorthCard.tsx b/packages/desktop-client/src/components/reports/reports/NetWorthCard.tsx
index 52c3054c83..0353b75ae4 100644
--- a/packages/desktop-client/src/components/reports/reports/NetWorthCard.tsx
+++ b/packages/desktop-client/src/components/reports/reports/NetWorthCard.tsx
@@ -23,6 +23,7 @@ import { calculateTimeRange } from '@desktop-client/components/reports/reportRan
import { createSpreadsheet as netWorthSpreadsheet } from '@desktop-client/components/reports/spreadsheets/net-worth-spreadsheet';
import { useReport } from '@desktop-client/components/reports/useReport';
import { useLocale } from '@desktop-client/hooks/useLocale';
+import { useSyncedPref } from '@desktop-client/hooks/useSyncedPref';
type NetWorthCardProps = {
widgetId: string;
@@ -44,6 +45,8 @@ export function NetWorthCard({
const locale = useLocale();
const { t } = useTranslation();
const { isNarrowWidth } = useResponsive();
+ const [_firstDayOfWeekIdx] = useSyncedPref('firstDayOfWeekIdx');
+ const firstDayOfWeekIdx = _firstDayOfWeekIdx || '0';
const [nameMenuOpen, setNameMenuOpen] = useState(false);
@@ -61,8 +64,19 @@ export function NetWorthCard({
meta?.conditions,
meta?.conditionsOp,
locale,
+ meta?.interval || 'Monthly',
+ firstDayOfWeekIdx,
),
- [start, end, accounts, meta?.conditions, meta?.conditionsOp, locale],
+ [
+ start,
+ end,
+ accounts,
+ meta?.conditions,
+ meta?.conditionsOp,
+ locale,
+ meta?.interval,
+ firstDayOfWeekIdx,
+ ],
);
const data = useReport('net_worth', params);
@@ -140,6 +154,7 @@ export function NetWorthCard({
graphData={data.graphData}
compact={true}
showTooltip={!isEditing && !isNarrowWidth}
+ interval={meta?.interval || 'Monthly'}
style={{ height: 'auto', flex: 1 }}
/>
) : (
diff --git a/packages/desktop-client/src/components/reports/spreadsheets/net-worth-spreadsheet.ts b/packages/desktop-client/src/components/reports/spreadsheets/net-worth-spreadsheet.ts
index ba673814d3..7f64527b82 100644
--- a/packages/desktop-client/src/components/reports/spreadsheets/net-worth-spreadsheet.ts
+++ b/packages/desktop-client/src/components/reports/spreadsheets/net-worth-spreadsheet.ts
@@ -15,6 +15,7 @@ import {
type RuleConditionEntity,
} from 'loot-core/types/models';
+import { ReportOptions } from '@desktop-client/components/reports/ReportOptions';
import { type useSpreadsheet } from '@desktop-client/hooks/useSpreadsheet';
import { aqlQuery } from '@desktop-client/queries/aqlQuery';
@@ -30,6 +31,8 @@ export function createSpreadsheet(
conditions: RuleConditionEntity[] = [],
conditionsOp: 'and' | 'or' = 'and',
locale: Locale,
+ interval: string = 'Monthly',
+ firstDayOfWeekIdx: string = '0',
) {
return async (
spreadsheet: ReturnType<typeof useSpreadsheet>,
@@ -40,6 +43,24 @@ export function createSpreadsheet(
});
const conditionsOpKey = conditionsOp === 'or' ? '$or' : '$and';
+ // Convert dates to ensure we have the full range. Then clamp end date to avoid future projections
+ const startDate = monthUtils.firstDayOfMonth(start);
+
+ // Start with the provided end-of-month date, then adjust for current context
+ let endDate = monthUtils.lastDayOfMonth(end);
+
+ if (interval === 'Daily') {
+ const today = monthUtils.currentDay();
+ if (monthUtils.isAfter(endDate, today)) {
+ endDate = today;
+ }
+ } else if (interval === 'Weekly') {
+ const currentWeekStart = monthUtils.currentWeek(firstDayOfWeekIdx);
+ if (monthUtils.isAfter(endDate, currentWeekStart)) {
+ endDate = currentWeekStart;
+ }
+ }
+
const data = await Promise.all(
accounts.map(async acct => {
const [starting, balances]: [number, Balance[]] = await Promise.all([
@@ -48,7 +69,7 @@ export function createSpreadsheet(
.filter({
[conditionsOpKey]: filters,
account: acct.id,
- date: { $lt: monthUtils.firstDayOfMonth(start) },
+ date: { $lt: startDate },
})
.calculate({ $sum: '$amount' }),
).then(({ data }) => data),
@@ -61,27 +82,69 @@ export function createSpreadsheet(
.filter({
account: acct.id,
$and: [
- { date: { $gte: monthUtils.firstDayOfMonth(start) } },
- { date: { $lte: monthUtils.lastDayOfMonth(end) } },
+ { date: { $gte: startDate } },
+ { date: { $lte: endDate } },
],
})
- .groupBy({ $month: '$date' })
+ .groupBy(
+ interval === 'Yearly'
+ ? { $year: '$date' }
+ : interval === 'Daily' || interval === 'Weekly'
+ ? 'date'
+ : { $month: '$date' },
+ )
.select([
- { date: { $month: '$date' } },
+ {
+ date:
+ interval === 'Yearly'
+ ? { $year: '$date' }
+ : interval === 'Daily' || interval === 'Weekly'
+ ? 'date'
+ : { $month: '$date' },
+ },
{ amount: { $sum: '$amount' } },
]),
).then(({ data }) => data),
]);
+ // For weekly intervals, transform dates to week format and properly aggregate
+ let processedBalances: Record<string, Balance>;
+ if (interval === 'Weekly') {
+ // Group transactions by week and sum their amounts
+ const weeklyBalances: Record<string, number> = {};
+ balances.forEach(b => {
+ const weekDate = monthUtils.weekFromDate(b.date, firstDayOfWeekIdx);
+ weeklyBalances[weekDate] =
+ (weeklyBalances[weekDate] || 0) + b.amount;
+ });
+
+ // Convert back to Balance format
+ processedBalances = {};
+ Object.entries(weeklyBalances).forEach(([date, amount]) => {
+ processedBalances[date] = { date, amount };
+ });
+ } else {
+ processedBalances = keyBy(balances, 'date');
+ }
+
return {
id: acct.id,
- balances: keyBy(balances, 'date'),
+ balances: processedBalances,
starting,
};
}),
);
- setData(recalculate(data, start, end, locale));
+ setData(
+ recalculate(
+ data,
+ startDate,
+ endDate,
+ locale,
+ interval,
+ firstDayOfWeekIdx,
+ ),
+ );
};
}
@@ -91,18 +154,30 @@ function recalculate(
balances: Record<string, Balance>;
starting: number;
}>,
- start: string,
- end: string,
+ startDate: string,
+ endDate: string,
locale: Locale,
+ interval: string = 'Monthly',
+ firstDayOfWeekIdx: string = '0',
) {
- const months = monthUtils.rangeInclusive(start, end);
+ // Get intervals using the same pattern as other working spreadsheets
+ const intervals =
+ interval === 'Weekly'
+ ? monthUtils.weekRangeInclusive(startDate, endDate, firstDayOfWeekIdx)
+ : interval === 'Daily'
+ ? monthUtils.dayRangeInclusive(startDate, endDate)
+ : interval === 'Yearly'
+ ? monthUtils.yearRangeInclusive(startDate, endDate)
+ : monthUtils.rangeInclusive(
+ monthUtils.getMonth(startDate),
+ monthUtils.getMonth(endDate),
+ );
const accountBalances = data.map(account => {
- // Start off with the balance at that point in time
let balance = account.starting;
- return months.map(month => {
- if (account.balances[month]) {
- balance += account.balances[month].amount;
+ return intervals.map(intervalItem => {
+ if (account.balances[intervalItem]) {
+ balance += account.balances[intervalItem].amount;
}
return balance;
});
@@ -114,7 +189,7 @@ function recalculate(
let lowestNetWorth: number | null = null;
let highestNetWorth: number | null = null;
- const graphData = months.reduce<
+ const graphData = intervals.reduce<
Array<{
x: string;
y: number;
@@ -124,7 +199,7 @@ function recalculate(
networth: string;
date: string;
}>
- >((arr, month, idx) => {
+ >((arr, intervalItem, idx) => {
let debt = 0;
let assets = 0;
let total = 0;
@@ -144,7 +219,16 @@ function recalculate(
hasNegative = true;
}
- const x = d.parseISO(month + '-01');
+ // Parse dates based on interval type - following the working pattern
+ let x: Date;
+ if (interval === 'Daily' || interval === 'Weekly') {
+ x = d.parseISO(intervalItem);
+ } else if (interval === 'Yearly') {
+ x = d.parseISO(intervalItem + '-01-01');
+ } else {
+ x = d.parseISO(intervalItem + '-01');
+ }
+
const change = last ? total - amountToInteger(last.y) : 0;
if (arr.length === 0) {
@@ -152,24 +236,39 @@ function recalculate(
}
endNetWorth = total;
- arr.push({
- x: d.format(x, 'MMM ’yy', { locale }),
+ // Use standardized format from ReportOptions
+ const displayFormat =
+ ReportOptions.intervalFormat.get(interval) ?? 'MMM ‘yy';
+
+ const tooltipFormat =
+ interval === 'Daily'
+ ? 'MMMM d, yyyy'
+ : interval === 'Weekly'
+ ? 'MMM d, yyyy'
+ : interval === 'Yearly'
+ ? 'yyyy'
+ : 'MMMM yyyy';
+
+ const graphPoint = {
+ x: d.format(x, displayFormat, { locale }),
y: integerToAmount(total),
assets: integerToCurrency(assets),
debt: `-${integerToCurrency(debt)}`,
change: integerToCurrency(change),
networth: integerToCurrency(total),
- date: d.format(x, 'MMMM yyyy', { locale }),
- });
+ date: d.format(x, tooltipFormat, { locale }),
+ };
+
+ arr.push(graphPoint);
+
+ // Track min/max for the current point only
+ if (lowestNetWorth === null || graphPoint.y < lowestNetWorth) {
+ lowestNetWorth = graphPoint.y;
+ }
+ if (highestNetWorth === null || graphPoint.y > highestNetWorth) {
+ highestNetWorth = graphPoint.y;
+ }
- arr.forEach(item => {
- if (lowestNetWorth === null || item.y < lowestNetWorth) {
- lowestNetWorth = item.y;
- }
- if (highestNetWorth === null || item.y > highestNetWorth) {
- highestNetWorth = item.y;
- }
- });
return arr;
}, []);
@@ -177,8 +276,8 @@ function recalculate(
graphData: {
data: graphData,
hasNegative,
- start,
- end,
+ start: startDate,
+ end: endDate,
},
netWorth: endNetWorth,
totalChange: endNetWorth - startNetWorth,
diff --git a/packages/loot-core/src/types/models/dashboard.ts b/packages/loot-core/src/types/models/dashboard.ts
index 2ceb64b052..47afb372d0 100644
--- a/packages/loot-core/src/types/models/dashboard.ts
+++ b/packages/loot-core/src/types/models/dashboard.ts
@@ -28,6 +28,7 @@ export type NetWorthWidget = AbstractWidget<
conditions?: RuleConditionEntity[];
conditionsOp?: 'and' | 'or';
timeFrame?: TimeFrame;
+ interval?: 'Daily' | 'Weekly' | 'Monthly' | 'Yearly';
} | null
>;
export type CashFlowWidget = AbstractWidget<
diff --git a/upcoming-release-notes/5282.md b/upcoming-release-notes/5282.md
new file mode 100644
index 0000000000..857ba6902d
--- /dev/null
+++ b/upcoming-release-notes/5282.md
@@ -0,0 +1,6 @@
+---
+category: Enhancements
+authors: [SaiPratyush]
+---
+
+Add interval picker for net worth report