import { FC, useState } from 'react'; import { Pie } from '@visx/shape'; import { Group } from '@visx/group'; import { Text } from '@visx/text'; export type PieChartDataRecord = { symbol: string, amount: number, color: string }; export interface PieChartProps { data: PieChartDataRecord[]; width: number; height: number; total: number; label: string; } export const PieChart: FC = ({ data, width, height, total, label }) => { const half = width / 2; const [active, setActive] = useState(null); return ( data.amount} outerRadius={half} innerRadius={({ data }) => (active && (active.symbol === data.symbol) ? half - 14 : half - 8)} padAngle={0.01} > {pie => { return pie.arcs.map(arc => { return ( setActive(arc.data)} onMouseLeave={() => setActive(null)} > ) }) }} {active ? active.amount : total} {label} ); };