import { useCallback, useState } from "react"; // recharts import { Cell, Legend, Pie, PieChart, ResponsiveContainer, Sector } from "recharts"; // helpers import { groupBy } from "helpers/array.helper"; // types import { IIssue } from "types"; // constants import { STATE_GROUP_COLORS } from "constants/state"; type Props = { issues: IIssue[] | undefined; }; export const IssuesPieChart: React.FC = ({ issues }) => { const [activeIndex, setActiveIndex] = useState(0); const groupedIssues = { backlog: [], unstarted: [], started: [], cancelled: [], completed: [], ...groupBy(issues ?? [], "state_detail.group"), }; const data = [ { name: "Backlog", value: groupedIssues.backlog.length, }, { name: "Unstarted", value: groupedIssues.unstarted.length, }, { name: "Started", value: groupedIssues.started.length, }, { name: "Cancelled", value: groupedIssues.cancelled.length, }, { name: "Completed", value: groupedIssues.completed.length, }, ]; const onPieEnter = useCallback( (_: any, index: number) => { setActiveIndex(index); }, [setActiveIndex] ); const renderActiveShape = ({ cx, cy, midAngle, innerRadius, outerRadius, startAngle, endAngle, fill, payload, value, }: any) => { const RADIAN = Math.PI / 180; const sin = Math.sin(-RADIAN * midAngle); const cos = Math.cos(-RADIAN * midAngle); const sx = cx + (outerRadius + 10) * cos; const sy = cy + (outerRadius + 10) * sin; const mx = cx + (outerRadius + 30) * cos; const my = cy + (outerRadius + 30) * sin; const ex = mx + (cos >= 0 ? 1 : -1) * 22; const ey = my; const textAnchor = cos >= 0 ? "start" : "end"; return ( {payload.name} = 0 ? 1 : -1) * 12} y={ey} textAnchor={textAnchor} fill="#333"> {value} issues ); }; return (

Issues by States

{data.map((cell: any) => ( ))}
); };