/**
* Pie Chart Component
* Displays distribution data as a pie chart
*/
import {
PieChart as RechartsPieChart,
Pie,
Cell,
Tooltip,
Legend,
ResponsiveContainer,
} from 'recharts';
interface PieChartProps {
data: any[];
dataKey: string;
nameKey: string;
title?: string;
colors?: string[];
height?: number;
showLegend?: boolean;
innerRadius?: number;
outerRadius?: number;
formatter?: (value: number) => string;
}
const DEFAULT_COLORS = [
'#10b981', '#3b82f6', '#8b5cf6', '#f59e0b', '#ef4444',
'#06b6d4', '#ec4899', '#84cc16', '#f97316', '#6366f1',
];
export default function PieChart({
data,
dataKey,
nameKey,
title,
colors = DEFAULT_COLORS,
height = 300,
showLegend = true,
innerRadius = 0,
outerRadius = 80,
formatter = (value) => value.toLocaleString(),
}: PieChartProps) {
const RADIAN = Math.PI / 180;
const renderCustomizedLabel = ({
cx,
cy,
midAngle,
innerRadius,
outerRadius,
percent,
}: any) => {
if (percent < 0.05) return null;
const radius = innerRadius + (outerRadius - innerRadius) * 0.5;
const x = cx + radius * Math.cos(-midAngle * RADIAN);
const y = cy + radius * Math.sin(-midAngle * RADIAN);
return (