Fixed area chart tooltip

This commit is contained in:
Daniel Cojocea committed 2024-09-04 21:41:16 -04:00
1 parent 7e01006cef
commit f689b304c8
3 files changed
+53 -20

No files matched your search

@@ -1,6 +1,6 @@
import PropTypes from "prop-types"; import PropTypes from "prop-types";
import { AreaChart, Area, XAxis, Tooltip, ResponsiveContainer } from "recharts"; import { AreaChart, Area, XAxis, Tooltip, ResponsiveContainer } from "recharts";
import { Box, Typography } from "@mui/material"; import { Box, Stack, Typography } from "@mui/material";
import { useTheme } from "@emotion/react"; import { useTheme } from "@emotion/react";
import "./index.css"; import "./index.css";
@@ -16,14 +16,15 @@ const CustomToolTip = ({ active, payload, label }) => {
border: 1, border: 1,
borderColor: theme.palette.border.dark, borderColor: theme.palette.border.dark,
borderRadius: theme.shape.borderRadius, borderRadius: theme.shape.borderRadius,
py: theme.spacing(6), py: theme.spacing(2),
px: theme.spacing(8), px: theme.spacing(4),
}} }}
> >
<Typography <Typography
sx={{ sx={{
color: theme.palette.primary.main, color: theme.palette.text.tertiary,
fontSize: 13, fontSize: 12,
fontWeight: 500,
}} }}
> >
{new Date(label).toLocaleDateString("en-US", { {new Date(label).toLocaleDateString("en-US", {
@@ -38,15 +39,39 @@ const CustomToolTip = ({ active, payload, label }) => {
hour12: true, // AM/PM format hour12: true, // AM/PM format
})} })}
</Typography> </Typography>
<Typography <Box mt={theme.spacing(1)}>
mt={theme.spacing(2.5)} <Box
sx={{ display="inline-block"
color: theme.palette.text.secondary, width={theme.spacing(4)}
fontSize: 13, height={theme.spacing(4)}
}} backgroundColor={theme.palette.primary.main}
> sx={{ borderRadius: "50%" }}
Response Time (ms): {payload[0].payload.originalResponseTime} />
</Typography>{" "} <Stack
display="inline-flex"
direction="row"
justifyContent="space-between"
ml={theme.spacing(3)}
sx={{
"& span": {
color: theme.palette.text.tertiary,
fontSize: 11,
fontWeight: 500,
},
}}
>
<Typography component="span" sx={{ opacity: 0.8 }}>
Response Time
</Typography>{" "}
<Typography component="span">
{payload[0].payload.originalResponseTime}
<Typography component="span" sx={{ opacity: 0.8 }}>
{" "}
ms
</Typography>
</Typography>
</Stack>
</Box>
{/* Display original value */} {/* Display original value */}
</Box> </Box>
); );
@@ -67,10 +92,10 @@ const MonitorDetailsAreaChart = ({ checks }) => {
const theme = useTheme(); const theme = useTheme();
return ( return (
<ResponsiveContainer width="100%" height="100%"> <ResponsiveContainer width="100%" height={220}>
<AreaChart <AreaChart
width={500} width="100%"
height={400} height="100%"
data={checks} data={checks}
margin={{ margin={{
top: 10, top: 10,
@@ -94,10 +119,12 @@ const MonitorDetailsAreaChart = ({ checks }) => {
</linearGradient> </linearGradient>
</defs> </defs>
<XAxis <XAxis
stroke={theme.palette.border.dark}
dataKey="createdAt" dataKey="createdAt"
tickFormatter={formatDate} tickFormatter={formatDate}
tick={{ fontSize: "13px" }} tick={{ fontSize: "13px" }}
tickLine={false} tickLine={false}
height={18}
/> />
<Tooltip content={<CustomToolTip />} /> <Tooltip content={<CustomToolTip />} />
<Area <Area
+7 -1
View File
@@ -474,7 +474,13 @@ const DetailsPage = ({ isAdmin }) => {
data={[{ response: monitor?.periodAvgResponseTime }]} data={[{ response: monitor?.periodAvgResponseTime }]}
/> />
</ChartBox> </ChartBox>
<ChartBox> <ChartBox
sx={{
"& tspan": {
fontSize: 11,
},
}}
>
<Stack> <Stack>
<IconBox> <IconBox>
<ResponseTimeIcon /> <ResponseTimeIcon />
+2 -2
View File
@@ -16,11 +16,11 @@ export const ChartBox = styled(Stack)(({ theme }) => ({
fontSize: 15, fontSize: 15,
fontWeight: 500, fontWeight: 500,
}, },
"& p": { "& .MuiBox-root:not(.area-tooltip) p": {
color: theme.palette.text.tertiary, color: theme.palette.text.tertiary,
fontSize: 13, fontSize: 13,
}, },
"& span": { "& .MuiBox-root > span": {
color: theme.palette.text.primary, color: theme.palette.text.primary,
fontSize: 20, fontSize: 20,
"& span": { "& span": {