// Tiny SVG bar chart for daily traffic (download stacked over upload).
import type { DayUsage } from './types';
import { bytes } from './format';
export function trafficChart(series: DayUsage[], height = 120): string {
const w = 600;
const pad = 2;
const n = Math.max(series.length, 1);
const bw = w / n;
const max = Math.max(1, ...series.map((d) => d.rx + d.tx));
let bars = '';
series.forEach((d, i) => {
const x = i * bw + pad / 2;
// From the person's point of view: router tx = download, rx = upload.
const hDown = (d.tx / max) * (height - 4);
const hUp = (d.rx / max) * (height - 4);
const title = `${d.day}: ↓ ${bytes(d.tx)} · ↑ ${bytes(d.rx)}`;
bars +=
`${title}` +
`` +
`` +
``;
});
return ``;
}