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:
@@ -44,20 +44,35 @@ export function MonthlyChart({
|
||||
}: MonthlyChartProps) {
|
||||
const [isExpanded, setIsExpanded] = useState(defaultExpanded);
|
||||
|
||||
// Calculer l'intervalle dynamiquement selon le nombre de données
|
||||
const getXAxisInterval = () => {
|
||||
if (data.length <= 6) return 0; // Afficher tous les labels pour 6 mois ou moins
|
||||
if (data.length <= 12) return 1; // Afficher un label sur deux pour 7-12 mois
|
||||
return Math.floor(data.length / 12); // Pour plus de 12 mois, afficher environ 12 labels
|
||||
};
|
||||
|
||||
// Formater les labels de manière plus compacte
|
||||
const formatMonthLabel = (month: string) => {
|
||||
// Format: "janv. 24" -> "janv 24" (enlever le point)
|
||||
return month.replace('.', '');
|
||||
};
|
||||
|
||||
const chartContent = (
|
||||
<>
|
||||
{data.length > 0 ? (
|
||||
<div className="h-[400px] sm:h-[300px]">
|
||||
<ResponsiveContainer width="100%" height="100%">
|
||||
<LineChart data={data} margin={{ left: 0, right: 10, top: 10, bottom: 5 }}>
|
||||
<LineChart data={data} margin={{ left: 0, right: 10, top: 10, bottom: data.length > 6 ? 80 : 60 }}>
|
||||
<CartesianGrid strokeDasharray="3 3" className="stroke-muted" />
|
||||
<XAxis
|
||||
dataKey="month"
|
||||
className="text-xs"
|
||||
angle={-45}
|
||||
textAnchor="end"
|
||||
height={60}
|
||||
interval={0}
|
||||
angle={data.length > 6 ? -45 : 0}
|
||||
textAnchor={data.length > 6 ? "end" : "middle"}
|
||||
height={data.length > 6 ? 80 : 60}
|
||||
interval={getXAxisInterval()}
|
||||
tickFormatter={formatMonthLabel}
|
||||
tick={{ fontSize: 11 }}
|
||||
/>
|
||||
<YAxis
|
||||
className="text-xs"
|
||||
|
||||
Reference in New Issue
Block a user