Files
ai-taxonomy-literature-anal…/components/ReviewCharts.tsx
T

50 lines
2.7 KiB
TypeScript

const PALETTE = ['#2f5bea', '#e0702b', '#1b9e77', '#a14b9c', '#c9a227', '#d6336c', '#37a0d6', '#6b8e23'];
/** Swimlane: one lane per subfield, papers as dots on a venue-date axis. */
export function SubfieldTimeline({ lanes, cite }: { lanes: { name: string; papers: { id: number; date: string; title: string }[] }[]; cite: Record<number, number> }) {
const all = lanes.flatMap((l) => l.papers);
if (!all.length) return null;
const ts = (d: string) => new Date(d + (d.length === 7 ? '-15' : '') + 'T00:00:00Z').getTime();
const lo = Math.min(...all.map((p) => ts(p.date))) - 25 * 864e5, hi = Math.max(...all.map((p) => ts(p.date))) + 25 * 864e5;
const W = 760, L = 210, R = 16, laneH = 34, top = 8, H = top + lanes.length * laneH + 30;
const X = (t: number) => L + ((t - lo) / (hi - lo || 1)) * (W - L - R);
const months: number[] = [];
for (let d = new Date(lo); d.getTime() <= hi; d.setUTCMonth(d.getUTCMonth() + 1)) months.push(Date.UTC(d.getUTCFullYear(), d.getUTCMonth(), 1));
return (
<svg viewBox={`0 0 ${W} ${H}`} width="100%" role="img" aria-label="papers per subfield over time">
{months.map((m) => (<g key={m}><line x1={X(m)} x2={X(m)} y1={top} y2={H - 26} stroke="currentColor" opacity=".08" /><text x={X(m)} y={H - 10} fontSize="10" textAnchor="middle" fill="currentColor" opacity=".6">{new Date(m).toISOString().slice(0, 7)}</text></g>))}
{lanes.map((l, i) => {
const y = top + i * laneH + laneH / 2;
const byDate: Record<string, number> = {};
return (
<g key={l.name}>
<text x={L - 8} y={y + 4} fontSize="11" textAnchor="end" fill="currentColor">{l.name.length > 32 ? l.name.slice(0, 31) + '…' : l.name}</text>
<line x1={L} x2={W - R} y1={y} y2={y} stroke="currentColor" opacity=".15" />
{l.papers.map((p) => {
const k = (byDate[p.date] = (byDate[p.date] ?? 0) + 1);
const dx = ((k - 1) % 6) * 7 - 17, dy = Math.floor((k - 1) / 6) * 7 - 5;
return (
<a key={p.id} href={`#ref-${p.id}`}>
<circle cx={X(ts(p.date)) + dx} cy={y + dy} r="4.5" fill={PALETTE[i % PALETTE.length]} opacity=".85"><title>{`[${cite[p.id]}] ${p.title} (${p.date})`}</title></circle>
</a>
);
})}
</g>
);
})}
</svg>
);
}
/** Horizontal workflow: boxes with arrows, wrapping. */
export function WorkflowFlow({ steps }: { steps: string[] }) {
if (!steps.length) return null;
return (
<div className="flow">
{steps.map((s, i) => (
<div key={i} className="flow-step"><span className="flow-n">{i + 1}</span>{s}{i < steps.length - 1 && <span className="flow-arrow">→</span>}</div>
))}
</div>
);
}