From ae22535dd06d16cec6f7467f01ad79421848a738 Mon Sep 17 00:00:00 2001 From: Julien Froidefond Date: Thu, 9 Oct 2025 14:01:36 +0200 Subject: [PATCH] refactor: improve type safety in CustomLabel for StatusDistributionChart component - Updated the CustomLabel component to use PieLabelRenderProps for better type definitions. - Added type guards to ensure numeric values are validated before rendering labels, enhancing robustness. --- .../charts/StatusDistributionChart.tsx | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/components/dashboard/charts/StatusDistributionChart.tsx b/src/components/dashboard/charts/StatusDistributionChart.tsx index 98a687f..e1cc572 100644 --- a/src/components/dashboard/charts/StatusDistributionChart.tsx +++ b/src/components/dashboard/charts/StatusDistributionChart.tsx @@ -7,6 +7,7 @@ import { ResponsiveContainer, Tooltip, Legend, + PieLabelRenderProps, } from 'recharts'; interface StatusDistributionData { @@ -72,15 +73,21 @@ export function StatusDistributionChart({ return null; }; - const CustomLabel = (props: { - cx: number; - cy: number; - midAngle: number; - innerRadius: number; - outerRadius: number; - percent: number; - }) => { + const CustomLabel = (props: PieLabelRenderProps) => { const { cx, cy, midAngle, innerRadius, outerRadius, percent } = props; + + // Type guards to ensure we have the required numeric values + if ( + typeof cx !== 'number' || + typeof cy !== 'number' || + typeof midAngle !== 'number' || + typeof innerRadius !== 'number' || + typeof outerRadius !== 'number' || + typeof percent !== 'number' + ) { + return null; + } + if (percent < 0.05) return null; // Ne pas afficher les labels pour les petites sections const RADIAN = Math.PI / 180;