import * as React from 'react'; import { Area, AreaChart, XAxis } from 'recharts'; import { Card, CardContent } from '@/components/ui/card'; import { ChartConfig, ChartContainer, ChartTooltip, ChartTooltipContent } from '@/components/ui/chart'; import { Metric } from '@/types/metric'; import { Button } from '@/components/ui/button'; import { Formatter } from 'recharts/types/component/DefaultTooltipContent'; interface Props { title: string; color: string; dataKey: 'load' | 'memory_used' | 'disk_used'; label: string; chartData: Metric[]; formatter?: Formatter; } export function ResourceUsageChart({ title, color, dataKey, label, chartData, formatter }: Props) { const chartConfig = { [dataKey]: { label: label, color: color, }, } satisfies ChartConfig; const getCurrentValue = () => { if (chartData.length === 0) return 'N/A'; const value = chartData[chartData.length - 1][dataKey]; if (formatter) { return formatter(value, dataKey); } return typeof value === 'number' ? value.toLocaleString() : String(value); }; return (

{title}

{getCurrentValue()}
{ const date = new Date(value); return date.toLocaleDateString('en-US', { hour: '2-digit', minute: '2-digit', month: 'short', day: 'numeric', }); }} /> { return new Date(value).toLocaleDateString('en-US', { hour: '2-digit', minute: '2-digit', month: 'short', day: 'numeric', }); }} formatter={formatter} indicator="dot" /> } />
); }