"use client"; import type { ComponentRenderProps } from "./types"; import { baseClass, getCustomClass } from "./utils"; interface DataPoint { label: string; value: number; } export function LineGraph({ element }: ComponentRenderProps) { const { props } = element; const customClass = getCustomClass(props); const data = (props.data as DataPoint[]) || []; const title = props.title as string | undefined; const maxValue = Math.max(...data.map((d) => d.value)); const minValue = Math.min(...data.map((d) => d.value)); const range = maxValue - minValue || 1; // SVG dimensions with padding const width = 300; const height = 100; const padding = { top: 10, right: 10, bottom: 10, left: 10 }; const chartWidth = width - padding.left - padding.right; const chartHeight = height - padding.top - padding.bottom; // Calculate points for the SVG path const points = data.map((d, i) => { const x = padding.left + (data.length > 1 ? (i / (data.length - 1)) * chartWidth : chartWidth / 2); const y = padding.top + chartHeight - ((d.value - minValue) / range) * chartHeight; return { x, y, ...d }; }); const pathD = points.length > 0 ? `M ${points.map((p) => `${p.x} ${p.y}`).join(" L ")}` : ""; return (