pagespeed

This commit is contained in:
Alex Holliday committed 2025-12-08 23:55:27 +00:00
1 parent e12e198aed
commit 3616b69925
3 files changed
+74 -24

No files matched your search

@@ -96,7 +96,7 @@ export function DataTable<
return ( return (
<Grid container key={header.id}> <Grid container key={header.id}>
<Grid size={3} display={"flex"} alignItems={"center"}> <Grid size={3} display={"flex"} alignItems={"center"}>
<Typography color={theme.palette.text.primary}> <Typography component="div" color={theme.palette.text.primary}>
{header.content} {header.content}
</Typography> </Typography>
</Grid> </Grid>
@@ -2,9 +2,12 @@ import { BaseChart } from "@/components/monitors/Chart";
import { FileText } from "lucide-react"; import { FileText } from "lucide-react";
import { Pie, PieChart, ResponsiveContainer, Label } from "recharts"; import { Pie, PieChart, ResponsiveContainer, Label } from "recharts";
import Typography from "@mui/material/Typography"; import Typography from "@mui/material/Typography";
import Box from "@mui/material/Box";
import { getPageSpeedPalette } from "@/utils/MonitorUtils"; import { getPageSpeedPalette } from "@/utils/MonitorUtils";
import { useTheme } from "@mui/material/styles"; import { useTheme } from "@mui/material/styles";
import { alpha } from "@mui/material/styles"; import { alpha } from "@mui/material/styles";
import { useState } from "react";
import Tooltip from "@mui/material/Tooltip";
const CenterLabel = ({ viewBox, value }: any) => { const CenterLabel = ({ viewBox, value }: any) => {
const { cx, cy } = viewBox; const { cx, cy } = viewBox;
@@ -19,6 +22,15 @@ const CenterLabel = ({ viewBox, value }: any) => {
export const ChartPageSpeedReport = ({ latestCheck }: { latestCheck: any }) => { export const ChartPageSpeedReport = ({ latestCheck }: { latestCheck: any }) => {
const theme = useTheme(); const theme = useTheme();
const [hoverTitle, setHoverTitle] = useState<string | null>(null);
const LABELS: Record<string, string> = {
FCP: "First Contentful Paint",
SI: "Speed Index",
LCP: "Largest Contentful Paint",
TBT: "Total Blocking Time",
CLS: "Cumulative Layout Shift",
};
const metrics = [ const metrics = [
{ key: "fcp", color: alpha("#1DE9B6", 0.6), weight: 0.1 }, { key: "fcp", color: alpha("#1DE9B6", 0.6), weight: 0.1 },
{ key: "si", color: alpha("#7C4DFF", 0.6), weight: 0.1 }, { key: "si", color: alpha("#7C4DFF", 0.6), weight: 0.1 },
@@ -60,33 +72,71 @@ export const ChartPageSpeedReport = ({ latestCheck }: { latestCheck: any }) => {
const score = [ const score = [
{ {
value: 100, value: 100,
fill: alpha( fill: alpha(theme.palette[pageSpeedPalette].light || "#ffffff", 0.6),
theme.palette[pageSpeedPalette].light || "#ffffff",
0.6
),
stroke: "none", stroke: "none",
}, },
]; ];
return ( return (
<BaseChart icon={<FileText size={20} strokeWidth={1.5} />} title="Average PageSpeed score"> <BaseChart
<ResponsiveContainer width="100%" height={250}> icon={<FileText size={20} strokeWidth={1.5} />}
<PieChart> title="Average PageSpeed score"
<Pie data={score} dataKey="value" cx="50%" cy="50%" outerRadius="65%"> >
<Label <Tooltip
position={"center"} open={Boolean(hoverTitle)}
content={<CenterLabel value={Math.floor(totalScore * 100)} />} title={hoverTitle || ""}
/> arrow
</Pie> followCursor
<Pie placement="top"
data={scores} >
innerRadius="70%" <Box
outerRadius="80%" sx={{
label={({ name, value }) => `${name}: ${Math.round(value)}`} "& .recharts-wrapper:focus, & .recharts-surface:focus": {
dataKey="value" outline: "none",
/> },
</PieChart> "& .recharts-wrapper *:focus": { outline: "none" },
</ResponsiveContainer> "& svg:focus, & g:focus, & path:focus": { outline: "none" },
position: "relative",
}}
>
<ResponsiveContainer width="100%" height={250}>
<PieChart>
<Pie
data={score}
dataKey="value"
cx="50%"
cy="50%"
outerRadius="65%"
>
<Label
position={"center"}
content={<CenterLabel value={Math.floor(totalScore * 100)} />}
/>
</Pie>
<Pie
data={scores}
innerRadius="70%"
outerRadius="80%"
label={({ name, value }) => `${name}: ${Math.round(value)}`}
dataKey="value"
stroke="none"
onMouseEnter={(_, index: number) => {
const d = scores[index];
if (!d) return;
const isInverse = String(d.name).includes("Inverse");
const pair =
isInverse && scores[index + 1] ? scores[index + 1] : d;
const base = String(pair.name).replace(" Inverse", "");
const full = LABELS[base] ?? base;
const displayVal = Math.round(Number(pair.value) || 0);
setHoverTitle(`${full}: ${displayVal}`);
}}
onMouseLeave={() => setHoverTitle(null)}
/>
</PieChart>
</ResponsiveContainer>
</Box>
</Tooltip>
</BaseChart> </BaseChart>
); );
}; };
@@ -24,7 +24,7 @@ export const HistogramPageSpeedScoresTooltip = ({
return ( return (
<Box <Box
sx={{ sx={{
backgroundColor: theme.palette.primary.main, backgroundColor: theme.palette.background.paper,
border: 1, border: 1,
borderColor: theme.palette.divider, borderColor: theme.palette.divider,
borderRadius: theme.shape.borderRadius, borderRadius: theme.shape.borderRadius,