'use client' import React from 'react' interface ChartDataPoint { value: number label?: string timestamp?: string } interface AreaChartProps { className?: string data?: ChartDataPoint[] } const AreaChart: React.FC = ({ className = '', data }) => { const width = 635 const height = 200 const paddingBottom = 20 const baselineY = height - paddingBottom const maxPlotHeight = height - 40 const safeData = (Array.isArray(data) && data.length > 0) ? data : [ { value: 5 }, { value: 3 }, { value: 7 }, { value: 2 }, { value: 6 }, { value: 4 }, { value: 8 } ] const maxVal = Math.max(...safeData.map(d => d.value || 0), 1) const stepX = safeData.length > 1 ? width / (safeData.length - 1) : width const points = safeData.map((d, i) => { const x = i * stepX const y = baselineY - (Math.min(d.value || 0, maxVal) / maxVal) * maxPlotHeight return { x, y } }) const linePath = points.map((p, i) => `${i === 0 ? 'M' : 'L'}${p.x},${p.y}`).join(' ') const areaPath = `${linePath} L${width},${baselineY} L0,${baselineY} Z` return (
{points.map((p, i) => ( ))}
) } export default AreaChart