/** * Traffic Chart — Recharts line chart for bandwidth over time * Ball Studios */ import React from 'react'; import { LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, Legend, ResponsiveContainer, } from 'recharts'; interface DataPoint { rx_bytes: number; tx_bytes: number; recorded_at: string; } interface Props { data: DataPoint[]; } function formatTick(bytes: number): string { if (bytes < 1024) return `${bytes}B`; if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(0)}K`; return `${(bytes / 1024 / 1024).toFixed(1)}M`; } export default function TrafficChart({ data }: Props) { if (data.length === 0) { return
No historical data available yet.
; } const chartData = data.map(d => ({ time: new Date(d.recorded_at).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' }), rx: d.rx_bytes, tx: d.tx_bytes, })); return ( [ `${(v / 1024 / 1024).toFixed(2)} MB`, name === 'rx' ? '⬇ Inbound' : '⬆ Outbound', ]} /> v === 'rx' ? '⬇ Inbound' : '⬆ Outbound'} /> ); }