-
Notifications
You must be signed in to change notification settings - Fork 5
/
UptimeChart.tsx
48 lines (43 loc) · 1.23 KB
/
UptimeChart.tsx
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
import { MantineTheme, useMantineTheme } from "@mantine/core"
import React from "react"
import { ResponsiveContainer, BarChart, Bar, Cell } from "recharts"
type UptimeChartProps = {
data: {
[key: string]: string | number
}[]
}
const getBarColor = ({
theme,
uptime,
}: {
theme: MantineTheme
uptime: number | string
}) => {
if (Number(uptime) >= 0.9) return theme.colors.green[5]
if (Number(uptime) >= 0.8) return theme.colors.yellow[7]
return theme.colors.red[9]
}
const UptimeChart = ({ data }: UptimeChartProps) => {
const theme = useMantineTheme()
return (
<ResponsiveContainer height="100%" width="100%">
<BarChart
barCategoryGap={2}
data={data}
margin={{ left: 16, right: 16, bottom: 10 }}
>
<Bar background={false} dataKey="maxUptime" minPointSize={10}>
{data.map(({ uptime }, index) => (
<Cell key={`cell-${index}`} fill={getBarColor({ theme, uptime })} />
))}
</Bar>
{/*<Tooltip*/}
{/* allowEscapeViewBox={{ x: true, y: true }}*/}
{/* cursor={{ fill: "transparent" }}*/}
{/* position={{ y: -75 }}*/}
{/*/>*/}
</BarChart>
</ResponsiveContainer>
)
}
export default UptimeChart