|
#!/usr/bin/env node |
|
// Re-draws the "Changes merged per day" chart with Claude model release markers. |
|
// |
|
// npm install |
|
// node make_chart.mjs [changes_merged_per_day_2026.csv] [output-name] |
|
// |
|
// Reads the CSV of values extracted from the original chart and writes |
|
// <output-name>.svg and <output-name>.png at the original 3840x2160 size. |
|
// DM Sans stands in for the original typeface. Every position, size and colour below was |
|
// measured from the original PNG, in pixels. |
|
|
|
import fs from 'node:fs'; |
|
import path from 'node:path'; |
|
import { createRequire } from 'node:module'; |
|
import { Resvg } from '@resvg/resvg-js'; |
|
import * as fontkit from 'fontkit'; |
|
|
|
const [csvPath = 'changes_merged_per_day_2026.csv', outName = 'changes_merged_per_day_with_releases'] = |
|
process.argv.slice(2); |
|
|
|
// ---------------------------------------------------------------- releases to mark |
|
// [date, label lines, side of the dotted line the text sits on, y of the label's top] |
|
const T1 = 1050, T2 = 1190, T3 = 1330, T4 = 1470; // label rows, staggered so lines never cross labels |
|
const RELEASES = [ |
|
['2026-02-05', ['Opus 4.6'], 'right', T3], |
|
['2026-02-17', ['Sonnet 4.6'], 'right', T4], |
|
['2026-04-07', ['Mythos Preview'], 'right', T3], |
|
['2026-04-16', ['Opus 4.7'], 'right', T4], |
|
['2026-05-28', ['Opus 4.8'], 'right', T1], |
|
['2026-06-09', ['Fable 5', 'Mythos 5'], 'right', T2], |
|
['2026-06-30', ['Sonnet 5'], 'right', T3], |
|
['2026-07-24', ['Opus 5'], 'left', T2], |
|
['2026-09-01', ['Fable 5.1', 'Mythos 5.1'], 'left', 912], // tucked under the 30,401 callout |
|
]; |
|
|
|
// ---------------------------------------------------------------- style (sampled from the original) |
|
const BG = '#e7e7db', CARD = '#fafbf8'; |
|
const INK = '#141412', SUB = '#5f5e55', MUTED = '#72736e', NUM = '#393937'; |
|
const GRID = '#e5e7de', BLUE = '#5391ca', ORANGE = '#d87757', LINE = '#393a35'; |
|
|
|
const W = 3840, H = 2160; |
|
const X0 = 407.712; // x of the Jan 1 bar centre |
|
const X_END = 3645.0; // right end of the x axis and gridlines |
|
const DX = 12.58518; // px per day |
|
const BAR_W = 9.0, R = BAR_W / 2; |
|
const Y0 = 1726.01; // y of value 0 |
|
const PX_PER_UNIT = 0.034743; |
|
const MON = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; |
|
|
|
const yv = (v) => Y0 - PX_PER_UNIT * v; |
|
const dayIndex = (iso) => { |
|
const [y, m, d] = iso.split('-').map(Number); |
|
return Math.round((Date.UTC(y, m - 1, d) - Date.UTC(2026, 0, 1)) / 86400000); |
|
}; |
|
const xd = (d) => X0 + d * DX; |
|
const f1 = (n) => n.toFixed(1), f2 = (n) => n.toFixed(2); |
|
|
|
// ---------------------------------------------------------------- fonts |
|
const require = createRequire(import.meta.url); |
|
const FONT_DIR = path.dirname(require.resolve('@expo-google-fonts/dm-sans/package.json')); |
|
const FONT_FILES = { |
|
400: '400Regular/DMSans_400Regular.ttf', |
|
500: '500Medium/DMSans_500Medium.ttf', |
|
600: '600SemiBold/DMSans_600SemiBold.ttf', |
|
700: '700Bold/DMSans_700Bold.ttf', |
|
}; |
|
const fontPaths = Object.fromEntries(Object.entries(FONT_FILES).map(([w, f]) => [w, path.join(FONT_DIR, f)])); |
|
const fkCache = {}; |
|
function textWidth(s, size, weight, ls = 0) { |
|
fkCache[weight] ??= fontkit.openSync(fontPaths[weight]); |
|
const font = fkCache[weight]; |
|
return (font.layout(s).advanceWidth * size) / font.unitsPerEm + ls * Math.max(s.length - 1, 0); |
|
} |
|
|
|
const esc = (s) => s.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>'); |
|
function text(x, y, s, size, weight = 400, fill = MUTED, anchor = 'start', ls = 0) { |
|
const lsa = ls ? ` letter-spacing="${ls}"` : ''; |
|
return `<text x="${f1(x)}" y="${f1(y)}" font-family="DM Sans" font-size="${size}" font-weight="${weight}" ` + |
|
`fill="${fill}" text-anchor="${anchor}"${lsa}>${esc(s)}</text>`; |
|
} |
|
|
|
// ---------------------------------------------------------------- data |
|
function parseCSV(src) { |
|
const rows = []; |
|
let row = [], field = '', quoted = false; |
|
for (let i = 0; i < src.length; i++) { |
|
const c = src[i]; |
|
if (quoted) { |
|
if (c === '"' && src[i + 1] === '"') { field += '"'; i++; } |
|
else if (c === '"') quoted = false; |
|
else field += c; |
|
} else if (c === '"') quoted = true; |
|
else if (c === ',') { row.push(field); field = ''; } |
|
else if (c === '\n') { row.push(field); rows.push(row); row = []; field = ''; } |
|
else if (c !== '\r') field += c; |
|
} |
|
if (field || row.length) { row.push(field); rows.push(row); } |
|
const [header, ...body] = rows; |
|
return body.filter((r) => r.length > 1).map((r) => Object.fromEntries(header.map((h, i) => [h, r[i]]))); |
|
} |
|
|
|
const rows = parseCSV(fs.readFileSync(csvPath, 'utf8')).map((r) => ({ |
|
date: r.date, pr: Number(r.pull_requests), acr: Number(r.antique_change_requests), |
|
})); |
|
rows.forEach((r, i) => { |
|
r.total = r.pr + r.acr; |
|
r.avg = i >= 6 ? rows.slice(i - 6, i + 1).reduce((s, x) => s + x.pr + x.acr, 0) / 7 : null; // trailing 7-day mean |
|
}); |
|
|
|
// highest bar or average-line point within a day either side, so marker lines stop just above the data |
|
function dataTop(k) { |
|
let m = 0; |
|
for (let j = k - 1; j <= k + 1; j++) { |
|
if (j < 0 || j >= rows.length) continue; |
|
m = Math.max(m, rows[j].total, rows[j].avg ?? 0); |
|
} |
|
return yv(m); |
|
} |
|
|
|
// ---------------------------------------------------------------- build the SVG |
|
const out = [`<svg xmlns="http://www.w3.org/2000/svg" width="${W}" height="${H}" viewBox="0 0 ${W} ${H}">`]; |
|
out.push(`<rect width="${W}" height="${H}" fill="${BG}"/>`); |
|
out.push(`<rect x="72" y="376" width="3696" height="1714" rx="44" fill="${CARD}"/>`); |
|
out.push(text(1920, 190, 'Changes merged per day', 122, 600, INK, 'middle', -1.5)); |
|
out.push(text(1920, 287, 'Anthropic monorepo, January–September 2026', 70, 500, SUB, 'middle', -1.0)); |
|
|
|
// gridlines, y ticks and labels |
|
for (let v = 5000; v <= 35000; v += 5000) { |
|
const y = yv(v); |
|
out.push(`<line x1="${f1(X0)}" y1="${f2(y)}" x2="${X_END}" y2="${f2(y)}" stroke="${GRID}" stroke-width="4"/>`); |
|
} |
|
for (let v = 0; v <= 35000; v += 5000) { |
|
const y = yv(v); |
|
out.push(`<line x1="384.5" y1="${f2(y)}" x2="${X0}" y2="${f2(y)}" stroke="${MUTED}" stroke-width="6"/>`); |
|
out.push(text(353, y + 16.5, v.toLocaleString('en-US'), 47, 600, MUTED, 'end', -1.5)); |
|
} |
|
|
|
// release marker lines (dotted), drawn behind the bars |
|
const releases = RELEASES.map(([date, names, side, y]) => { |
|
const k = dayIndex(date); |
|
return { k, date, names, side, y, x: xd(k), top: y - 2, bottom: dataTop(k) - 36 }; |
|
}); |
|
for (const r of releases) { |
|
out.push(`<line x1="${f1(r.x)}" y1="${f1(r.top)}" x2="${f1(r.x)}" y2="${f1(r.bottom)}" stroke="${MUTED}" ` + |
|
`stroke-width="5" stroke-linecap="round" stroke-dasharray="0.01 13"/>`); |
|
} |
|
|
|
// bars: rounded tops, pull requests stacked under antique change requests |
|
out.push('<g>'); |
|
rows.forEach((row, i) => { |
|
if (row.total <= 0) return; |
|
const x = xd(i), yt = yv(row.total), ry = Math.min(R, Y0 - yt); |
|
const shape = `M${f2(x - R)},${f2(Y0)} L${f2(x - R)},${f2(yt + ry)} A${f2(R)},${f2(ry)} 0 0 1 ${f2(x + R)},${f2(yt + ry)} ` + |
|
`L${f2(x + R)},${f2(Y0)} Z`; |
|
if (row.acr > 0 && row.pr > 0) { |
|
const yb = yv(row.pr); |
|
out.push(`<clipPath id="c${i}"><path d="${shape}"/></clipPath>`); |
|
out.push(`<g clip-path="url(#c${i})"><rect x="${f2(x - R)}" y="${f2(yt - 1)}" width="${f2(BAR_W)}" ` + |
|
`height="${f2(yb - yt + 1)}" fill="${ORANGE}"/><rect x="${f2(x - R)}" y="${f2(yb)}" width="${f2(BAR_W)}" ` + |
|
`height="${f2(Y0 - yb + 1)}" fill="${BLUE}"/></g>`); |
|
} else { |
|
out.push(`<path d="${shape}" fill="${row.acr > 0 ? ORANGE : BLUE}"/>`); |
|
} |
|
}); |
|
out.push('</g>'); |
|
|
|
// 7-day average line |
|
const pts = rows.map((r, i) => (r.avg === null ? null : `${f2(xd(i))},${f2(yv(r.avg))}`)).filter(Boolean); |
|
out.push(`<path d="M${pts.join(' L')}" fill="none" stroke="${LINE}" stroke-width="6.2" stroke-linejoin="round" stroke-linecap="round"/>`); |
|
|
|
// axes, month ticks and labels |
|
out.push(`<line x1="384.5" y1="${f2(Y0 - 0.01)}" x2="${X_END}" y2="${f2(Y0 - 0.01)}" stroke="${MUTED}" stroke-width="6"/>`); |
|
out.push(`<line x1="${f1(X0 + 0.3)}" y1="${f1(yv(35000) - 3)}" x2="${f1(X0 + 0.3)}" y2="1749" stroke="${MUTED}" stroke-width="6"/>`); |
|
for (let m = 1; m <= 12; m++) { |
|
const x = xd(dayIndex(`2026-${String(m).padStart(2, '0')}-01`)); |
|
if (x > X_END - 1) break; |
|
out.push(`<line x1="${f1(x)}" y1="${f1(Y0)}" x2="${f1(x)}" y2="1749" stroke="${MUTED}" stroke-width="6"/>`); |
|
out.push(text(x, 1822, MON[m - 1], 47, 600, MUTED, 'middle', -1.0)); |
|
} |
|
|
|
// "Quiet week" annotation, in the original's dashed style (label raised to clear the Opus 5 label) |
|
const xq = xd(dayIndex('2026-07-29')); |
|
out.push(text(xq, T1 + 36, 'Quiet week', 50, 600, MUTED, 'middle', -1.0)); |
|
out.push(`<line x1="${f1(xq)}" y1="${f1(T1 + 66)}" x2="${f1(xq)}" y2="1607.0" stroke="${MUTED}" stroke-width="6" ` + |
|
`stroke-linecap="round" stroke-dasharray="23 19.5" stroke-dashoffset="12"/>`); |
|
|
|
// release labels: model name(s) in dark ink, date underneath in grey |
|
for (const r of releases) { |
|
const right = r.side === 'right'; |
|
const tx = right ? r.x + 16 : r.x - 16; |
|
const anchor = right ? 'start' : 'end'; |
|
const base = r.y + 32; |
|
r.names.forEach((name, k) => out.push(text(tx, base + k * 50, name, 46, 600, NUM, anchor, -0.5))); |
|
const [, mm, dd] = r.date.split('-').map(Number); |
|
out.push(text(tx, base + (r.names.length - 1) * 50 + 46, `${MON[mm - 1]} ${dd}`, 40, 400, MUTED, anchor, -0.3)); |
|
} |
|
|
|
// callout box for the peak day |
|
out.push(`<rect x="3060.0" y="670" width="457.0" height="197" rx="27" fill="${CARD}" stroke="${MUTED}" stroke-width="6"/>`); |
|
out.push(text(3471, 756, '30,401', 66, 700, NUM, 'end', -1.5)); |
|
out.push(text(3471, 820, 'merged on Sep 9', 48, 500, MUTED, 'end', -0.5)); |
|
|
|
// legend, centred under the plot |
|
const items = [ |
|
['sq', BLUE, 'Pull requests'], |
|
['sq', ORANGE, 'Antique change requests'], |
|
['ln', LINE, '7-day average'], |
|
['rel', MUTED, 'Claude model release'], |
|
]; |
|
const SW = { sq: 59, ln: 90, rel: 20 }, GAP = { sq: 32, ln: 26, rel: 22 }; |
|
const widths = items.map(([k, , t]) => SW[k] + GAP[k] + textWidth(t, 49, 500, -0.5)); |
|
let lx = 1920 - (widths.reduce((a, b) => a + b, 0) + 82 * (items.length - 1)) / 2; |
|
const ymid = 1945.5; |
|
items.forEach(([kind, col, label], i) => { |
|
if (kind === 'sq') { |
|
out.push(`<rect x="${f1(lx)}" y="${f1(ymid - 29)}" width="59" height="58" rx="8" fill="${col}"/>`); |
|
} else if (kind === 'ln') { |
|
out.push(`<line x1="${f1(lx + 5)}" y1="${ymid}" x2="${f1(lx + 85)}" y2="${ymid}" stroke="${col}" stroke-width="10" stroke-linecap="round"/>`); |
|
} else { |
|
out.push(`<line x1="${f1(lx + 10)}" y1="${f1(ymid - 27)}" x2="${f1(lx + 10)}" y2="${f1(ymid + 27)}" stroke="${col}" ` + |
|
`stroke-width="5" stroke-linecap="round" stroke-dasharray="0.01 13"/>`); |
|
} |
|
out.push(text(lx + SW[kind] + GAP[kind], ymid + 16.5, label, 49, 500, MUTED, 'start', -0.5)); |
|
lx += widths[i] + 82; |
|
}); |
|
out.push('</svg>'); |
|
const svg = out.join('\n'); |
|
|
|
// ---------------------------------------------------------------- render |
|
fs.writeFileSync(`${outName}.svg`, svg); |
|
const png = new Resvg(svg, { |
|
font: { fontFiles: Object.values(fontPaths), loadSystemFonts: false, defaultFontFamily: 'DM Sans' }, |
|
shapeRendering: 2, textRendering: 2, |
|
}).render().asPng(); |
|
fs.writeFileSync(`${outName}.png`, png); |
|
console.log(`wrote ${outName}.svg and ${outName}.png`); |