"use client"; import { useEffect, useState } from "react"; import { Bar, BarChart, Legend, ResponsiveContainer, Tooltip, XAxis, YAxis, } from "recharts"; type WorkoutDataPoint = { label: string; date: string; name: string; volumeKg: number; }; type Props = { data: WorkoutDataPoint[]; }; const COLORS: Record = {}; const PALETTE = ["var(--color-accent)", "#5b9bd5", "#70ad47", "#ffc000", "#ed7d31"]; function getColor(name: string): string { if (!COLORS[name]) { COLORS[name] = PALETTE[Object.keys(COLORS).length % PALETTE.length]; } return COLORS[name]; } export function VolumeTrendChart({ data }: Props) { const [mounted, setMounted] = useState(false); useEffect(() => setMounted(true), []); if (!mounted) { return (
); } const workoutNames = [...new Set(data.map((d) => d.name))]; const chartData: Record[] = []; const grouped = new Map>(); for (const point of data) { const key = point.date; if (!grouped.has(key)) { grouped.set(key, { label: point.label }); } const entry = grouped.get(key)!; entry[point.name] = ((entry[point.name] as number) || 0) + point.volumeKg; } for (const entry of grouped.values()) { chartData.push(entry); } return (
Trend wolumenu treningowego wg typu
[ `${Math.round(Number(value)).toLocaleString("pl-PL")} kg`, "Wolumen", ]} /> {workoutNames.map((name) => ( ))}
); }