feat: improve MonthlyChart and transaction data formatting; dynamically adjust X-axis intervals and enhance month label presentation for better readability

This commit is contained in:
Julien Froidefond
2025-12-21 13:35:49 +01:00
parent 6f78dca1f0
commit b3ae6059ca
2 changed files with 42 additions and 17 deletions

View File

@@ -139,19 +139,29 @@ export function useTransactionsChartData({
monthlyMap.set(monthKey, current);
});
const monthlyChartData: MonthlyChartData[] = Array.from(
monthlyMap.entries()
)
.sort((a, b) => a[0].localeCompare(b[0]))
.map(([month, values]) => ({
month: new Date(month + "-01").toLocaleDateString("fr-FR", {
// Format months with year: use short format for better readability
const sortedMonths = Array.from(monthlyMap.entries()).sort((a, b) =>
a[0].localeCompare(b[0])
);
const monthlyChartData: MonthlyChartData[] = sortedMonths.map(
([monthKey, values]) => {
const date = new Date(monthKey + "-01");
// Format: "janv. 24" instead of "janv. 2024" for compactness
const monthLabel = date.toLocaleDateString("fr-FR", {
month: "short",
year: "numeric",
}),
revenus: values.income,
depenses: values.expenses,
solde: values.income - values.expenses,
}));
});
const yearShort = date.getFullYear().toString().slice(-2);
return {
month: `${monthLabel} ${yearShort}`,
revenus: values.income,
depenses: values.expenses,
solde: values.income - values.expenses,
};
}
);
return monthlyChartData;
}, [transactionsData]);