import { TrendData } from '../types' export function TrendChart({ data }: { data: TrendData }) { if (!data || data.dates.length === 0) { return (
Keine Trend-Daten verfuegbar
) } const maxScore = Math.max(...data.scores, 5) const minScore = Math.min(...data.scores, 0) const range = maxScore - minScore || 1 return (
{/* Y-Axis Labels */}
{maxScore.toFixed(1)} {((maxScore + minScore) / 2).toFixed(1)} {minScore.toFixed(1)}
{/* Chart Area */}
{/* Grid Lines */} {/* Line Chart */} { const x = (i / (data.scores.length - 1 || 1)) * 100 const y = 100 - ((score - minScore) / range) * 100 return `${x},${y}` }) .join(' ')} /> {/* Data Points */} {data.scores.map((score, i) => { const x = (i / (data.scores.length - 1 || 1)) * 100 const y = 100 - ((score - minScore) / range) * 100 return })}
{/* X-Axis Labels */}
{data.dates.slice(0, 5).map((date, i) => ( {new Date(date).toLocaleDateString('de-DE', { day: '2-digit', month: '2-digit' })} ))}
{/* Trend Indicator */}
{data.trend === 'improving' ? 'Verbessernd' : data.trend === 'declining' ? 'Verschlechternd' : 'Stabil'}
) }