From d51aa9429e50135634b92135ada9229769cffa38 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Sat, 13 Sep 2025 23:40:25 +0000
Subject: [PATCH] Fix MonthlyTrends dynamic title, remove Period Summary,
convert BalanceChart to stacked area chart
Co-authored-by: elisiariocouto <818914+elisiariocouto@users.noreply.github.com>
---
.../src/components/analytics/BalanceChart.tsx | 18 +++++-----
.../components/analytics/MonthlyTrends.tsx | 28 ++++++++++++---
frontend/src/routes/analytics.tsx | 35 -------------------
3 files changed, 32 insertions(+), 49 deletions(-)
diff --git a/frontend/src/components/analytics/BalanceChart.tsx b/frontend/src/components/analytics/BalanceChart.tsx
index 897a194..05fcdf4 100644
--- a/frontend/src/components/analytics/BalanceChart.tsx
+++ b/frontend/src/components/analytics/BalanceChart.tsx
@@ -1,6 +1,6 @@
import {
- LineChart,
- Line,
+ AreaChart,
+ Area,
XAxis,
YAxis,
CartesianGrid,
@@ -111,7 +111,7 @@ export default function BalanceChart({ data, accounts, className }: BalanceChart
-
+
`€${value.toLocaleString()}`}
/>
[
+ formatter={(value: number, name: string) => [
`€${value.toLocaleString()}`,
- "Balance",
+ getAccountDisplayName(name),
]}
labelFormatter={(label) => `Date: ${label}`}
/>
{Object.keys(accountBalances).map((accountId, index) => (
-
))}
-
+
diff --git a/frontend/src/components/analytics/MonthlyTrends.tsx b/frontend/src/components/analytics/MonthlyTrends.tsx
index 2b37952..b7cfb16 100644
--- a/frontend/src/components/analytics/MonthlyTrends.tsx
+++ b/frontend/src/components/analytics/MonthlyTrends.tsx
@@ -53,7 +53,7 @@ export default function MonthlyTrends({ className, days = 365 }: MonthlyTrendsPr
if (!monthlyMap[monthKey]) {
monthlyMap[monthKey] = {
- month: date.toLocaleDateString(undefined, {
+ month: date.toLocaleDateString('en-GB', {
year: 'numeric',
month: 'short'
}),
@@ -77,10 +77,20 @@ export default function MonthlyTrends({ className, days = 365 }: MonthlyTrendsPr
...Object.entries(monthlyMap)
.sort(([a], [b]) => a.localeCompare(b))
.map(([, data]) => data)
- .slice(-12) // Last 12 months
);
}
+ // Calculate number of months to display based on days filter
+ const getMonthsToDisplay = (days: number): number => {
+ if (days <= 30) return 1;
+ if (days <= 180) return 6;
+ if (days <= 365) return 12;
+ return Math.ceil(days / 30);
+ };
+
+ const monthsToDisplay = getMonthsToDisplay(days);
+ const displayData = monthlyData.slice(-monthsToDisplay);
+
if (isLoading) {
return (
@@ -94,7 +104,7 @@ export default function MonthlyTrends({ className, days = 365 }: MonthlyTrendsPr
);
}
- if (monthlyData.length === 0) {
+ if (displayData.length === 0) {
return (
@@ -123,14 +133,22 @@ export default function MonthlyTrends({ className, days = 365 }: MonthlyTrendsPr
return null;
};
+ // Generate dynamic title based on time period
+ const getTitle = (days: number): string => {
+ if (days <= 30) return "Monthly Spending Trends (Last 30 Days)";
+ if (days <= 180) return "Monthly Spending Trends (Last 6 Months)";
+ if (days <= 365) return "Monthly Spending Trends (Last 12 Months)";
+ return `Monthly Spending Trends (Last ${Math.ceil(days / 30)} Months)`;
+ };
+
return (
- Monthly Spending Trends (Last 12 Months)
+ {getTitle(days)}
-
+
-
- {/* Summary Section */}
- {stats && (
-
-
- Period Summary ({stats.period_days} days)
-
-
-
-
Booked Transactions
-
{stats.booked_transactions}
-
-
-
Pending Transactions
-
{stats.pending_transactions}
-
-
-
Transaction Ratio
-
- {stats.total_transactions > 0
- ? `${Math.round(
- (stats.booked_transactions / stats.total_transactions) * 100
- )}% booked`
- : "No transactions"}
-
-
-
-
Spend Rate
-
- €{((stats.total_expenses || 0) / stats.period_days).toFixed(2)}/day
-
-
-
-
- )}
);
}