'use client'
import {
BarChart,
Bar,
XAxis,
YAxis,
Tooltip,
Legend,
ReferenceLine,
ResponsiveContainer,
} from 'recharts'
import type { VelocityData } from '@/lib/insights/velocity'
import { SERIES_COLORS } from '@/lib/chart-colors'
interface Props {
data: VelocityData
}
export function VelocityChart({ data }: Props) {
const { sprints, productNames } = data
if (sprints.length < 2) {
return (
Velocity
Velocity wordt zichtbaar na 2+ voltooide sprints (nu: {sprints.length}).
)
}
// Reshape: [{ sprintLabel, [productName1]: count, [productName2]: count, ... }]
type Row = { sprintLabel: string } & Record
const grouped = new Map()
for (const s of sprints) {
const key = `${s.sprintId}`
if (!grouped.has(key)) {
grouped.set(key, { sprintLabel: s.sprintCode })
}
grouped.get(key)![s.productName] = s.doneCount
}
const rows = Array.from(grouped.values())
// Average across all bars (used for ReferenceLine)
const allCounts = sprints.map(s => s.doneCount)
const avg = allCounts.length > 0 ? allCounts.reduce((a, b) => a + b, 0) / allCounts.length : 0
return (
Velocity (laatste {sprints.length} sprints)
{productNames.map((p, i) => (
))}
{avg > 0 && (
)}
)
}