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

113 lines
2.8 KiB
React
Raw Normal View History

2024-07-17 12:33:24 -07:00
import PropTypes from "prop-types";
import { AreaChart, Area, XAxis, Tooltip, ResponsiveContainer } from "recharts";
2024-08-27 12:18:25 -04:00
import { Box, Typography } from "@mui/material";
import { useTheme } from "@emotion/react";
2024-07-18 19:50:08 -04:00
import "./index.css";
2024-07-17 12:33:24 -07:00
const CustomToolTip = ({ active, payload, label }) => {
2024-08-27 12:18:25 -04:00
const theme = useTheme();
if (active && payload && payload.length) {
return (
2024-08-27 12:18:25 -04:00
<Box
className="area-tooltip"
sx={{
backgroundColor: theme.palette.background.main,
border: 1,
borderColor: theme.palette.border.dark,
borderRadius: theme.shape.borderRadius,
py: theme.spacing(6),
px: theme.spacing(8),
}}
>
<Typography
sx={{
color: theme.palette.primary.main,
2024-08-27 12:18:25 -04:00
fontSize: 13,
}}
>
{new Date(label).toLocaleDateString("en-US", {
weekday: "short", // Mon
month: "long", // July
day: "numeric", // 17
}) +
", " +
new Date(label).toLocaleTimeString("en-US", {
hour: "numeric", // 12
minute: "2-digit", // 15
hour12: true, // AM/PM format
})}
2024-08-27 12:18:25 -04:00
</Typography>
<Typography
mt={theme.spacing(2.5)}
sx={{
color: theme.palette.text.secondary,
fontSize: 13,
}}
>
Response Time (ms): {payload[0].payload.originalResponseTime}
</Typography>{" "}
{/* Display original value */}
2024-08-27 12:18:25 -04:00
</Box>
);
}
return null;
};
const MonitorDetailsAreaChart = ({ checks }) => {
2024-07-17 12:33:24 -07:00
const formatDate = (timestamp) => {
const date = new Date(timestamp);
return date.toLocaleTimeString("en-US", {
hour: "numeric",
minute: "2-digit",
hour12: true,
});
};
return (
<ResponsiveContainer width="100%" height="100%">
<AreaChart
width={500}
height={400}
2024-08-08 11:20:54 -07:00
data={checks}
2024-07-17 12:33:24 -07:00
margin={{
top: 10,
2024-07-18 19:50:08 -04:00
right: 0,
2024-07-17 12:33:24 -07:00
left: 0,
bottom: 0,
}}
>
<XAxis
dataKey="createdAt"
tickFormatter={formatDate}
tick={{ fontSize: "13px" }}
2024-07-18 19:50:08 -04:00
tickLine={false}
2024-07-17 12:33:24 -07:00
/>
<Tooltip content={<CustomToolTip />} />
2024-07-17 12:33:24 -07:00
<Area
type="monotone"
dataKey="responseTime"
stroke="#29afee"
fill="#eaf2fd"
/>
</AreaChart>
</ResponsiveContainer>
);
};
MonitorDetailsAreaChart.propTypes = {
checks: PropTypes.array,
};
CustomToolTip.propTypes = {
active: PropTypes.bool,
payload: PropTypes.arrayOf(
PropTypes.shape({
payload: PropTypes.shape({
originalResponseTime: PropTypes.number.isRequired,
}).isRequired,
})
),
label: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
2024-07-17 12:33:24 -07:00
};
export default MonitorDetailsAreaChart;