import { Area, AreaChart, CartesianGrid, YAxis } from "recharts" import { ChartContainer, ChartTooltip, ChartTooltipContent, xAxis } from "@/components/ui/chart" import { useYAxisWidth, cn, decimalString, formatShortDate, chartMargin, formatBytes, toFixedFloat } from "@/lib/utils" import { memo } from "react" import { ChartData } from "@/types" import { useLingui } from "@lingui/react/macro" import { Unit } from "@/lib/enums" export default memo(function MemChart({ chartData }: { chartData: ChartData }) { 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 }} /> } /> {chartData.systemStats.at(-1)?.stats.mz && ( )}
) })