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:
@@ -7,6 +7,7 @@ import {
|
|||||||
ResponsiveContainer,
|
ResponsiveContainer,
|
||||||
Tooltip,
|
Tooltip,
|
||||||
Legend,
|
Legend,
|
||||||
|
PieLabelRenderProps,
|
||||||
} from 'recharts';
|
} from 'recharts';
|
||||||
|
|
||||||
interface StatusDistributionData {
|
interface StatusDistributionData {
|
||||||
@@ -72,15 +73,21 @@ export function StatusDistributionChart({
|
|||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
const CustomLabel = (props: {
|
const CustomLabel = (props: PieLabelRenderProps) => {
|
||||||
cx: number;
|
|
||||||
cy: number;
|
|
||||||
midAngle: number;
|
|
||||||
innerRadius: number;
|
|
||||||
outerRadius: number;
|
|
||||||
percent: number;
|
|
||||||
}) => {
|
|
||||||
const { cx, cy, midAngle, innerRadius, outerRadius, percent } = props;
|
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
|
if (percent < 0.05) return null; // Ne pas afficher les labels pour les petites sections
|
||||||
|
|
||||||
const RADIAN = Math.PI / 180;
|
const RADIAN = Math.PI / 180;
|
||||||
|
|||||||
Reference in New Issue
Block a user