Files
ai-taxonomy-literature-anal…/components/SvgCharts.tsx
T
zzyang d6fc7c1dfa Add types-of-work classification, benchmarks and score pages
- Work type = area x role (fixed vs varied), vocabulary in scripts/worktypes.json
- LLM-read labels for 2,678 agent-related papers (data/labels), rule labels for the rest
- Per-type synthesis notes (why-same, sub-variants, benchmarks, workflow)
- Pages: /work-types matrix and detail (timeline, benchmarks, workflow, score charts), /benchmarks
- build_worktypes.py adds work-type tables to data/papers.db

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Bhs9LU8eMixk6g1kb1d3j7
2026-10-21 11:55:46 +00:00

92 lines
5.2 KiB
TypeScript

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 (
<svg viewBox={`0 0 ${W} ${H}`} width="100%" role="img" aria-label="papers per venue over time">
<line x1={M.l} y1={H - M.b} x2={W - M.r} y2={H - M.b} stroke="currentColor" opacity=".3" />
{[0, max / 2, max].map((v) => (
<g key={v}><text x={M.l - 6} y={Y(v) + 4} textAnchor="end" fontSize="11" fill="currentColor" opacity=".6">{Math.round(v)}</text></g>
))}
{items.map((i, k) => (
<g key={i.label + k}>
<rect x={X(ts(i.date)) - 14} y={Y(i.n)} width="28" height={H - M.b - Y(i.n)} fill={PALETTE[k % PALETTE.length]} rx="3"><title>{`${i.label}: ${i.n} papers`}</title></rect>
<text x={X(ts(i.date))} y={H - M.b + 14} textAnchor="middle" fontSize="11" fill="currentColor">{i.label}</text>
<text x={X(ts(i.date))} y={H - M.b + 26} textAnchor="middle" fontSize="9" fill="currentColor" opacity=".6">{fmtMonth(ts(i.date))}</text>
<text x={X(ts(i.date))} y={Y(i.n) - 4} textAnchor="middle" fontSize="11" fill="currentColor">{i.n}</text>
</g>
))}
</svg>
);
}
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 (
<div>
<svg viewBox={`0 0 ${W} ${H}`} width="100%" role="img" aria-label="scores over time">
<line x1={M.l} y1={H - M.b} x2={W - M.r} y2={H - M.b} stroke="currentColor" opacity=".3" />
{ticks.map((v) => (<g key={v}><line x1={M.l} x2={W - M.r} y1={Y(v)} y2={Y(v)} stroke="currentColor" opacity=".08" /><text x={M.l - 6} y={Y(v) + 4} textAnchor="end" fontSize="11" fill="currentColor" opacity=".6">{v.toFixed(1)}</text></g>))}
{[lo, (lo + hi) / 2, hi].map((t) => (<text key={t} x={X(t)} y={H - M.b + 16} textAnchor="middle" fontSize="11" fill="currentColor" opacity=".7">{fmtMonth(t)}</text>))}
{points.map((p, i) => (
<circle key={i} cx={X(ts(p.date))} cy={Y(p.score)} r="5" fill={PALETTE[series.indexOf(p.series) % PALETTE.length]} opacity=".85"><title>{`${p.label}: ${p.score}${p.unit ?? ''} (${p.series})`}</title></circle>
))}
</svg>
<Legend items={series.map((s, i) => ({ label: s, color: PALETTE[i % PALETTE.length] }))} />
</div>
);
}
/** 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 (
<div>
{sorted.map((r, i) => (
<div key={i} style={{ display: 'flex', alignItems: 'center', gap: 8, margin: '3px 0', fontSize: 13 }}>
<div style={{ width: 200, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }} title={r.label}>{r.label}</div>
<div style={{ flex: 1, background: 'var(--line)', borderRadius: 4, height: 12 }}>
<div style={{ width: `${(r.score / max) * 100}%`, height: 12, borderRadius: 4, background: PALETTE[series.indexOf(r.series) % PALETTE.length] }} />
</div>
<div style={{ width: 52, textAlign: 'right' }}>{r.score}</div>
</div>
))}
<Legend items={series.map((s, i) => ({ label: s, color: PALETTE[i % PALETTE.length] }))} />
</div>
);
}
function Legend({ items }: { items: { label: string; color: string }[] }): ReactNode {
return (
<div style={{ fontSize: 12, display: 'flex', gap: 12, flexWrap: 'wrap', marginTop: 4 }}>
{items.map((i) => (<span key={i.label}><span style={{ display: 'inline-block', width: 10, height: 10, borderRadius: 5, background: i.color, marginRight: 4 }} />{i.label}</span>))}
</div>
);
}