import { useMemo } from "react"; import type { SystemLoadChartPoint } from "@/lib/systemLoadChartView"; const polylinePoints = (points: SystemLoadChartPoint[], key: "cpu" | "ram") => { const denominator = Math.max(1, points.length - 1); return points.flatMap((point, index) => { const value = point[key]; return typeof value === "number" ? [`${(index / denominator) * 100},${100 - Math.max(0, Math.min(value, 100))}`] : []; }).join(" "); }; export const SystemLoadSvgChart = ({ points }: { points: SystemLoadChartPoint[] }) => { const cpu = useMemo(() => polylinePoints(points, "cpu"), [points]); const ram = useMemo(() => polylinePoints(points, "ram"), [points]); const firstTime = points[0]?.time ?? ""; const lastTime = points.at(-1)?.time ?? ""; return (
Live CPU- en RAM-belasting in procenten CPU is blauw en RAM is groen. De verticale schaal loopt van nul tot honderd procent. {[0, 25, 50, 75, 100].map(value => ( ))} {cpu ? : null} {ram ? : null}
{firstTime} CPURAM {lastTime}
); };