"use client"; import { useEffect, useId, useState } from "react"; import { Area, CartesianGrid, ComposedChart, Line, ResponsiveContainer, Tooltip, XAxis, YAxis, } from "recharts"; type Point = { distanceKm: number; altM: number; paceSec?: number }; type Props = { data: Point[]; syncId?: string; }; function fmtPace(sec: number): string { const m = Math.floor(sec / 60); const s = Math.round(sec % 60); return `${m}:${s.toString().padStart(2, "0")} /km`; } export function ElevationChart({ data, syncId }: Props) { const uid = useId(); const [mounted, setMounted] = useState(false); useEffect(() => setMounted(true), []); if (!mounted) { return
; } const altitudes = data.map((p) => p.altM); const minAlt = Math.min(...altitudes); const maxAlt = Math.max(...altitudes); const altPad = Math.max(5, Math.round((maxAlt - minAlt) * 0.15)); const pacePoints = data.map((p) => p.paceSec).filter((v): v is number => v != null && v > 0); const hasPace = pacePoints.length > 5; const minPace = hasPace ? Math.min(...pacePoints) : 0; const maxPace = hasPace ? Math.max(...pacePoints) : 0; const pacePad = Math.max(5, Math.round((maxPace - minPace) * 0.15)); const tooltipStyle = { background: "var(--color-bg)", border: "1px solid var(--color-muted)", borderRadius: 8, fontSize: 12, color: "var(--color-fg)", }; return (
Profil wysokości {hasPace && ( Tempo )}
`${Number(v).toFixed(1)} km`} interval={Math.max(0, Math.floor(data.length / 5) - 1)} /> `${Math.round(v)} m`} domain={[minAlt - altPad, maxAlt + altPad]} /> {hasPace && ( )} { if (name === "altM") return [`${Math.round(Number(value))} m n.p.m.`, "Wysokość"]; if (name === "paceSec") return [fmtPace(Number(value)), "Tempo"]; return [value, name]; }} labelFormatter={(l) => `${Number(l).toFixed(2)} km`} /> {hasPace && ( )}
); }