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

109 lines
3.0 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 (
2024-08-23 13:41:06 -04:00
<Stack
direction="row"
flexWrap="nowrap"
gap="3px"
height="50px"
width="fit-content"
onClick={(event) => event.stopPropagation()}
sx={{
cursor: "default",
}}
>
2024-08-22 19:36:48 -04:00
{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: {
2024-08-23 13:41:06 -04:00
offset: [0, -10],
2024-08-22 20:15:49 -04:00
},
},
],
},
2024-08-22 19:36:48 -04:00
}}
>
<Box
2024-08-22 20:15:49 -04:00
position="relative"
2024-08-23 13:41:06 -04:00
width="9px"
2024-08-22 20:15:49 -04:00
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={{
2024-08-23 13:41:06 -04:00
borderRadius: "3px",
2024-08-22 19:36:48 -04:00
}}
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={{
2024-08-23 13:41:06 -04:00
borderRadius: "3px",
2024-08-22 20:15:49 -04:00
}}
/>
</Box>
</Tooltip>
2024-08-22 19:36:48 -04:00
))}
</Stack>
);
};
export default BarChart;