diff --git a/client/src/Components/monitors/charts/HistogramDetailsStacked.tsx b/client/src/Components/monitors/charts/HistogramDetailsStacked.tsx index a47af1a0d..81ca5a103 100644 --- a/client/src/Components/monitors/charts/HistogramDetailsStacked.tsx +++ b/client/src/Components/monitors/charts/HistogramDetailsStacked.tsx @@ -1,8 +1,18 @@ import type { GroupedUptimeCheck } from "@/Types/Check"; -import { Area, AreaChart, CartesianGrid, ResponsiveContainer } from "recharts"; +import { Area, AreaChart, CartesianGrid, ResponsiveContainer, YAxis } from "recharts"; +import { useMemo } from "react"; import { useTheme } from "@mui/material"; +const PHASE_KEYS = [ + "avgDns", + "avgTcp", + "avgTls", + "avgRequest", + "avgFirstByte", + "avgDownload", +] as const; + export const HistogramDetailsStacked = ({ checks = [], range, @@ -12,6 +22,17 @@ export const HistogramDetailsStacked = ({ }) => { const theme = useTheme(); + // Cap the y-domain at the p95 of bucket totals so a single timeout bucket + // doesn't flatten every other bucket; spikes clip off the top instead. + const yMax = useMemo(() => { + const totals = checks + .map((check) => PHASE_KEYS.reduce((sum, key) => sum + check[key], 0)) + .sort((a, b) => a - b); + if (totals.length < 2) return undefined; + const p95 = totals[Math.min(totals.length - 1, Math.floor(totals.length * 0.95))]; + return p95 > 0 ? Math.ceil(p95) : undefined; + }, [checks]); + console.log(JSON.stringify(checks, null, 2)); return ( @@ -27,11 +48,54 @@ export const HistogramDetailsStacked = ({ fill="transparent" vertical={false} /> + + + + + + + +