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,
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user