Added area chart
This commit is contained in:
1 parent
267ef14bb8
commit
78680d036c
3 files changed
+120
-5
No files matched your search
@@ -52,12 +52,35 @@ const useUtils = () => {
|
|||||||
"& h2": { color: theme.palette.warning.main },
|
"& h2": { color: theme.palette.warning.main },
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
const pagespeedStyles = {
|
||||||
|
up: {
|
||||||
|
bg: theme.palette.success.bg,
|
||||||
|
light: theme.palette.success.light,
|
||||||
|
stroke: theme.palette.success.main,
|
||||||
|
},
|
||||||
|
down: {
|
||||||
|
bg: theme.palette.error.bg,
|
||||||
|
light: theme.palette.error.light,
|
||||||
|
stroke: theme.palette.error.main,
|
||||||
|
},
|
||||||
|
paused: {
|
||||||
|
bg: theme.palette.warning.bg,
|
||||||
|
light: theme.palette.warning.light,
|
||||||
|
stroke: theme.palette.warning.main,
|
||||||
|
},
|
||||||
|
pending: {
|
||||||
|
bg: theme.palette.warning.bg,
|
||||||
|
light: theme.palette.warning.light,
|
||||||
|
stroke: theme.palette.warning.main,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
determineState,
|
determineState,
|
||||||
statusColor,
|
statusColor,
|
||||||
statusMsg,
|
statusMsg,
|
||||||
pagespeedStatusMsg,
|
pagespeedStatusMsg,
|
||||||
|
pagespeedStyles,
|
||||||
statusStyles,
|
statusStyles,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,19 +1,103 @@
|
|||||||
import PageSpeedIcon from "../../assets/icons/page-speed.svg?react";
|
import PageSpeedIcon from "../../assets/icons/page-speed.svg?react";
|
||||||
import { StatusLabel } from "../../Components/Label";
|
import { StatusLabel } from "../../Components/Label";
|
||||||
import { Box, Grid, Stack, Typography } from "@mui/material";
|
import { Box, Grid, Typography } from "@mui/material";
|
||||||
import { useNavigate } from "react-router";
|
import { useNavigate } from "react-router";
|
||||||
import { useTheme } from "@emotion/react";
|
import { useTheme } from "@emotion/react";
|
||||||
import { formatDate, formatDurationRounded } from "../../Utils/timeUtils";
|
import { IconBox } from "./Details/styled";
|
||||||
import { getLastChecked } from "../../Utils/monitorUtils";
|
|
||||||
import useUtils from "../Monitors/utils";
|
import useUtils from "../Monitors/utils";
|
||||||
import PropTypes from "prop-types";
|
import PropTypes from "prop-types";
|
||||||
import { IconBox } from "./Details/styled";
|
import { Area, AreaChart, CartesianGrid, ResponsiveContainer } from "recharts";
|
||||||
|
|
||||||
|
const processData = (data) => {
|
||||||
|
if (data.length === 0) return [];
|
||||||
|
let formattedData = [];
|
||||||
|
|
||||||
|
const calculateScore = (entry) => {
|
||||||
|
return (
|
||||||
|
(entry.accessibility +
|
||||||
|
entry.bestPractices +
|
||||||
|
entry.performance +
|
||||||
|
entry.seo) /
|
||||||
|
4
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
data.forEach((entry) => {
|
||||||
|
entry = { ...entry, score: calculateScore(entry) };
|
||||||
|
formattedData.push(entry);
|
||||||
|
});
|
||||||
|
|
||||||
|
return formattedData;
|
||||||
|
};
|
||||||
|
|
||||||
|
const PagespeedAreaChart = ({ data, status }) => {
|
||||||
|
const theme = useTheme();
|
||||||
|
const { pagespeedStyles } = useUtils();
|
||||||
|
|
||||||
|
const formattedData = processData(data);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ResponsiveContainer width="100%" minWidth={25} height={100}>
|
||||||
|
<AreaChart
|
||||||
|
width="100%"
|
||||||
|
height="100%"
|
||||||
|
data={formattedData}
|
||||||
|
margin={{ top: 10, bottom: -5 }}
|
||||||
|
style={{ cursor: "pointer" }}
|
||||||
|
>
|
||||||
|
<CartesianGrid
|
||||||
|
stroke={theme.palette.border.light}
|
||||||
|
strokeWidth={1}
|
||||||
|
strokeOpacity={1}
|
||||||
|
fill="transparent"
|
||||||
|
vertical={false}
|
||||||
|
/>
|
||||||
|
{/* <Tooltip
|
||||||
|
cursor={{ stroke: theme.palette.border.light }}
|
||||||
|
content={<CustomToolTip config={filteredConfig} />}
|
||||||
|
/> */}
|
||||||
|
<defs>
|
||||||
|
<linearGradient
|
||||||
|
id={`pagespeed-chart-${status}`}
|
||||||
|
x1="0"
|
||||||
|
y1="0"
|
||||||
|
x2="0"
|
||||||
|
y2="1"
|
||||||
|
>
|
||||||
|
<stop
|
||||||
|
offset="0%"
|
||||||
|
stopColor={pagespeedStyles[status].stroke}
|
||||||
|
stopOpacity={0.8}
|
||||||
|
/>
|
||||||
|
<stop
|
||||||
|
offset="100%"
|
||||||
|
stopColor={pagespeedStyles[status].light}
|
||||||
|
stopOpacity={0}
|
||||||
|
/>
|
||||||
|
</linearGradient>
|
||||||
|
</defs>
|
||||||
|
<Area
|
||||||
|
dataKey="score"
|
||||||
|
stroke={pagespeedStyles[status].stroke}
|
||||||
|
strokeWidth={1.5}
|
||||||
|
fill={`url(#pagespeed-chart-${status})`}
|
||||||
|
activeDot={{
|
||||||
|
stroke: pagespeedStyles[status].stroke,
|
||||||
|
fill: pagespeedStyles[status].stroke,
|
||||||
|
r: 4.5,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</AreaChart>
|
||||||
|
</ResponsiveContainer>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
const Card = ({ monitor }) => {
|
const Card = ({ monitor }) => {
|
||||||
const { determineState, pagespeedStatusMsg } = useUtils();
|
const { determineState, pagespeedStatusMsg } = useUtils();
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const monitorState = determineState(monitor);
|
const monitorState = determineState(monitor);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Grid item lg={6} flexGrow={1}>
|
<Grid item lg={6} flexGrow={1}>
|
||||||
<Box
|
<Box
|
||||||
@@ -57,6 +141,14 @@ const Card = ({ monitor }) => {
|
|||||||
>
|
>
|
||||||
{monitor.url}
|
{monitor.url}
|
||||||
</Typography>
|
</Typography>
|
||||||
|
<Box
|
||||||
|
mx={theme.spacing(-8)}
|
||||||
|
mt={theme.spacing(4)}
|
||||||
|
mb={theme.spacing(-8)}
|
||||||
|
sx={{ gridColumnStart: 1, gridColumnEnd: 4 }}
|
||||||
|
>
|
||||||
|
<PagespeedAreaChart data={monitor.checks} status={monitorState} />
|
||||||
|
</Box>
|
||||||
</Box>
|
</Box>
|
||||||
</Grid>
|
</Grid>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -56,7 +56,6 @@ const PageSpeed = ({ isAdmin }) => {
|
|||||||
// will show skeletons only on initial load
|
// will show skeletons only on initial load
|
||||||
// since monitor state is being added to redux persist, there's no reason to display skeletons on every render
|
// since monitor state is being added to redux persist, there's no reason to display skeletons on every render
|
||||||
let isActuallyLoading = isLoading && monitors?.length === 0;
|
let isActuallyLoading = isLoading && monitors?.length === 0;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box
|
<Box
|
||||||
className="page-speed"
|
className="page-speed"
|
||||||
@@ -89,6 +88,7 @@ const PageSpeed = ({ isAdmin }) => {
|
|||||||
variant="contained"
|
variant="contained"
|
||||||
color="primary"
|
color="primary"
|
||||||
onClick={() => navigate("/pagespeed/create")}
|
onClick={() => navigate("/pagespeed/create")}
|
||||||
|
sx={{ whiteSpace: "nowrap" }}
|
||||||
>
|
>
|
||||||
Create new
|
Create new
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
Reference in new issue
Block a user