import { ReactNode } from 'react'; const PALETTE = ['#2f5bea', '#e0702b', '#1b9e77', '#a14b9c', '#c9a227', '#d6336c', '#37a0d6']; const W = 640, H = 240, M = { l: 44, r: 12, t: 12, b: 32 }; const ts = (d: string) => new Date(d + 'T00:00:00Z').getTime(); const fmtMonth = (t: number) => new Date(t).toISOString().slice(0, 7); /** Papers per venue, placed on a time axis (venue start date). */ export function TimelineBars({ items }: { items: { label: string; date: string; n: number }[] }) { if (!items.length) return null; const xs = items.map((i) => ts(i.date)); const lo = Math.min(...xs) - 20 * 864e5, hi = Math.max(...xs) + 20 * 864e5; const max = Math.max(...items.map((i) => i.n)); const X = (t: number) => M.l + ((t - lo) / (hi - lo || 1)) * (W - M.l - M.r); const Y = (v: number) => H - M.b - (v / max) * (H - M.t - M.b); return ( {[0, max / 2, max].map((v) => ( {Math.round(v)} ))} {items.map((i, k) => ( {`${i.label}: ${i.n} papers`} {i.label} {fmtMonth(ts(i.date))} {i.n} ))} ); } export interface ScorePoint { date: string; score: number; series: string; label: string; unit?: string | null } /** Scores over time, coloured by setting (finetuned / prompted / baseline / proposed). */ export function ScoreScatter({ points }: { points: ScorePoint[] }) { if (!points.length) return null; const series = Array.from(new Set(points.map((p) => p.series))); const xs = points.map((p) => ts(p.date)); const lo = Math.min(...xs) - 15 * 864e5, hi = Math.max(...xs) + 15 * 864e5; const ys = points.map((p) => p.score); const ymin = Math.min(0, ...ys), ymax = Math.max(...ys) * 1.05 || 1; const X = (t: number) => M.l + ((t - lo) / (hi - lo || 1)) * (W - M.l - M.r); const Y = (v: number) => H - M.b - ((v - ymin) / (ymax - ymin || 1)) * (H - M.t - M.b); const ticks = [ymin, (ymin + ymax) / 2, ymax]; return (
{ticks.map((v) => ({v.toFixed(1)}))} {[lo, (lo + hi) / 2, hi].map((t) => ({fmtMonth(t)}))} {points.map((p, i) => ( {`${p.label}: ${p.score}${p.unit ?? ''} (${p.series})`} ))} ({ label: s, color: PALETTE[i % PALETTE.length] }))} />
); } /** Horizontal bars: best score per system. */ export function ScoreBars({ rows }: { rows: { label: string; score: number; series: string }[] }) { if (!rows.length) return null; const series = Array.from(new Set(rows.map((r) => r.series))); const max = Math.max(...rows.map((r) => r.score)) || 1; const sorted = [...rows].sort((a, b) => b.score - a.score).slice(0, 15); return (
{sorted.map((r, i) => (
{r.label}
{r.score}
))} ({ label: s, color: PALETTE[i % PALETTE.length] }))} />
); } function Legend({ items }: { items: { label: string; color: string }[] }): ReactNode { return (
{items.map((i) => ({i.label}))}
); }