forked from MergeFi/frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBarChart.tsx
More file actions
36 lines (34 loc) · 1.09 KB
/
Copy pathBarChart.tsx
File metadata and controls
36 lines (34 loc) · 1.09 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
export interface BarChartPoint {
label: string;
value: number;
}
export function BarChart({
data,
height = 160,
formatValue,
}: {
data: BarChartPoint[];
height?: number;
formatValue?: (v: number) => string;
}) {
const max = Math.max(...data.map((d) => d.value), 1);
return (
<div className="flex gap-2" style={{ height }}>
{data.map((d) => {
const pct = Math.max((d.value / max) * 100, 2);
return (
<div key={d.label} className="group flex flex-1 flex-col items-center gap-2">
<div className="relative flex w-full flex-1 items-end justify-center">
<div
className="w-full max-w-8 rounded-t-md bg-indigo-500/80 transition-colors group-hover:bg-indigo-500 dark:bg-indigo-400/70 dark:group-hover:bg-indigo-400"
style={{ height: `${pct}%` }}
title={formatValue ? formatValue(d.value) : String(d.value)}
/>
</div>
<span className="text-[11px] text-slate-400 dark:text-slate-500">{d.label}</span>
</div>
);
})}
</div>
);
}