"use client"; import { motion } from "framer-motion"; import { complexityCurves, curvePoints } from "@/lib/complexity"; import { ComplexityClass } from "@/lib/types"; interface GrowthChartProps { active: ComplexityClass; n: number; maxN: number; labels: Record; } const CURVES: { key: ComplexityClass; color: string }[] = [ { key: "n+k", color: "hsl(var(--state-sorted))" }, { key: "nlogn", color: "hsl(var(--primary))" }, { key: "n2-adaptive", color: "hsl(var(--state-pivot))" }, { key: "n2", color: "hsl(var(--state-swap))" }, ]; const W = 320; const H = 160; const PAD = 10; function toPath(points: { n: number; v: number }[], maxN: number) { return points .map((p, i) => { const x = PAD + (p.n / maxN) * (W - 2 * PAD); const y = H - PAD - p.v * (H - 2 * PAD); return `${i === 0 ? "M" : "L"} ${x.toFixed(1)} ${y.toFixed(1)}`; }) .join(" "); } export default function GrowthChart({ active, n, maxN, labels }: GrowthChartProps) { return (
{/* axes */} {CURVES.map(({ key, color }) => { const pts = curvePoints(complexityCurves[key], maxN); const isActive = key === active; return ( ); })} {/* marker at current n on the active curve */} {(() => { const pts = curvePoints(complexityCurves[active], maxN, 200); const closest = pts.reduce((a, b) => (Math.abs(b.n - n) < Math.abs(a.n - n) ? b : a)); const x = PAD + (closest.n / maxN) * (W - 2 * PAD); const y = H - PAD - closest.v * (H - 2 * PAD); const color = CURVES.find((c) => c.key === active)?.color ?? "hsl(var(--primary))"; return ( ); })()}
{CURVES.map(({ key, color }) => (
{labels[key]}
))}
); }