-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #49 from Robert-M-Lucas/dev-SCRUM-78
Added Graphs
- Loading branch information
Showing
7 changed files
with
474 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import {Line, LineChart, ResponsiveContainer, Tooltip, XAxis, YAxis} from "recharts"; | ||
import {Transaction} from "../../../utils/transaction.ts"; | ||
import strftime from "strftime"; | ||
import {round} from "lodash"; | ||
|
||
export default function balanceGraphTile(transactions: Transaction[]) { | ||
const data: { | ||
date: string, | ||
amount: number, | ||
}[] = []; | ||
|
||
let currentBalance = 0; | ||
|
||
if (transactions.length == 0) { | ||
return <p>No Data</p>; | ||
} | ||
|
||
const revTransactions = transactions.slice().reverse(); | ||
|
||
let currentDate = revTransactions[0].dateTime; | ||
|
||
for (const transaction of revTransactions) { | ||
const transDate = strftime("%d/%m/%y", new Date(transaction.dateTime)); | ||
|
||
// eslint-disable-next-line no-constant-condition | ||
while (true) { | ||
const date = strftime("%d/%m/%y", new Date(currentDate)); | ||
if (date === transDate) { | ||
break; | ||
} | ||
if (date === data[data.length - 1].date) { | ||
currentDate += 8.64e7; | ||
continue; | ||
} | ||
data.push( | ||
{ | ||
date: date, | ||
amount: round(currentBalance, 2), | ||
} | ||
) | ||
currentDate += 8.64e7; | ||
} | ||
|
||
currentBalance += transaction.amount; | ||
|
||
const val = { | ||
date: transDate, | ||
amount: round(currentBalance, 2), | ||
}; | ||
|
||
if (data.length > 0 && data[data.length - 1].date === transDate) { | ||
data[data.length - 1] = val; | ||
} | ||
else { | ||
data.push(val) | ||
} | ||
} | ||
|
||
return <> | ||
<p>Balance</p> | ||
<ResponsiveContainer width={"100%"} height={"100%"}> | ||
<LineChart data={data} margin={{top: 0, left: 0, right: 25, bottom: 0}}> | ||
<XAxis dataKey="date"/> | ||
<YAxis/> | ||
<Tooltip/> | ||
<Line type="monotone" dataKey="amount" stroke="#8884d8" dot={false}/> | ||
</LineChart> | ||
</ResponsiveContainer> | ||
</>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import {Line, LineChart, ResponsiveContainer, Tooltip, XAxis, YAxis} from "recharts"; | ||
import {Transaction} from "../../../utils/transaction.ts"; | ||
import strftime from "strftime"; | ||
import {round} from "lodash"; | ||
|
||
export default function expenseGraphTile(transactions: Transaction[]) { | ||
const data: { | ||
date: string, | ||
amount: number, | ||
}[] = []; | ||
|
||
let currentExpenses = 0; | ||
|
||
if (transactions.length == 0) { | ||
return <p>No Data</p>; | ||
} | ||
|
||
const revTransactions = transactions.slice().reverse(); | ||
|
||
let currentDate = revTransactions[0].dateTime; | ||
|
||
for (const transaction of revTransactions) { | ||
const transDate = strftime("%d/%m/%y", new Date(transaction.dateTime)); | ||
|
||
// eslint-disable-next-line no-constant-condition | ||
while (true) { | ||
const date = strftime("%d/%m/%y", new Date(currentDate)); | ||
if (date === transDate) { | ||
break; | ||
} | ||
if (date === data[data.length - 1].date) { | ||
currentDate += 8.64e7; | ||
continue; | ||
} | ||
data.push( | ||
{ | ||
date: date, | ||
amount: round(-currentExpenses, 2), | ||
} | ||
) | ||
currentDate += 8.64e7; | ||
} | ||
|
||
if (transaction.amount < 0) { | ||
currentExpenses += transaction.amount; | ||
} | ||
|
||
const val = { | ||
date: transDate, | ||
amount: round(-currentExpenses, 2), | ||
}; | ||
|
||
if (data.length > 0 && data[data.length - 1].date === transDate) { | ||
data[data.length - 1] = val; | ||
} | ||
else { | ||
data.push(val) | ||
} | ||
} | ||
|
||
return <> | ||
<p>Expenses</p> | ||
<ResponsiveContainer width={"100%"} height={"100%"}> | ||
<LineChart data={data} margin={{top: 0, left: 0, right: 25, bottom: 0}}> | ||
<XAxis dataKey="date"/> | ||
<YAxis/> | ||
<Tooltip/> | ||
<Line type="monotone" dataKey="amount" stroke="rgb(202, 15, 15)" dot={false}/> | ||
</LineChart> | ||
</ResponsiveContainer> | ||
</>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import {Line, LineChart, ResponsiveContainer, Tooltip, XAxis, YAxis} from "recharts"; | ||
import {Transaction} from "../../../utils/transaction.ts"; | ||
import strftime from "strftime"; | ||
import {round} from "lodash"; | ||
|
||
export default function incomeGraphTile(transactions: Transaction[]) { | ||
const data: { | ||
date: string, | ||
amount: number, | ||
}[] = []; | ||
|
||
let currentIncome = 0; | ||
|
||
if (transactions.length == 0) { | ||
return <p>No Data</p>; | ||
} | ||
|
||
const revTransactions = transactions.slice().reverse(); | ||
|
||
let currentDate = revTransactions[0].dateTime; | ||
|
||
for (const transaction of revTransactions) { | ||
const transDate = strftime("%d/%m/%y", new Date(transaction.dateTime)); | ||
|
||
// eslint-disable-next-line no-constant-condition | ||
while (true) { | ||
const date = strftime("%d/%m/%y", new Date(currentDate)); | ||
if (date === transDate) { | ||
break; | ||
} | ||
if (date === data[data.length - 1].date) { | ||
currentDate += 8.64e7; | ||
continue; | ||
} | ||
data.push( | ||
{ | ||
date: date, | ||
amount: round(currentIncome, 2), | ||
} | ||
) | ||
currentDate += 8.64e7; | ||
} | ||
|
||
if (transaction.amount > 0) { | ||
currentIncome += transaction.amount; | ||
} | ||
|
||
const val = { | ||
date: transDate, | ||
amount: round(currentIncome, 2), | ||
}; | ||
|
||
if (data.length > 0 && data[data.length - 1].date === transDate) { | ||
data[data.length - 1] = val; | ||
} | ||
else { | ||
data.push(val) | ||
} | ||
} | ||
|
||
return <> | ||
<p>Income</p> | ||
<ResponsiveContainer width={"100%"} height={"100%"}> | ||
<LineChart data={data} margin={{top: 0, left: 0, right: 25, bottom: 0}}> | ||
<XAxis dataKey="date"/> | ||
<YAxis/> | ||
<Tooltip/> | ||
<Line type="monotone" dataKey="amount" stroke="green" dot={false}/> | ||
</LineChart> | ||
</ResponsiveContainer> | ||
</>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import {Line, LineChart, ResponsiveContainer, Tooltip, XAxis, YAxis} from "recharts"; | ||
import {Transaction} from "../../../utils/transaction.ts"; | ||
import {UserPrefs} from "../../../utils/user_prefs.ts"; | ||
import strftime from "strftime"; | ||
import {round} from "lodash"; | ||
|
||
export default function needsGraphTile(transactions: Transaction[], userPrefs: UserPrefs) { | ||
const data: { | ||
date: string, | ||
amount: number, | ||
goal: number | ||
}[] = []; | ||
|
||
let currentIncome = 0; | ||
let currentNeeds = 0; | ||
|
||
if (transactions.length == 0) { | ||
return <p>No Data</p>; | ||
} | ||
|
||
const revTransactions = transactions.slice().reverse(); | ||
|
||
let currentDate = revTransactions[0].dateTime; | ||
|
||
for (const transaction of revTransactions) { | ||
const transDate = strftime("%d/%m/%y", new Date(transaction.dateTime)); | ||
|
||
// eslint-disable-next-line no-constant-condition | ||
while (true) { | ||
const date = strftime("%d/%m/%y", new Date(currentDate)); | ||
if (date === transDate) { | ||
break; | ||
} | ||
if (date === data[data.length - 1].date) { | ||
currentDate += 8.64e7; | ||
continue; | ||
} | ||
data.push( | ||
{ | ||
date: date, | ||
amount: round(-currentNeeds, 2), | ||
goal: round(currentIncome * userPrefs.getNeedsBudget(), 2), | ||
} | ||
) | ||
currentDate += 8.64e7; | ||
} | ||
|
||
if (transaction.amount > 0) { | ||
currentIncome += transaction.amount; | ||
} | ||
if (transaction.getCategoryCategory() == "Needs") { | ||
currentNeeds += transaction.amount; | ||
} | ||
|
||
const val = { | ||
date: transDate, | ||
amount: round(-currentNeeds, 2), | ||
goal: round(currentIncome * userPrefs.getNeedsBudget(), 2), | ||
}; | ||
|
||
if (data.length > 0 && data[data.length - 1].date === transDate) { | ||
data[data.length - 1] = val; | ||
} | ||
else { | ||
data.push(val) | ||
} | ||
} | ||
|
||
return <> | ||
<p>Needs</p> | ||
<ResponsiveContainer width={"100%"} height={"100%"}> | ||
<LineChart data={data} margin={{top: 0, left: 0, right: 25, bottom: 0}}> | ||
<XAxis dataKey="date"/> | ||
<YAxis/> | ||
<Tooltip/> | ||
<Line type="monotone" dataKey="amount" stroke="#8884d8" dot={false}/> | ||
<Line type="monotone" dataKey="goal" stroke="rgb(202, 15, 15)" dot={false}/> | ||
</LineChart> | ||
</ResponsiveContainer> | ||
</>; | ||
} |
Oops, something went wrong.