Skip to content

A local-first personal finance app

Fix spending report error (#2745)

Neil3e03718f1313
diff --git a/packages/desktop-client/src/components/reports/graphs/SpendingGraph.tsx b/packages/desktop-client/src/components/reports/graphs/SpendingGraph.tsx
index e74f646307..616315fd24 100644
--- a/packages/desktop-client/src/components/reports/graphs/SpendingGraph.tsx
+++ b/packages/desktop-client/src/components/reports/graphs/SpendingGraph.tsx
@@ -145,8 +145,12 @@ export function SpendingGraph({
: b,
).months[lastMonth][balanceTypeOp];
const maxYAxis = selectionMax > thisMonthMax;
- const dataMax = Math.max(...data.intervalData.map(i => i[balanceTypeOp]));
- const dataMin = Math.min(...data.intervalData.map(i => i[balanceTypeOp]));
+ const dataMax = Math.max(
+ ...data.intervalData.map(i => i.months[thisMonth].cumulative),
+ );
+ const dataMin = Math.min(
+ ...data.intervalData.map(i => i.months[thisMonth].cumulative),
+ );
const tickFormatter = tick => {
if (!privacyMode) return `${amountToCurrencyNoDecimal(tick)}`; // Formats the tick values as strings with commas
@@ -154,18 +158,16 @@ export function SpendingGraph({
};
const gradientOffset = () => {
- if (dataMax <= 0) {
+ if (!dataMax || dataMax <= 0) {
return 0;
}
- if (dataMin >= 0) {
+ if (!dataMin || dataMin >= 0) {
return 1;
}
return dataMax / (dataMax - dataMin);
};
- const off = gradientOffset();
-
const getVal = (obj, month) => {
if (month === 'average') {
return obj[month] && -1 * obj[month];
@@ -246,7 +248,7 @@ export function SpendingGraph({
y2="1"
>
<stop
- offset={off}
+ offset={gradientOffset()}
stopColor={theme.reportsGreen}
stopOpacity={0.2}
/>
@@ -259,7 +261,7 @@ export function SpendingGraph({
y2="1"
>
<stop
- offset={off}
+ offset={gradientOffset()}
stopColor={theme.reportsGreen}
stopOpacity={1}
/>
diff --git a/upcoming-release-notes/2745.md b/upcoming-release-notes/2745.md
new file mode 100644
index 0000000000..7898425d76
--- /dev/null
+++ b/upcoming-release-notes/2745.md
@@ -0,0 +1,6 @@
+---
+category: Bugfix
+authors: [carkom]
+---
+
+Fixes a NaN error in spending report.