import { useLingui } from "@lingui/react/macro" import { memo } from "react" import { Area, AreaChart, CartesianGrid, YAxis } from "recharts" import { ChartContainer, ChartTooltip, ChartTooltipContent, xAxis } from "@/components/ui/chart" import { Unit } from "@/lib/enums" import { chartMargin, cn, decimalString, formatBytes, formatShortDate, toFixedFloat } from "@/lib/utils" import type { ChartData } from "@/types" import { useYAxisWidth } from "./hooks" export default memo(function MemChart({ chartData, showMax }: { chartData: ChartData; showMax: boolean }) { const { yAxisWidth, updateYAxisWidth } = useYAxisWidth() const { t } = useLingui() const totalMem = toFixedFloat(chartData.systemStats.at(-1)?.stats.m ?? 0, 1) // console.log('rendered at', new Date()) if (chartData.systemStats.length === 0) { return null } return (
{/* {!yAxisSet && } */} {totalMem && ( { const { value: convertedValue, unit } = formatBytes(value * 1024, false, Unit.Bytes, true) return updateYAxisWidth(toFixedFloat(convertedValue, value >= 10 ? 0 : 1) + " " + unit) }} /> )} {xAxis(chartData)} a.order - b.order} labelFormatter={(_, data) => formatShortDate(data[0].payload.created)} contentFormatter={({ value }) => { // mem values are supplied as GB const { value: convertedValue, unit } = formatBytes(value * 1024, false, Unit.Bytes, true) return decimalString(convertedValue, convertedValue >= 100 ? 1 : 2) + " " + unit }} /> } /> (showMax ? stats?.mm : stats?.mu)} type="monotoneX" fill="var(--chart-2)" fillOpacity={0.4} stroke="var(--chart-2)" stackId="1" isAnimationActive={false} /> {/* {chartData.systemStats.at(-1)?.stats.mz && ( */} (showMax ? null : stats?.mz)} type="monotoneX" fill="hsla(175 60% 45% / 0.8)" fillOpacity={0.5} stroke="hsla(175 60% 45% / 0.8)" stackId="1" isAnimationActive={false} /> {/* )} */} (showMax ? null : stats?.mb)} type="monotoneX" fill="hsla(160 60% 45% / 0.5)" fillOpacity={0.4} stroke="hsla(160 60% 45% / 0.5)" stackId="1" isAnimationActive={false} /> {/* } /> */}
) })