Skip to content
Snippets Groups Projects
Unverified Commit 3e03718f authored by Neil's avatar Neil Committed by GitHub
Browse files

Fix spending report error (#2745)

* spending error

* fixes

* notes
parent 9c3075f6
No related branches found
No related tags found
No related merge requests found
...@@ -145,8 +145,12 @@ export function SpendingGraph({ ...@@ -145,8 +145,12 @@ export function SpendingGraph({
: b, : b,
).months[lastMonth][balanceTypeOp]; ).months[lastMonth][balanceTypeOp];
const maxYAxis = selectionMax > thisMonthMax; const maxYAxis = selectionMax > thisMonthMax;
const dataMax = Math.max(...data.intervalData.map(i => i[balanceTypeOp])); const dataMax = Math.max(
const dataMin = Math.min(...data.intervalData.map(i => i[balanceTypeOp])); ...data.intervalData.map(i => i.months[thisMonth].cumulative),
);
const dataMin = Math.min(
...data.intervalData.map(i => i.months[thisMonth].cumulative),
);
const tickFormatter = tick => { const tickFormatter = tick => {
if (!privacyMode) return `${amountToCurrencyNoDecimal(tick)}`; // Formats the tick values as strings with commas if (!privacyMode) return `${amountToCurrencyNoDecimal(tick)}`; // Formats the tick values as strings with commas
...@@ -154,18 +158,16 @@ export function SpendingGraph({ ...@@ -154,18 +158,16 @@ export function SpendingGraph({
}; };
const gradientOffset = () => { const gradientOffset = () => {
if (dataMax <= 0) { if (!dataMax || dataMax <= 0) {
return 0; return 0;
} }
if (dataMin >= 0) { if (!dataMin || dataMin >= 0) {
return 1; return 1;
} }
return dataMax / (dataMax - dataMin); return dataMax / (dataMax - dataMin);
}; };
const off = gradientOffset();
const getVal = (obj, month) => { const getVal = (obj, month) => {
if (month === 'average') { if (month === 'average') {
return obj[month] && -1 * obj[month]; return obj[month] && -1 * obj[month];
...@@ -246,7 +248,7 @@ export function SpendingGraph({ ...@@ -246,7 +248,7 @@ export function SpendingGraph({
y2="1" y2="1"
> >
<stop <stop
offset={off} offset={gradientOffset()}
stopColor={theme.reportsGreen} stopColor={theme.reportsGreen}
stopOpacity={0.2} stopOpacity={0.2}
/> />
...@@ -259,7 +261,7 @@ export function SpendingGraph({ ...@@ -259,7 +261,7 @@ export function SpendingGraph({
y2="1" y2="1"
> >
<stop <stop
offset={off} offset={gradientOffset()}
stopColor={theme.reportsGreen} stopColor={theme.reportsGreen}
stopOpacity={1} stopOpacity={1}
/> />
......
---
category: Bugfix
authors: [carkom]
---
Fixes a NaN error in spending report.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment