/** * ClassBreakdown — pie / donut chart + legend showing vehicle class split. */ import { PieChart, Pie, Cell, Tooltip, ResponsiveContainer, Legend } from 'recharts' const CLASS_COLORS = { car: '#3b82f6', bus: '#f59e0b', truck: '#10b981', motorcycle: '#ef4444', } const FALLBACK_COLORS = ['#8b5cf6', '#06b6d4', '#f97316', '#84cc16'] export default function ClassBreakdown({ latest }) { const raw = latest?.count_per_class ?? {} const data = Object.entries(raw).map(([name, value]) => ({ name, value })) const total = data.reduce((s, d) => s + d.value, 0) return (

Class Breakdown

{data.length === 0 ? (
No detections yet
) : (
{data.map((entry, i) => ( ))} [`${v} (${total ? ((v / total) * 100).toFixed(1) : 0}%)`, name]} /> {/* Legend */}
{data.map((entry, i) => (
{entry.name} {entry.value}
))}
)}
) }