Files
Checkmate/Client/src/Components/Charts/BarChart/index.jsx
T

99 lines
2.9 KiB
React
Raw Normal View History

2024-08-22 19:36:48 -04:00
import { useTheme } from "@emotion/react";
2024-08-22 20:15:49 -04:00
import { Box, Stack, Tooltip, Typography } from "@mui/material";
import { formatDate } from "../../../Utils/timeUtils";
import "./index.css";
2024-08-22 19:36:48 -04:00
const BarChart = ({ checks = [] }) => {
const theme = useTheme();
return (
<Stack direction="row" flexWrap="nowrap" gap={theme.gap.xs} height="50px">
{checks.map((check) => (
2024-08-22 20:15:49 -04:00
<Tooltip
title={
<>
<Typography>
{formatDate(new Date(check.createdAt), { year: undefined })}
</Typography>
<Box mt={theme.gap.xs}>
<Box
display="inline-block"
width={theme.gap.small}
height={theme.gap.small}
backgroundColor={
check.status
? theme.label.up.dotColor
: theme.label.down.dotColor
}
sx={{ borderRadius: "50%" }}
/>
<Stack
display="inline-flex"
direction="row"
justifyContent="space-between"
ml={theme.gap.xs}
gap={theme.gap.large}
>
<Typography component="span" sx={{ opacity: 0.8 }}>
Response Time
</Typography>
<Typography component="span">
{check.originalResponseTime}
<Typography component="span" sx={{ opacity: 0.8 }}>
{" "}
ms
</Typography>
</Typography>
</Stack>
</Box>
</>
}
placement="top"
2024-08-22 19:36:48 -04:00
key={`check-${check?._id}`}
2024-08-22 20:15:49 -04:00
slotProps={{
popper: {
className: "bar-tooltip",
modifiers: [
{
name: "offset",
options: {
offset: [0, -12],
},
},
],
},
2024-08-22 19:36:48 -04:00
}}
>
<Box
2024-08-22 20:15:49 -04:00
position="relative"
width="8px"
height="100%"
2024-08-22 19:36:48 -04:00
backgroundColor={
2024-08-22 20:15:49 -04:00
check.status ? theme.label.up.bgColor : theme.label.down.bgColor
2024-08-22 19:36:48 -04:00
}
sx={{
borderRadius: theme.gap.xs,
}}
2024-08-22 20:15:49 -04:00
>
<Box
position="absolute"
bottom={0}
width="100%"
height={`${check.responseTime}%`}
backgroundColor={
check.status
? theme.label.up.dotColor
: theme.label.down.dotColor
}
sx={{
borderRadius: theme.gap.xs,
}}
/>
</Box>
</Tooltip>
2024-08-22 19:36:48 -04:00
))}
</Stack>
);
};
export default BarChart;