"use client";
import {
Cell,
Legend,
Pie,
PieChart,
ResponsiveContainer,
Tooltip,
} from "recharts";
interface DonutChartInnerProps {
data: Array<{ name: string; value: number; color?: string }>;
title?: string;
centerText?: {
title: string;
value: string | number;
};
colors: string[];
height: number;
}
interface TooltipProps {
active?: boolean;
payload?: Array<{
name: string;
value: number;
payload: { total: number };
}>;
}
const CustomTooltip = ({ active, payload }: TooltipProps) => {
if (active && payload && payload.length) {
const data = payload[0];
return (
{data.name}
{data.value}{" "}
sessions ({((data.value / data.payload.total) * 100).toFixed(1)}%)
);
}
return null;
};
interface LegendProps {
payload?: Array<{
value: string;
color: string;
type?: string;
}>;
}
const CustomLegend = ({ payload }: LegendProps) => {
return (
{payload?.map((entry, index) => (
))}
);
};
interface CenterLabelProps {
centerText?: {
title: string;
value: string | number;
};
}
const CenterLabel = ({ centerText }: CenterLabelProps) => {
if (!centerText) return null;
return (
{centerText.value}
{centerText.title}
);
};
export default function DonutChartInner({
data,
title,
centerText,
colors,
height,
}: DonutChartInnerProps) {
const total = data.reduce((sum, item) => sum + item.value, 0);
const dataWithTotal = data.map((item) => ({ ...item, total }));
return (
{
if (e.key === "Enter" || e.key === " ") {
e.preventDefault();
}
}}
>
{dataWithTotal.map((entry, index) => (
|
))}
} />
} />
);
}