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

86 lines
2.1 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-07-18 19:50:08 -04:00
import "./index.css";
2024-07-17 12:33:24 -07:00
const CustomToolTip = ({ active, payload, label }) => {
if (active && payload && payload.length) {
return (
2024-07-18 19:50:08 -04:00
<div className="area-tooltip">
<p>
{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
})}
</p>
<p>Response Time (ms): {payload[0].payload.originalResponseTime}</p>{" "}
{/* Display original value */}
</div>
);
}
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;