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.
This commit is contained in:
Julien Froidefond
2025-10-09 14:01:36 +02:00
parent 0ffcec7ffc
commit ae22535dd0

View File

@@ -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;