import React from "react"; /** Compact trend line — SVG polyline, no axes. role="img" with a spoken summary. */ export function Sparkline({ data = [], width = 160, height = 44, tone = "primary", showArea = true, unit = "", label, style }) { const nums = data.map((d) => (typeof d === "number" ? d : d.value)); if (!nums.length) return null; const min = Math.min(...nums), max = Math.max(...nums); const span = max - min || 1; const step = nums.length > 1 ? width / (nums.length - 1) : width; const pad = 3; const pts = nums.map((v, i) => [i * step, pad + (1 - (v - min) / span) * (height - pad * 2)]); const line = pts.map((p, i) => (i ? "L" : "M") + p[0].toFixed(1) + " " + p[1].toFixed(1)).join(" "); const area = line + " L" + width + " " + height + " L0 " + height + " Z"; const stroke = tone === "primary" ? "hsl(var(--primary))" : "hsl(var(--state-" + tone + "-icon))"; const first = nums[0], last = nums[nums.length - 1]; const summary = (label ? label + ". " : "") + nums.length + "개 구간 추이, " + first + unit + "에서 " + last + unit + "로 " + (last - first >= 0 ? "상승" : "하락"); return ( {showArea && } ); }