Switch to unified view

a b/client/src/components/PieChart.jsx
1
import { useEffect } from 'react';
2
import { PieChart, Pie, Cell } from 'recharts';
3
4
const COLORS = ['#FFBB28', '#0088FE', '#b2420a'];
5
6
function Chart(props) {
7
    const RADIAN = Math.PI / 180;
8
    const renderCustomizedLabel = ({ cx, cy, midAngle, innerRadius, outerRadius, percent, index }) => {
9
        const radius = innerRadius + (outerRadius - innerRadius) * 0.5;
10
        const x = cx + radius * Math.cos(-midAngle * RADIAN);
11
        const y = cy + radius * Math.sin(-midAngle * RADIAN);
12
      
13
        return (
14
          <text x={x} y={y} fill="white" textAnchor={x > cx ? 'start' : 'end'} dominantBaseline="central">
15
            {`${(percent * 100).toFixed(0)}%`}
16
          </text>
17
        );
18
      };
19
20
21
    return ( 
22
        <PieChart width={props.width} height={props.height}>
23
            <Pie
24
                data={props.data}
25
                dataKey="prob"
26
                outerRadius={props.outerRadius}
27
                label={props.label ? renderCustomizedLabel: null}
28
            >
29
                {
30
                    props.data.map((entry, index) => <Cell key={entry.name} fill={COLORS[index % COLORS.length]} />)
31
                }
32
            </Pie>
33
        </PieChart>
34
     );
35
}
36
37
export default Chart;
38
export { COLORS };