forked from Cylo-Traders/Agrocylo-PIP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFundingOutcomeChart.tsx
More file actions
51 lines (49 loc) · 1.39 KB
/
Copy pathFundingOutcomeChart.tsx
File metadata and controls
51 lines (49 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import {
Cell,
Legend,
Pie,
PieChart,
ResponsiveContainer,
Tooltip,
} from 'recharts';
import type { FundingOutcomeSlice } from '../../lib/analytics/metrics';
import { OUTCOME_COLORS } from '../../lib/analytics/theme';
import { EmptyChartState } from './ChartCard';
export function FundingOutcomeChart({ data }: { data: FundingOutcomeSlice[] }) {
const total = data.reduce((sum, slice) => sum + slice.value, 0);
if (total === 0) {
return <EmptyChartState message="No campaigns recorded yet." />;
}
return (
<ResponsiveContainer width="100%" height={280}>
<PieChart>
<Pie
data={data}
dataKey="value"
nameKey="label"
innerRadius={60}
outerRadius={95}
paddingAngle={2}
>
{data.map((entry, index) => (
<Cell
key={entry.label}
fill={OUTCOME_COLORS[index % OUTCOME_COLORS.length]}
/>
))}
</Pie>
<Tooltip
formatter={(value, name) => {
const numeric = Number(value ?? 0);
return [
`${numeric} (${((numeric / total) * 100).toFixed(0)}%)`,
name,
];
}}
contentStyle={{ borderRadius: 8, borderColor: '#e0cfb0' }}
/>
<Legend wrapperStyle={{ fontSize: 12, color: '#7d5e34' }} />
</PieChart>
</ResponsiveContainer>
);
}