From 98fcce46478d89e3cf324278880af8715e5726bd Mon Sep 17 00:00:00 2001 From: Usman Baig Date: Mon, 23 Mar 2026 10:54:09 +0100 Subject: [PATCH] feat(pagespeed): switch trend chart from Recharts to visx for dashboard consistency --- app/sites/[id]/pagespeed/page.tsx | 103 ++++++++++-------------------- 1 file changed, 35 insertions(+), 68 deletions(-) diff --git a/app/sites/[id]/pagespeed/page.tsx b/app/sites/[id]/pagespeed/page.tsx index 5463f20..3a22b43 100644 --- a/app/sites/[id]/pagespeed/page.tsx +++ b/app/sites/[id]/pagespeed/page.tsx @@ -8,20 +8,7 @@ import { updatePageSpeedConfig, triggerPageSpeedCheck, getPageSpeedLatest, type import { toast, Button } from '@ciphera-net/ui' import { motion } from 'framer-motion' import ScoreGauge from '@/components/pagespeed/ScoreGauge' -import { - AreaChart, - Area, - XAxis, - YAxis, - CartesianGrid, - ReferenceLine, -} from 'recharts' -import { ChartContainer, ChartTooltip, ChartTooltipContent, type ChartConfig } from '@/components/charts' - -// * Chart configuration for score trend -const chartConfig = { - score: { label: 'Performance', color: 'var(--chart-1)' }, -} satisfies ChartConfig +import { AreaChart as VisxAreaChart, Area as VisxArea, Grid as VisxGrid, XAxis as VisxXAxis, YAxis as VisxYAxis, ChartTooltip as VisxChartTooltip } from '@/components/ui/area-chart' // * Metric status thresholds (Google's Core Web Vitals thresholds) function getMetricStatus(metric: string, value: number | null): { label: string; color: string } { @@ -225,14 +212,11 @@ export default function PageSpeedPage() { ) } - // * Prepare chart data from history + // * Prepare chart data from history (visx needs Date objects for x-axis) const chartData = (historyChecks ?? []).map(c => ({ - date: new Date(c.checked_at).toLocaleDateString('en-GB', { day: '2-digit', month: 'short' }), - score: c.performance_score, + dateObj: new Date(c.checked_at), + score: c.performance_score ?? 0, })) - // * Check if all chart labels are the same (single day of data) - const uniqueDates = new Set(chartData.map(d => d.date)) - const hideXAxis = uniqueDates.size <= 1 // * Parse audits into groups by Lighthouse category const audits = currentCheck?.audits ?? [] @@ -446,62 +430,45 @@ export default function PageSpeedPage() { - {/* Section 3 — Score Trend Chart */} + {/* Section 3 — Score Trend Chart (visx) */} {chartData.length >= 2 && (

Performance Score Trend

- - - - - - - - - - - - - - {value}} - /> - } - /> - + []} + xDataKey="dateObj" + aspectRatio="3 / 1" + margin={{ top: 10, right: 10, bottom: 30, left: 40 }} + > + + - - + d.toLocaleDateString('en-GB', { day: 'numeric', month: 'short' })} + /> + String(Math.round(v))} + /> + ) => [{ + label: 'Score', + value: String(Math.round(point.score as number)), + color: 'var(--chart-line-primary)', + }]} + /> + +
)}