import { Paper, Text } from "@mantine/core"; import { IconBrain } from "@tabler/icons-react"; import { formatBytesPair } from "@homarr/common"; import { useScopedI18n } from "@homarr/translation/client"; import type { LabelDisplayModeOption } from ".."; import { CommonChart } from "./common-chart"; export const SystemResourceMemoryChart = ({ memoryUsageOverTime, totalCapacityInBytes, hasShadow, labelDisplayMode, }: { memoryUsageOverTime: number[]; totalCapacityInBytes: number; hasShadow: boolean; labelDisplayMode: LabelDisplayModeOption; }) => { const chartData = memoryUsageOverTime.map((usage, index) => ({ index, usage })); const t = useScopedI18n("widget.systemResources.card"); const percentageUsed = memoryUsageOverTime.length > 0 && totalCapacityInBytes > 0 ? // eslint-disable-next-line @typescript-eslint/no-non-null-assertion memoryUsageOverTime[memoryUsageOverTime.length - 1]! / totalCapacityInBytes : undefined; return ( { const value = payload[0] ? Number(payload[0].value) : 0; const memory = formatBytesPair(Math.round(value), totalCapacityInBytes); return ( {memory.used} / {memory.available} ( {totalCapacityInBytes > 0 ? Math.round((value / totalCapacityInBytes) * 100) : 0}%) ); }, }} /> ); };