Skip to content

Commit

Permalink
Enhance Y-Axis Scaling on Net Worth Graph (#1709)
Browse files Browse the repository at this point in the history
  • Loading branch information
Crazypkr1099 authored Sep 19, 2023
1 parent ddb78af commit 16334f6
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
4 changes: 3 additions & 1 deletion packages/desktop-client/src/components/reports/NetWorth.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ export default function NetWorth() {
[start, end, accounts, filters, conditionsOp],
);
const data = useReport('net_worth', params);

useEffect(() => {
async function run() {
const trans = await send('get-earliest-transaction');
Expand Down Expand Up @@ -133,6 +132,9 @@ export default function NetWorth() {
start={start}
end={end}
graphData={data.graphData}
domain={{
y: [data.lowestNetWorth * 0.99, data.highestNetWorth * 1.01],
}}
/>

<View style={{ marginTop: 30 }}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,16 @@ type NetWorthGraphProps = {
style?: CSSProperties;
graphData;
compact: boolean;
domain?: {
y?: [number, number];
};
};
function NetWorthGraph({ style, graphData, compact }: NetWorthGraphProps) {
function NetWorthGraph({
style,
graphData,
compact,
domain,
}: NetWorthGraphProps) {
const Chart = compact ? VictoryGroup : VictoryChart;

return (
Expand All @@ -38,6 +46,7 @@ function NetWorthGraph({ style, graphData, compact }: NetWorthGraphProps) {
scale={{ x: 'time', y: 'linear' }}
theme={chartTheme}
domainPadding={{ x: 0, y: 10 }}
domain={domain}
width={width}
height={height}
containerComponent={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ function recalculate(data, start, end) {
let hasNegative = false;
let startNetWorth = 0;
let endNetWorth = 0;
let lowestNetWorth = null;
let highestNetWorth = null;

const graphData = months.reduce((arr, month, idx) => {
let debt = 0;
Expand Down Expand Up @@ -140,6 +142,15 @@ function recalculate(data, start, end) {
endNetWorth = total;

arr.push({ x, y: integerToAmount(total), premadeLabel: label });

arr.forEach(item => {
if (item.y < lowestNetWorth || lowestNetWorth === null) {
lowestNetWorth = item.y;
}
if (item.y > highestNetWorth || highestNetWorth === null) {
highestNetWorth = item.y;
}
});
return arr;
}, []);

Expand All @@ -152,5 +163,7 @@ function recalculate(data, start, end) {
},
netWorth: endNetWorth,
totalChange: endNetWorth - startNetWorth,
lowestNetWorth,
highestNetWorth,
};
}
6 changes: 6 additions & 0 deletions upcoming-release-notes/1709.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Enhancements
authors: [Crazypkr1099]
---

Enhance Y-Axis Scaling on Net Worth Graph

0 comments on commit 16334f6

Please sign in to comment.