Fix Net Worth graph not showing correct number of intervals (#7296)

* Fix Net Worth graph showing N-1 intervals, resulting in inconsistent totalChange value.

* Fix starting date being wrong for 'daily' and 'weekly'

* Linting

* Add release note

* Update VRT screenshots

Auto-generated by VRT workflow

PR: #7296

* Remove manipulation of startDate for 'yearly'

The result was not consistent with the reports previous behavior when yearly was selected (it went back too far).

* Remove empty datapoint at beginning when start equals earliest transaction

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
This commit is contained in:
Emil Tveden Bjerglund
2026-04-08 04:40:28 +02:00
committed by GitHub
parent 2295e6d464
commit 3d5881ea57
11 changed files with 47 additions and 3 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 101 KiB

After

Width:  |  Height:  |  Size: 104 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 102 KiB

After

Width:  |  Height:  |  Size: 103 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 102 KiB

After

Width:  |  Height:  |  Size: 104 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 105 KiB

After

Width:  |  Height:  |  Size: 105 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 103 KiB

After

Width:  |  Height:  |  Size: 104 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 106 KiB

After

Width:  |  Height:  |  Size: 106 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 92 KiB

After

Width:  |  Height:  |  Size: 91 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 92 KiB

After

Width:  |  Height:  |  Size: 92 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 95 KiB

After

Width:  |  Height:  |  Size: 95 KiB

View File

@@ -40,8 +40,42 @@ 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);
// Go back exactly one interval before the selected range start
// to get the correct starting balance for the first period
const rangeStart = d.parseISO(monthUtils.firstDayOfMonth(start));
let startDate: string;
if (interval === 'Daily') {
startDate = monthUtils.dayFromDate(d.subDays(rangeStart, 1));
} else if (interval === 'Weekly') {
startDate = monthUtils.weekFromDate(
d.subDays(rangeStart, 1),
firstDayOfWeekIdx,
);
} else {
// Monthly or yearly
startDate = monthUtils.firstDayOfMonth(monthUtils.prevMonth(start));
}
// If the earliest transaction is on or after the first day of the start
// month, the prior period lookback would be empty (all zeros). Skip it to
// avoid rendering an empty data point.
const earliestTransaction = await send('get-earliest-transaction');
if (
earliestTransaction &&
earliestTransaction.date >= monthUtils.firstDayOfMonth(start)
) {
if (interval === 'Daily') {
startDate = earliestTransaction.date;
} else if (interval === 'Weekly') {
startDate = monthUtils.weekFromDate(
earliestTransaction.date,
firstDayOfWeekIdx,
);
} else {
// Monthly or Yearly
startDate = monthUtils.firstDayOfMonth(start);
}
}
// Start with the provided end-of-month date, then adjust for current context
let endDate = monthUtils.lastDayOfMonth(end);
@@ -193,6 +227,7 @@ function recalculate(
);
let hasNegative = false;
let startNetWorth = 0;
let endNetWorth = 0;
let lowestNetWorth: number | null = null;
let highestNetWorth: number | null = null;
@@ -242,6 +277,9 @@ function recalculate(
const change = last ? total - last.y : total - priorPeriodNetWorth;
if (arr.length === 0) {
startNetWorth = total;
}
endNetWorth = total;
// Use standardized format from ReportOptions
@@ -293,7 +331,7 @@ function recalculate(
end: endDate,
},
netWorth: endNetWorth,
totalChange: endNetWorth - priorPeriodNetWorth,
totalChange: endNetWorth - startNetWorth,
lowestNetWorth,
highestNetWorth,
accounts: data

View File

@@ -0,0 +1,6 @@
---
category: Bugfixes
authors: [emiltb]
---
Fix Net Worth graph showing a time-interval less than specified