joelniklaus HF Staff commited on
Commit
a34e974
·
1 Parent(s): 75ef4f9

Improved the banner to make it more specific and memorable

Browse files
Files changed (1) hide show
  1. app/src/content/embeds/banner.html +787 -381
app/src/content/embeds/banner.html CHANGED
@@ -1,387 +1,793 @@
1
- <div class="d3-synth-scale" style="width:100%;margin:0;aspect-ratio:2.5/1;min-height:300px;"></div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  <script>
3
- (() => {
4
- const ensureD3 = (cb) => {
5
- if (window.d3 && typeof window.d3.select === 'function') return cb();
6
- let s = document.getElementById('d3-cdn-script');
7
- if (!s) { s = document.createElement('script'); s.id = 'd3-cdn-script'; s.src = 'https://cdn.jsdelivr.net/npm/d3@7/dist/d3.min.js'; document.head.appendChild(s); }
8
- const onReady = () => { if (window.d3 && typeof window.d3.select === 'function') cb(); };
9
- s.addEventListener('load', onReady, { once: true });
10
- if (window.d3) onReady();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  };
12
 
13
- const bootstrap = () => {
14
- const mount = document.currentScript ? document.currentScript.previousElementSibling : null;
15
- const container = (mount && mount.querySelector && mount.querySelector('.d3-synth-scale')) ||
16
- Array.from(document.querySelectorAll('.d3-synth-scale')).find(el => el.dataset.mounted !== 'true');
17
- if (!container) return;
18
- if (container.dataset.mounted === 'true') return;
19
- container.dataset.mounted = 'true';
20
- container.style.background = 'transparent';
21
- container.style.overflow = 'visible';
22
- container.style.position = 'relative';
23
-
24
- const JSON_PATHS = ['/data/rephrasing_metadata.json', './assets/data/rephrasing_metadata.json'];
25
- const CSV_PATHS = ['/data/benchmark-results.csv', './assets/data/benchmark-results.csv'];
26
-
27
- const fetchFirstAvailable = async (paths, parse) => {
28
- for (const p of paths) {
29
- try { const r = await fetch(p, { cache: 'no-cache' }); if (r.ok) return parse ? parse(await r.text()) : r.json(); } catch(_) {}
30
- }
31
- throw new Error('Data not found: ' + paths.join(', '));
32
- };
33
-
34
- // Derive display fields from a JSON entry
35
- const FAMILY_MAP = {
36
- 'gemma': 'Gemma', 'qwen': 'Qwen', 'llama': 'Llama',
37
- 'falcon': 'Falcon', 'granite': 'Granite', 'smollm': 'SmolLM2'
38
- };
39
- const SOURCE_MAP = {
40
- 'fineweb-edu-hq-20BT': 'FW-Edu HQ',
41
- 'fineweb-edu-lq-20BT': 'FW-Edu LQ',
42
- 'dclm-37BT': 'DCLM',
43
- 'cosmopedia-25BT': 'Cosmopedia'
44
- };
45
- const CAT_MAP = { 'format': 'Format', 'nemotron': 'Nemotron', 'rewire': 'REWIRE' };
46
-
47
- const PROMPT_LABELS = {
48
- 'article': 'Article', 'commentary': 'Commentary', 'discussion': 'Discussion',
49
- 'faq': 'Faq', 'math': 'Math', 'table': 'Table', 'tutorial': 'Tutorial',
50
- 'distill': 'Distill', 'diverse_qa_pairs': 'Diverse QA',
51
- 'extract_knowledge': 'Extract Knowledge', 'knowledge_list': 'Knowledge List',
52
- 'wikipedia_style_rephrasing': 'Wikipedia Style',
53
- 'guided_rewrite_improved': 'Guided Rewrite+',
54
- 'guided_rewrite_original': 'Guided Rewrite'
55
- };
56
-
57
- function gpuDays(seconds) {
58
- const d = Math.round(seconds / 86400);
59
- return d.toLocaleString() + ' days';
60
- }
61
-
62
- // Map source_dataset names to baseline run names in the CSV
63
- const SOURCE_TO_BASELINE_RUN = {
64
- 'fineweb-edu-hq-20BT': 'fw_edu_hq',
65
- 'fineweb-edu-lq-20BT': 'fw_edu_lq',
66
- 'dclm-37BT': 'dclm',
67
- 'cosmopedia-25BT': 'cosmopedia'
68
- };
69
-
70
- // Extract max-step agg_score_macro per baseline run from CSV rows
71
- function buildBaselineMacro(csvRows) {
72
- const baselineRuns = new Set(Object.values(SOURCE_TO_BASELINE_RUN));
73
- const best = {};
74
- for (const row of csvRows) {
75
- if (!baselineRuns.has(row.runname)) continue;
76
- const step = +row.steps;
77
- const score = +row.agg_score_macro;
78
- if (!(row.runname in best) || step > best[row.runname][0]) {
79
- best[row.runname] = [step, score];
80
- }
81
- }
82
- const out = {};
83
- for (const [src, run] of Object.entries(SOURCE_TO_BASELINE_RUN)) {
84
- if (run in best) out[src] = best[run][1];
85
- }
86
- return out;
87
- }
88
-
89
- function parseEntry(d, i, baselineMacro) {
90
- const [cat, promptFile] = d.prompt.split('/');
91
- const promptKey = promptFile.replace('.md', '');
92
- const modelShort = d.model.split('/').pop();
93
- const modelLower = d.model.toLowerCase();
94
- const family = Object.entries(FAMILY_MAP).find(([k]) => modelLower.includes(k))?.[1] || 'Other';
95
- const aggMacro = d.results?.agg_score_macro;
96
- const baseline = baselineMacro[d.source_dataset];
97
- return {
98
- id: i,
99
- prompt: PROMPT_LABELS[promptKey] || promptKey,
100
- cat: CAT_MAP[cat] || cat,
101
- source: SOURCE_MAP[d.source_dataset] || d.source_dataset,
102
- model: modelShort,
103
- family,
104
- compB: d.output_tokens / 1e9,
105
- outputHuman: d.output_tokens_human,
106
- inputHuman: d.input_tokens_human,
107
- gpuSeconds: d.gpu_time_seconds,
108
- gpuTime: gpuDays(d.gpu_time_seconds),
109
- docsM: d.num_documents / 1e6,
110
- dclm: d.dclm_score_difference,
111
- dclmBase: d.input_dclm_score,
112
- edu: d.edu_score_difference,
113
- eduBase: d.input_edu_score,
114
- aggDiff: (aggMacro != null && baseline != null) ? aggMacro - baseline : null,
115
- aggBase: baseline,
116
- phase: (i * 2.399) % (Math.PI * 2)
117
- };
118
- }
119
-
120
- function formatTokens(n) {
121
- if (n >= 1000) return (n / 1000).toFixed(1) + 'T';
122
- return n.toFixed(1) + 'B';
123
- }
124
-
125
- // Format absolute diff + relative % in brackets, e.g. "+0.018 (+12.3%)"
126
- function fmtDelta(diff, base) {
127
- const sign = diff >= 0 ? '+' : '';
128
- const abs = `${sign}${diff.toFixed(3)}`;
129
- if (base != null && base !== 0) {
130
- const pct = (diff / base) * 100;
131
- return `${abs} <span style="opacity:.5">(${pct >= 0 ? '+' : ''}${pct.toFixed(1)}%)</span>`;
132
- }
133
- return abs;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
134
  }
135
-
136
- Promise.all([
137
- fetchFirstAvailable(JSON_PATHS),
138
- fetchFirstAvailable(CSV_PATHS, d3.csvParse)
139
- ]).then(([raw, csvRows]) => {
140
- const baselineMacro = buildBaselineMacro(csvRows);
141
- const data = raw.map((d, i) => parseEntry(d, i, baselineMacro));
142
- const totalOutputB = data.reduce((s, d) => s + d.compB, 0);
143
- const totalDocsM = data.reduce((s, d) => s + d.docsM, 0);
144
- const numExperiments = data.length;
145
-
146
- let animFrame = null;
147
-
148
- const render = () => {
149
- const W = container.clientWidth || 900;
150
- const H = container.clientHeight || 360;
151
- if (animFrame) { cancelAnimationFrame(animFrame); animFrame = null; }
152
- container.innerHTML = '';
153
-
154
- const canvas = d3.select(container).append('svg')
155
- .attr('width', W).attr('height', H)
156
- .style('font-family', "'Inter', system-ui, -apple-system, sans-serif");
157
-
158
- const col = {
159
- Gemma: '#5b9bd5', Qwen: '#e07b54', Llama: '#8bc474',
160
- Falcon: '#c9a046', Granite: '#9a8ec2', SmolLM2: '#e06b9e'
161
- };
162
- const fillAlpha = 0.22;
163
-
164
- const cx = W / 2;
165
- const packR = Math.min(W * 0.28, H * 0.34);
166
- const maxR = Math.min(packR * 0.30, 44);
167
- const minR = Math.max(4, W * 0.005);
168
- const rScale = d3.scaleSqrt()
169
- .domain([0, d3.max(data, d => d.compB)])
170
- .range([minR, maxR]);
171
-
172
- const megaFS = Math.min(W * 0.15, H * 0.24, 150);
173
- const subFS = Math.max(8, megaFS * 0.1);
174
- const megaY = H * 0.48;
175
- const subY = H * 0.87;
176
- const packCY = megaY;
177
-
178
- data.forEach(d => { d.r = rScale(d.compB); d.x = cx; d.y = packCY; });
179
-
180
- const spread = Math.min(W * 0.13, 110);
181
- const focalL = cx - spread;
182
- const focalR = cx + spread;
183
-
184
- const sim = d3.forceSimulation(data)
185
- .alphaDecay(0.012).velocityDecay(0.32)
186
- .force('x', d3.forceX(d => (d.id % 2 === 0) ? focalL : focalR).strength(0.02))
187
- .force('y', d3.forceY(packCY).strength(0.05))
188
- .force('collide', d3.forceCollide(d => d.r + 1.5).strength(0.8).iterations(3))
189
- .stop();
190
- for (let i = 0; i < 250; i++) sim.tick();
191
-
192
- const gB = canvas.append('g');
193
- const circles = gB.selectAll('circle')
194
- .data(data).join('circle')
195
- .attr('cx', d => d.x).attr('cy', d => d.y)
196
- .attr('r', d => d.r)
197
- .attr('fill', d => col[d.family])
198
- .attr('fill-opacity', fillAlpha)
199
- .attr('stroke', d => col[d.family])
200
- .attr('stroke-width', 0.7).attr('stroke-opacity', 0.12)
201
- .style('cursor', 'pointer');
202
-
203
- sim.on('tick', () => { circles.attr('cx', d => d.x).attr('cy', d => d.y); }).restart();
204
- sim.on('end', () => {
205
- data.forEach(d => { d.ox = d.x; d.oy = d.y; });
206
- const drift = () => {
207
- const t = Date.now() * 0.001;
208
- circles.each(function(d) {
209
- d3.select(this).attr('cy', d.oy + Math.sin(t * 0.22 + d.phase) * 1.2);
210
- });
211
- animFrame = requestAnimationFrame(drift);
212
- };
213
- drift();
214
- });
215
-
216
- // All overlay elements pass pointer events through to circles
217
- const noPtr = el => el.style('pointer-events', 'none');
218
-
219
- // Mega number
220
- noPtr(canvas.append('text')
221
- .attr('x', cx).attr('y', megaY)
222
- .attr('text-anchor', 'middle').attr('dominant-baseline', 'middle')
223
- .attr('fill', '#1a1a1a')
224
- .attr('font-size', megaFS).attr('font-weight', 900)
225
- .attr('letter-spacing', '-0.04em')
226
- .text(formatTokens(totalOutputB)));
227
-
228
- const labelFS = Math.max(10, megaFS * 0.15);
229
- noPtr(canvas.append('text')
230
- .attr('x', cx).attr('y', megaY + megaFS * 0.44)
231
- .attr('text-anchor', 'middle').attr('dominant-baseline', 'middle')
232
- .attr('fill', '#999')
233
- .attr('font-size', labelFS).attr('font-weight', 600)
234
- .attr('letter-spacing', '0.18em')
235
- .text('TOKENS GENERATED'));
236
-
237
- // Bottom stats
238
- const totalDocsB = (totalDocsM / 1000).toFixed(2);
239
- const subText = `${numExperiments} EXPERIMENTS \u00B7 ${totalDocsB}B DOCUMENTS`;
240
- const subEl = canvas.append('text')
241
- .attr('x', cx).attr('y', subY)
242
- .attr('text-anchor', 'middle').attr('dominant-baseline', 'middle')
243
- .attr('fill', '#555')
244
- .attr('font-size', subFS).attr('font-weight', 500)
245
- .attr('letter-spacing', '0.14em')
246
- .text(subText);
247
- noPtr(subEl);
248
-
249
- // Legend
250
- const legFS = Math.max(11, subFS * 1.5);
251
- const dotR = Math.max(2.5, legFS * 0.38);
252
- const legY = subY + subFS * 2.6;
253
- const familyCounts = {};
254
- data.forEach(d => { familyCounts[d.family] = (familyCounts[d.family] || 0) + 1; });
255
- const families = Object.entries(familyCounts)
256
- .sort((a, b) => b[1] - a[1])
257
- .map(([n, c]) => ({ n, c }));
258
-
259
- const legG = canvas.append('g');
260
- let tw = 0;
261
- families.forEach(it => { tw += dotR * 2 + 4 + (it.n.length + 4) * legFS * 0.55 + 12; });
262
- tw -= 12;
263
- let lx = cx - tw / 2;
264
- families.forEach(it => {
265
- const ig = legG.append('g').style('cursor', 'pointer');
266
- ig.append('circle')
267
- .attr('cx', lx + dotR).attr('cy', legY)
268
- .attr('r', dotR).attr('fill', col[it.n]).attr('fill-opacity', 0.5);
269
- const t = ig.append('text')
270
- .attr('x', lx + dotR * 2 + 4).attr('y', legY)
271
- .attr('dominant-baseline', 'middle')
272
- .attr('fill', '#555').attr('font-size', legFS).attr('font-weight', 500)
273
- .text(`${it.n} (${it.c})`);
274
- // Precompute cumulative stats for this family
275
- const fam = data.filter(d => d.family === it.n);
276
- const famOutputB = fam.reduce((s, d) => s + d.compB, 0);
277
- const famDocsM = fam.reduce((s, d) => s + d.docsM, 0);
278
- const famGpu = gpuDays(fam.reduce((s, d) => s + d.gpuSeconds, 0));
279
- const famModels = [...new Set(fam.map(d => d.model))];
280
-
281
- ig.on('mouseenter', function(event) {
282
- circles.transition().duration(80)
283
- .attr('fill-opacity', d => d.family === it.n ? 0.55 : 0.06)
284
- .attr('stroke-opacity', d => d.family === it.n ? 0.5 : 0.03);
285
- const c = col[it.n];
286
- tip.html(
287
- `<div style="display:flex;align-items:center;gap:6px;margin-bottom:4px">` +
288
- `<span style="width:8px;height:8px;border-radius:50%;background:${c};opacity:.6;display:inline-block"></span>` +
289
- `<span style="font-weight:700;font-size:1.05em;color:var(--text-color)">${it.n}</span></div>` +
290
- `<div style="display:grid;grid-template-columns:auto 1fr;gap:3px 14px;font-size:.9em">` +
291
- `<span style="opacity:.35">Runs</span><span style="font-weight:600;color:var(--text-color)">${it.c}</span>` +
292
- `<span style="opacity:.35">Models</span><span>${famModels.join(', ')}</span>` +
293
- `<span style="opacity:.35">Output</span><span>${formatTokens(famOutputB)} tokens</span>` +
294
- `<span style="opacity:.35">GPU time</span><span>${famGpu}</span>` +
295
- `<span style="opacity:.35">Docs</span><span>${famDocsM.toFixed(1)}M</span></div>`
296
- ).style('opacity', 1);
297
- const r = container.getBoundingClientRect();
298
- const bbox = ig.node().getBBox();
299
- const svgRect = canvas.node().getBoundingClientRect();
300
- let tx = svgRect.left - r.left + bbox.x + bbox.width / 2;
301
- let ty = svgRect.top - r.top + bbox.y + bbox.height + 8;
302
- tip.style('left', tx + 'px').style('top', ty + 'px')
303
- .style('transform', 'translate(-50%, 0)');
304
- }).on('mouseleave', () => {
305
- circles.transition().duration(160)
306
- .attr('fill-opacity', fillAlpha).attr('stroke-opacity', 0.12);
307
- tip.style('opacity', 0).style('transform', 'none');
308
- });
309
- lx += dotR * 2 + 4 + t.node().getComputedTextLength() + 12;
310
- });
311
-
312
- // Tooltip
313
- const tip = d3.select(container).append('div')
314
- .style('position', 'absolute').style('pointer-events', 'none')
315
- .style('background', 'var(--surface-bg)')
316
- .style('backdrop-filter', 'blur(10px)')
317
- .style('color', 'var(--text-color)')
318
- .style('border', '1px solid var(--border-color)')
319
- .style('border-radius', '10px').style('padding', '12px 16px')
320
- .style('font-size', Math.max(12, W * 0.014) + 'px')
321
- .style('font-family', "'Inter', system-ui, sans-serif")
322
- .style('line-height', '1.55').style('white-space', 'nowrap')
323
- .style('opacity', 0).style('transition', 'opacity .1s ease')
324
- .style('z-index', 10)
325
- .style('box-shadow', '0 4px 24px rgba(0,0,0,0.18)');
326
-
327
- circles
328
- .on('mouseenter', function(event, d) {
329
- d3.select(this).transition().duration(80)
330
- .attr('fill-opacity', 0.55).attr('stroke-opacity', 0.5).attr('stroke-width', 1.5);
331
- gB.selectAll('circle').filter(o => o.id !== d.id)
332
- .transition().duration(80)
333
- .attr('fill-opacity', 0.1).attr('stroke-opacity', 0.08);
334
- const c = col[d.family];
335
- const dc = d.dclm >= 0 ? '#16a34a' : '#dc2626';
336
- const ec = d.edu >= 0 ? '#16a34a' : '#dc2626';
337
- const ac = d.aggDiff != null ? (d.aggDiff >= 0 ? '#16a34a' : '#dc2626') : null;
338
- const aggRow = d.aggDiff != null
339
- ? `<span style="opacity:.35">Δ Macro</span><span style="color:${ac}">${fmtDelta(d.aggDiff, d.aggBase)}</span>`
340
- : '';
341
- tip.html(
342
- `<div style="display:flex;align-items:center;gap:6px;margin-bottom:4px">` +
343
- `<span style="width:8px;height:8px;border-radius:50%;background:${c};opacity:.6;display:inline-block"></span>` +
344
- `<span style="font-weight:700;font-size:1.05em;color:var(--text-color)">${d.model}</span></div>` +
345
- `<div style="opacity:.4;font-size:.88em;margin-bottom:7px">${d.prompt} · ${d.cat} · ${d.source}</div>` +
346
- `<div style="display:grid;grid-template-columns:auto 1fr;gap:3px 14px;font-size:.9em">` +
347
- `<span style="opacity:.35">Output</span><span style="font-weight:600;color:var(--text-color)">${d.outputHuman} tokens</span>` +
348
- `<span style="opacity:.35">Input</span><span>${d.inputHuman}</span>` +
349
- `<span style="opacity:.35">GPU time</span><span>${d.gpuTime}</span>` +
350
- `<span style="opacity:.35">Docs</span><span>${d.docsM.toFixed(1)}M</span>` +
351
- `<span style="opacity:.35">DCLM</span><span style="color:${dc}">${fmtDelta(d.dclm, d.dclmBase)}</span>` +
352
- `<span style="opacity:.35">Edu</span><span style="color:${ec}">${fmtDelta(d.edu, d.eduBase)}</span>` +
353
- aggRow + `</div>`
354
- ).style('opacity', 1);
355
- })
356
- .on('mousemove', function(event) {
357
- const r = container.getBoundingClientRect();
358
- let tx = event.clientX - r.left + 14;
359
- let ty = event.clientY - r.top - 10;
360
- if (tx + 260 > W) tx = event.clientX - r.left - 270;
361
- if (ty < 8) ty = 8;
362
- tip.style('left', tx + 'px').style('top', ty + 'px')
363
- .style('transform', 'none');
364
- })
365
- .on('mouseleave', function() {
366
- gB.selectAll('circle').transition().duration(160)
367
- .attr('fill-opacity', fillAlpha).attr('stroke-opacity', 0.12).attr('stroke-width', 0.7);
368
- tip.style('opacity', 0).style('transform', 'none');
369
- });
370
- };
371
-
372
- if (window.ResizeObserver) {
373
- new ResizeObserver(() => render()).observe(container);
374
- } else {
375
- window.addEventListener('resize', render);
376
- }
377
- render();
378
- }).catch(err => {
379
- container.innerHTML = `<pre style="color:red;padding:12px">${err.message}</pre>`;
380
  });
381
- };
382
-
383
- if (document.readyState === 'loading') {
384
- document.addEventListener('DOMContentLoaded', () => ensureD3(bootstrap), { once: true });
385
- } else { ensureD3(bootstrap); }
386
- })();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
387
  </script>
 
1
+ <div class="d3-bookshelf-banner" style="width:100%;margin:0;aspect-ratio:2/1;min-height:380px;"></div>
2
+ <style>
3
+ .d3-bookshelf-banner {
4
+ position: relative;
5
+ overflow: visible;
6
+ background: transparent;
7
+ font-family: 'Inter', system-ui, -apple-system, sans-serif;
8
+ }
9
+ .d3-bookshelf-banner svg { display: block; }
10
+ .d3-bookshelf-banner .book {
11
+ cursor: pointer;
12
+ }
13
+ .d3-bookshelf-banner .book .book-spine,
14
+ .d3-bookshelf-banner .book .book-pages {
15
+ transition: transform 0.22s cubic-bezier(.33,.1,.2,1), filter 0.22s ease, opacity 0.22s ease;
16
+ }
17
+ .d3-bookshelf-banner .overlay-text {
18
+ pointer-events: none;
19
+ user-select: none;
20
+ }
21
+ .d3-bookshelf-banner .d3-tooltip {
22
+ position: absolute;
23
+ pointer-events: none;
24
+ padding: 10px 14px;
25
+ border-radius: 10px;
26
+ font-size: 12px;
27
+ line-height: 1.5;
28
+ border: 1px solid var(--border-color);
29
+ background: var(--surface-bg);
30
+ backdrop-filter: blur(10px);
31
+ color: var(--text-color);
32
+ box-shadow: 0 4px 24px rgba(0,0,0,.18);
33
+ opacity: 0;
34
+ transition: opacity .12s ease;
35
+ white-space: nowrap;
36
+ z-index: 10;
37
+ }
38
+ </style>
39
  <script>
40
+ (() => {
41
+ const ensureD3 = (cb) => {
42
+ if (window.d3 && typeof window.d3.select === 'function') return cb();
43
+ let s = document.getElementById('d3-cdn-script');
44
+ if (!s) { s = document.createElement('script'); s.id = 'd3-cdn-script'; s.src = 'https://cdn.jsdelivr.net/npm/d3@7/dist/d3.min.js'; document.head.appendChild(s); }
45
+ const onReady = () => { if (window.d3 && typeof window.d3.select === 'function') cb(); };
46
+ s.addEventListener('load', onReady, { once: true });
47
+ if (window.d3) onReady();
48
+ };
49
+
50
+ const bootstrap = () => {
51
+ const scriptEl = document.currentScript;
52
+ let container = scriptEl ? scriptEl.previousElementSibling : null;
53
+ if (!(container && container.classList && container.classList.contains('d3-bookshelf-banner'))) {
54
+ const cs = Array.from(document.querySelectorAll('.d3-bookshelf-banner')).filter(el => !(el.dataset && el.dataset.mounted === 'true'));
55
+ container = cs[cs.length - 1] || null;
56
+ }
57
+ if (!container) return;
58
+ if (container.dataset) {
59
+ if (container.dataset.mounted === 'true') return;
60
+ container.dataset.mounted = 'true';
61
+ }
62
+ container.style.position = 'relative';
63
+
64
+ const FAMILY_MAP = {
65
+ 'gemma': 'Gemma', 'qwen': 'Qwen', 'llama': 'Llama',
66
+ 'falcon': 'Falcon', 'granite': 'Granite', 'smollm': 'SmolLM2'
67
+ };
68
+ const SOURCE_MAP = {
69
+ 'fineweb-edu-hq-20BT': 'FW-Edu HQ', 'fineweb-edu-lq-20BT': 'FW-Edu LQ',
70
+ 'dclm-37BT': 'DCLM', 'cosmopedia-25BT': 'Cosmopedia'
71
+ };
72
+ const CAT_MAP = { 'format': 'Format', 'nemotron': 'Nemotron', 'rewire': 'REWIRE' };
73
+ const PROMPT_LABELS = {
74
+ 'article': 'Article', 'commentary': 'Commentary', 'discussion': 'Discussion',
75
+ 'faq': 'FAQ', 'math': 'Math', 'table': 'Table', 'tutorial': 'Tutorial',
76
+ 'distill': 'Distill', 'diverse_qa_pairs': 'Diverse QA',
77
+ 'extract_knowledge': 'Extract Knowledge', 'knowledge_list': 'Knowledge List',
78
+ 'wikipedia_style_rephrasing': 'Wikipedia Style',
79
+ 'guided_rewrite_improved': 'Guided Rewrite+', 'guided_rewrite_original': 'Guided Rewrite',
80
+ 'explanation': 'Explanation', 'narrative': 'Narrative',
81
+ 'continue': 'Continue', 'summarize': 'Summarize'
82
+ };
83
+
84
+ function toCanonicalPrompt(promptPath) {
85
+ let base = promptPath.split('/').pop().replace('.md', '');
86
+ return base.replace(/-([\w.]+-)?\d+(\.\d+)?[bm]-\w+$/, '');
87
+ }
88
+
89
+ function getFamily(model) {
90
+ const lower = model.toLowerCase();
91
+ return Object.entries(FAMILY_MAP).find(([k]) => lower.includes(k))?.[1] || 'Other';
92
+ }
93
+
94
+ function gpuDays(seconds) { return Math.round(seconds / 86400).toLocaleString() + ' days'; }
95
+
96
+ const JSON_PATHS = ['/data/rephrasing_metadata.json', './assets/data/rephrasing_metadata.json'];
97
+ const CSV_PATHS = ['/data/benchmark-results.csv', './assets/data/benchmark-results.csv'];
98
+ const fetchFirst = async (paths, parse) => {
99
+ for (const p of paths) {
100
+ try { const r = await fetch(p, { cache: 'no-cache' }); if (r.ok) return parse ? parse(await r.text()) : r.json(); } catch(_) {}
101
+ }
102
+ throw new Error('Data not found: ' + paths.join(', '));
103
+ };
104
+
105
+ const SOURCE_TO_BASELINE_RUN = {
106
+ 'fineweb-edu-hq-20BT': 'fw_edu_hq', 'fineweb-edu-lq-20BT': 'fw_edu_lq',
107
+ 'dclm-37BT': 'dclm', 'cosmopedia-25BT': 'cosmopedia'
108
+ };
109
+ function buildBaselineMacro(csvRows) {
110
+ const baselineRuns = new Set(Object.values(SOURCE_TO_BASELINE_RUN));
111
+ const best = {};
112
+ for (const row of csvRows) {
113
+ if (!baselineRuns.has(row.runname)) continue;
114
+ const step = +row.steps, score = +row.agg_score_macro;
115
+ if (!(row.runname in best) || step > best[row.runname][0]) best[row.runname] = [step, score];
116
+ }
117
+ const out = {};
118
+ for (const [src, run] of Object.entries(SOURCE_TO_BASELINE_RUN)) {
119
+ if (run in best) out[src] = best[run][1];
120
+ }
121
+ return out;
122
+ }
123
+
124
+ function fmtDelta(diff, base) {
125
+ const sign = diff >= 0 ? '+' : '';
126
+ const abs = `${sign}${diff.toFixed(3)}`;
127
+ if (base != null && base !== 0) {
128
+ const pct = (diff / base) * 100;
129
+ return `${abs} <span style="opacity:.5">(${pct >= 0 ? '+' : ''}${pct.toFixed(1)}%)</span>`;
130
+ }
131
+ return abs;
132
+ }
133
+
134
+ // Deterministic hash for per-book variation
135
+ function bookHash(id, salt) { return ((id * 2654435761 + (salt || 0)) >>> 0) / 4294967296; }
136
+
137
+ const tip = document.createElement('div');
138
+ tip.className = 'd3-tooltip';
139
+ container.appendChild(tip);
140
+
141
+ Promise.all([
142
+ fetchFirst(JSON_PATHS),
143
+ fetchFirst(CSV_PATHS, d3.csvParse)
144
+ ]).then(([raw, csvRows]) => {
145
+ const baselineMacro = buildBaselineMacro(csvRows);
146
+
147
+ const data = raw.map((d, i) => {
148
+ const [cat] = d.prompt.split('/');
149
+ const promptKey = toCanonicalPrompt(d.prompt);
150
+ const modelShort = d.model.split('/').pop();
151
+ const family = getFamily(d.model);
152
+ const aggMacro = d.results?.agg_score_macro;
153
+ const baseline = baselineMacro[d.source_dataset];
154
+ return {
155
+ id: i, model: modelShort, family,
156
+ prompt: PROMPT_LABELS[promptKey] || promptKey,
157
+ cat: CAT_MAP[cat] || cat,
158
+ source: SOURCE_MAP[d.source_dataset] || d.source_dataset,
159
+ outputTokens: d.output_tokens,
160
+ outputHuman: d.output_tokens_human,
161
+ inputHuman: d.input_tokens_human,
162
+ gpuSeconds: d.gpu_time_seconds,
163
+ gpuTime: gpuDays(d.gpu_time_seconds),
164
+ docsM: d.num_documents / 1e6,
165
+ dclm: d.dclm_score_difference, dclmBase: d.input_dclm_score,
166
+ edu: d.edu_score_difference, eduBase: d.input_edu_score,
167
+ aggDiff: (aggMacro != null && baseline != null) ? aggMacro - baseline : null,
168
+ aggBase: baseline
169
+ };
170
+ });
171
+
172
+ // Shuffle data deterministically so thick and thin books mix on every shelf
173
+ const shuffled = data.slice().sort((a, b) => bookHash(a.id, 42) - bookHash(b.id, 42));
174
+
175
+ const totalDocsM = data.reduce((s, d) => s + d.docsM, 0);
176
+ const numExperiments = data.length;
177
+
178
+ const families = [...new Set(data.map(d => d.family))].sort();
179
+ let familyColors;
180
+ if (window.ColorPalettes) {
181
+ const pal = window.ColorPalettes.getColors('categorical', families.length);
182
+ familyColors = {};
183
+ families.forEach((f, i) => { familyColors[f] = pal[i]; });
184
+ } else {
185
+ const fallback = { Gemma: '#5b9bd5', Qwen: '#e07b54', Llama: '#8bc474', Falcon: '#c9a046', Granite: '#9a8ec2', SmolLM2: '#e06b9e' };
186
+ familyColors = {};
187
+ families.forEach(f => { familyColors[f] = fallback[f] || '#888'; });
188
+ }
189
+
190
+ const render = () => {
191
+ const W = container.clientWidth || 900;
192
+ const H = container.clientHeight || 410;
193
+ const isDark = document.documentElement.getAttribute('data-theme') === 'dark';
194
+ container.querySelectorAll('svg').forEach(el => el.remove());
195
+
196
+ const svg = d3.select(container).append('svg')
197
+ .attr('width', W).attr('height', H)
198
+ .style('font-family', "'Inter', system-ui, -apple-system, sans-serif");
199
+
200
+ const defs = svg.append('defs');
201
+
202
+ // --- Wood colors ---
203
+ const wood = {
204
+ face: isDark ? '#3d2b1f' : '#c8a882',
205
+ faceLight: isDark ? '#4a3628' : '#d4b896',
206
+ edge: isDark ? '#2a1d14' : '#a08060',
207
+ edgeLight: isDark ? '#53392a' : '#b89870',
208
+ shadow: isDark ? 'rgba(0,0,0,0.5)' : 'rgba(0,0,0,0.12)',
209
+ grain: isDark ? 'rgba(255,255,255,0.03)' : 'rgba(0,0,0,0.04)',
210
  };
211
 
212
+ // --- Layout ---
213
+ const SHELVES = 4;
214
+ const sideW = Math.max(10, Math.min(W * 0.025, 24));
215
+ const shelfBoardH = Math.max(5, H * 0.018);
216
+ const topPad = H * 0.01;
217
+ const shelfZoneH = H * 0.86;
218
+ const bookPadX = Math.max(3, W * 0.006);
219
+ const shelfTotalH = shelfZoneH / SHELVES;
220
+ const bookAreaH = shelfTotalH - shelfBoardH;
221
+ // The bookshelf structure ends at the bottom of the last shelf board
222
+ const shelfBottom = topPad + SHELVES * shelfTotalH;
223
+
224
+ // --- Background ---
225
+ svg.append('rect').attr('width', W).attr('height', H)
226
+ .attr('fill', isDark ? '#111' : '#fff');
227
+
228
+ // --- Back panel (behind books) ---
229
+ const backPanelColor = isDark ? '#1e1518' : '#e8ddd0';
230
+ const panelH = shelfBottom - topPad;
231
+ svg.append('rect')
232
+ .attr('x', sideW).attr('y', topPad)
233
+ .attr('width', W - sideW * 2).attr('height', panelH)
234
+ .attr('fill', backPanelColor);
235
+
236
+ // --- Wood grain texture on back panel ---
237
+ const grainG = svg.append('g').style('pointer-events', 'none');
238
+ for (let i = 0; i < 12; i++) {
239
+ const gy = topPad + panelH * (i / 12) + bookHash(i, 99) * 8;
240
+ grainG.append('line')
241
+ .attr('x1', sideW).attr('x2', W - sideW)
242
+ .attr('y1', gy).attr('y2', gy + bookHash(i, 77) * 4 - 2)
243
+ .attr('stroke', wood.grain).attr('stroke-width', 0.5);
244
+ }
245
+
246
+ // --- Side panels (wooden verticals) ---
247
+ // Left panel
248
+ const leftGrad = defs.append('linearGradient')
249
+ .attr('id', 'side-l').attr('x1', '0%').attr('x2', '100%');
250
+ leftGrad.append('stop').attr('offset', '0%').attr('stop-color', wood.edge);
251
+ leftGrad.append('stop').attr('offset', '40%').attr('stop-color', wood.faceLight);
252
+ leftGrad.append('stop').attr('offset', '100%').attr('stop-color', wood.face);
253
+ svg.append('rect')
254
+ .attr('x', 0).attr('y', topPad)
255
+ .attr('width', sideW).attr('height', panelH)
256
+ .attr('fill', 'url(#side-l)');
257
+
258
+ // Right panel
259
+ const rightGrad = defs.append('linearGradient')
260
+ .attr('id', 'side-r').attr('x1', '0%').attr('x2', '100%');
261
+ rightGrad.append('stop').attr('offset', '0%').attr('stop-color', wood.face);
262
+ rightGrad.append('stop').attr('offset', '60%').attr('stop-color', wood.faceLight);
263
+ rightGrad.append('stop').attr('offset', '100%').attr('stop-color', wood.edge);
264
+ svg.append('rect')
265
+ .attr('x', W - sideW).attr('y', topPad)
266
+ .attr('width', sideW).attr('height', panelH)
267
+ .attr('fill', 'url(#side-r)');
268
+
269
+ // Inner edge shadows on side panels
270
+ svg.append('rect')
271
+ .attr('x', sideW).attr('y', topPad)
272
+ .attr('width', 2).attr('height', panelH)
273
+ .attr('fill', isDark ? 'rgba(0,0,0,0.3)' : 'rgba(0,0,0,0.08)');
274
+ svg.append('rect')
275
+ .attr('x', W - sideW - 2).attr('y', topPad)
276
+ .attr('width', 2).attr('height', panelH)
277
+ .attr('fill', isDark ? 'rgba(0,0,0,0.3)' : 'rgba(0,0,0,0.08)');
278
+
279
+ // Top trim
280
+ const topGrad = defs.append('linearGradient')
281
+ .attr('id', 'top-trim').attr('x1', '0%').attr('y1', '0%').attr('x2', '0%').attr('y2', '100%');
282
+ topGrad.append('stop').attr('offset', '0%').attr('stop-color', wood.edgeLight);
283
+ topGrad.append('stop').attr('offset', '100%').attr('stop-color', wood.face);
284
+ svg.append('rect')
285
+ .attr('x', 0).attr('y', topPad)
286
+ .attr('width', W).attr('height', Math.max(3, shelfBoardH * 0.6))
287
+ .attr('fill', 'url(#top-trim)');
288
+
289
+ // --- Area-based sizing: both width and height scale with tokens ---
290
+ const tokenExtent = d3.extent(data, d => d.outputTokens);
291
+ const wScale = d3.scaleLinear().domain([0, tokenExtent[1]]).range([0, 1]);
292
+ const hScale = d3.scaleLinear().domain(tokenExtent).range([0.76, 0.95]);
293
+
294
+ // Page-top perspective: we're looking from slightly above
295
+ const pageTopBase = Math.max(3, bookAreaH * 0.08); // default visible depth
296
+ const pageTopHover = Math.max(6, bookAreaH * 0.22); // deeper on hover
297
+ const pageInset = Math.max(1, bookAreaH * 0.008); // trapezoid inset
298
+
299
+ // --- Pack books onto shelves ---
300
+ const innerLeft = sideW + bookPadX;
301
+ const innerRight = W - sideW - bookPadX;
302
+ const availableW = innerRight - innerLeft;
303
+ const bookGap = Math.max(0.5, W * 0.001);
304
+
305
+ const totalRawUnits = shuffled.reduce((s, b) => s + wScale(b.outputTokens), 0);
306
+ const targetRawPerShelf = totalRawUnits / SHELVES;
307
+
308
+ const shelfGroups = [];
309
+ let curShelf = [], curRaw = 0;
310
+ for (const book of shuffled) {
311
+ const raw = wScale(book.outputTokens);
312
+ if (curShelf.length > 0 && curRaw + raw > targetRawPerShelf * 1.1 && shelfGroups.length < SHELVES - 1) {
313
+ shelfGroups.push(curShelf);
314
+ curShelf = [];
315
+ curRaw = 0;
316
+ }
317
+ curShelf.push(book);
318
+ curRaw += raw;
319
+ }
320
+ if (curShelf.length) shelfGroups.push(curShelf);
321
+
322
+ // Position books: width from tokens, height from tokens + small random jitter
323
+ const allLaid = shelfGroups.map((books, si) => {
324
+ const shelfTopY = topPad + si * shelfTotalH;
325
+ const rawWidths = books.map(b => wScale(b.outputTokens));
326
+ const totalRaw = rawWidths.reduce((s, w) => s + w, 0);
327
+ const totalGaps = (books.length - 1) * bookGap;
328
+ const scale = (availableW - totalGaps) / totalRaw;
329
+
330
+ let x = innerLeft;
331
+ // Reserve space at top for the page-top strip (even when hovered)
332
+ const pageReserve = pageTopHover;
333
+ const usableH = bookAreaH - pageReserve;
334
+ return books.map((book, bi) => {
335
+ const bw = rawWidths[bi] * scale;
336
+ const hFrac = hScale(book.outputTokens) + (bookHash(book.id, 3) - 0.5) * 0.05;
337
+ const bh = usableH * Math.min(0.95, Math.max(0.62, hFrac));
338
+ const by = shelfTopY + pageReserve + (usableH - bh);
339
+ const bx = x;
340
+ x += bw + bookGap;
341
+ return { ...book, bx, by, bw, bh, shelfTopY, shelfIdx: si };
342
+ });
343
+ });
344
+
345
+ const allBooks = allLaid.flat();
346
+
347
+ // --- Draw shelf boards ---
348
+ const numShelves = shelfGroups.length;
349
+ for (let si = 0; si < numShelves; si++) {
350
+ const boardY = topPad + si * shelfTotalH + bookAreaH;
351
+ const shelfGrad = defs.append('linearGradient')
352
+ .attr('id', `shelf-${si}`).attr('x1', '0%').attr('y1', '0%').attr('x2', '0%').attr('y2', '100%');
353
+ shelfGrad.append('stop').attr('offset', '0%').attr('stop-color', wood.edgeLight);
354
+ shelfGrad.append('stop').attr('offset', '30%').attr('stop-color', wood.faceLight);
355
+ shelfGrad.append('stop').attr('offset', '100%').attr('stop-color', wood.face);
356
+ svg.append('rect')
357
+ .attr('x', 0).attr('y', boardY)
358
+ .attr('width', W).attr('height', shelfBoardH)
359
+ .attr('fill', `url(#shelf-${si})`);
360
+ // Front edge highlight
361
+ svg.append('rect')
362
+ .attr('x', 0).attr('y', boardY)
363
+ .attr('width', W).attr('height', 1)
364
+ .attr('fill', isDark ? 'rgba(255,255,255,0.06)' : 'rgba(255,255,255,0.35)');
365
+ // Bottom shadow
366
+ const shGrad = defs.append('linearGradient')
367
+ .attr('id', `shsh-${si}`).attr('x1', '0%').attr('y1', '0%').attr('x2', '0%').attr('y2', '100%');
368
+ shGrad.append('stop').attr('offset', '0%').attr('stop-color', wood.shadow);
369
+ shGrad.append('stop').attr('offset', '100%').attr('stop-color', 'transparent');
370
+ svg.append('rect')
371
+ .attr('x', sideW).attr('y', boardY + shelfBoardH)
372
+ .attr('width', W - sideW * 2).attr('height', Math.max(4, shelfTotalH * 0.06))
373
+ .attr('fill', `url(#shsh-${si})`);
374
+ }
375
+
376
+ // --- SVG filters ---
377
+ // Subtle cloth/leather texture overlay
378
+ const texFilter = defs.append('filter')
379
+ .attr('id', 'book-tex').attr('x', '0%').attr('y', '0%')
380
+ .attr('width', '100%').attr('height', '100%');
381
+ texFilter.append('feTurbulence')
382
+ .attr('type', 'fractalNoise').attr('baseFrequency', '0.8 0.5')
383
+ .attr('numOctaves', 4).attr('seed', 7).attr('result', 'noise');
384
+ texFilter.append('feColorMatrix')
385
+ .attr('in', 'noise').attr('type', 'saturate').attr('values', '0').attr('result', 'gray');
386
+ texFilter.append('feBlend')
387
+ .attr('in', 'SourceGraphic').attr('in2', 'gray')
388
+ .attr('mode', isDark ? 'soft-light' : 'overlay')
389
+ .attr('result', 'textured');
390
+ texFilter.append('feComposite')
391
+ .attr('in', 'textured').attr('in2', 'SourceGraphic').attr('operator', 'in');
392
+
393
+ // Drop shadow for pulled-out books
394
+ const pullShadow = defs.append('filter')
395
+ .attr('id', 'book-shadow').attr('x', '-10%').attr('y', '-10%')
396
+ .attr('width', '130%').attr('height', '140%');
397
+ pullShadow.append('feDropShadow')
398
+ .attr('dx', 0).attr('dy', 3)
399
+ .attr('stdDeviation', 3)
400
+ .attr('flood-color', 'rgba(0,0,0,0.35)');
401
+
402
+ // --- Per-book rounded spine gradients ---
403
+ allBooks.forEach(d => {
404
+ const c = familyColors[d.family];
405
+ const grad = defs.append('linearGradient')
406
+ .attr('id', `spine-${d.id}`).attr('x1', '0%').attr('x2', '100%');
407
+ grad.append('stop').attr('offset', '0%').attr('stop-color', d3.color(c).darker(0.6));
408
+ grad.append('stop').attr('offset', '30%').attr('stop-color', d3.color(c).brighter(0.15));
409
+ grad.append('stop').attr('offset', '55%').attr('stop-color', d3.color(c).brighter(0.25));
410
+ grad.append('stop').attr('offset', '100%').attr('stop-color', d3.color(c).darker(0.8));
411
+ });
412
+
413
+ // --- Draw books ---
414
+ const gBooks = svg.append('g');
415
+
416
+ const bookGroups = gBooks.selectAll('g.book')
417
+ .data(allBooks, d => d.id)
418
+ .join('g')
419
+ .attr('class', 'book');
420
+
421
+ // Page-top colors
422
+ const pageColor = isDark ? '#968672' : '#d8ccb2';
423
+ const pageLineColor = isDark ? 'rgba(0,0,0,0.18)' : 'rgba(0,0,0,0.10)';
424
+ const pageEdgeColor = isDark ? 'rgba(80,60,40,0.5)' : 'rgba(0,0,0,0.15)';
425
+
426
+ // Fixed cover thickness (same for every book)
427
+ const coverW = Math.max(2, W * 0.003);
428
+
429
+ bookGroups.each(function(d) {
430
+ const g = d3.select(this);
431
+ const h2 = bookHash(d.id, 2);
432
+ const h3 = bookHash(d.id, 5);
433
+
434
+ const coverColor = familyColors[d.family];
435
+ const coverDark = d3.color(coverColor).darker(0.4);
436
+
437
+ // Page-top strip: always visible (top-down perspective)
438
+ const pagesG = g.append('g').attr('class', 'book-pages');
439
+ const pth = pageTopBase;
440
+ // Pages trapezoid (cream, between the two covers)
441
+ const pts = [
442
+ [d.bx + coverW, d.by],
443
+ [d.bx + d.bw - coverW, d.by],
444
+ [d.bx + d.bw - coverW - pageInset, d.by - pth],
445
+ [d.bx + coverW + pageInset, d.by - pth]
446
+ ];
447
+ pagesG.append('polygon')
448
+ .attr('class', 'page-face')
449
+ .attr('points', pts.map(p => p.join(',')).join(' '))
450
+ .attr('fill', pageColor);
451
+ // Vertical page-edge lines
452
+ const pageW = d.bw - coverW * 2;
453
+ const nLines = Math.max(3, Math.round(pageW / 1.5));
454
+ for (let li = 0; li < nLines; li++) {
455
+ const xFrac = (li + 0.5) / nLines;
456
+ const lx = d.bx + coverW + pageW * xFrac;
457
+ pagesG.append('line')
458
+ .attr('class', 'page-line')
459
+ .attr('x1', lx).attr('x2', lx)
460
+ .attr('y1', d.by).attr('y2', d.by - pth)
461
+ .attr('stroke', pageLineColor).attr('stroke-width', 0.4);
462
+ }
463
+ // Left cover on page-top (trapezoid in book color)
464
+ pagesG.append('polygon')
465
+ .attr('class', 'cover-left')
466
+ .attr('points', [
467
+ [d.bx, d.by], [d.bx + coverW, d.by],
468
+ [d.bx + coverW + pageInset, d.by - pth], [d.bx + pageInset, d.by - pth]
469
+ ].map(p => p.join(',')).join(' '))
470
+ .attr('fill', coverDark);
471
+ // Right cover on page-top
472
+ pagesG.append('polygon')
473
+ .attr('class', 'cover-right')
474
+ .attr('points', [
475
+ [d.bx + d.bw - coverW, d.by], [d.bx + d.bw, d.by],
476
+ [d.bx + d.bw - pageInset, d.by - pth], [d.bx + d.bw - coverW - pageInset, d.by - pth]
477
+ ].map(p => p.join(',')).join(' '))
478
+ .attr('fill', coverDark);
479
+ // Front edge
480
+ pagesG.append('line')
481
+ .attr('class', 'page-edge')
482
+ .attr('x1', d.bx).attr('x2', d.bx + d.bw)
483
+ .attr('y1', d.by).attr('y2', d.by)
484
+ .attr('stroke', pageEdgeColor).attr('stroke-width', 1);
485
+
486
+ // Spine sub-group
487
+ const spine = g.append('g').attr('class', 'book-spine');
488
+
489
+ // Main spine body with rounded gradient + texture
490
+ spine.append('rect')
491
+ .attr('class', 'book-rect')
492
+ .attr('x', d.bx).attr('y', d.by)
493
+ .attr('width', d.bw).attr('height', d.bh)
494
+ .attr('rx', 0.5)
495
+ .attr('fill', `url(#spine-${d.id})`)
496
+ .attr('filter', 'url(#book-tex)');
497
+
498
+ // Cardboard cover edges on spine (left and right)
499
+ spine.append('rect')
500
+ .attr('x', d.bx).attr('y', d.by)
501
+ .attr('width', coverW).attr('height', d.bh)
502
+ .attr('fill', coverDark)
503
+ .style('pointer-events', 'none');
504
+ spine.append('rect')
505
+ .attr('x', d.bx + d.bw - coverW).attr('y', d.by)
506
+ .attr('width', coverW).attr('height', d.bh)
507
+ .attr('fill', coverDark)
508
+ .style('pointer-events', 'none');
509
+
510
+ // Spine groove lines
511
+ if (d.bw > 6) {
512
+ const grooveOff = d.bw * (0.12 + h2 * 0.06);
513
+ const grooveColor = isDark ? 'rgba(0,0,0,0.2)' : 'rgba(0,0,0,0.1)';
514
+ [grooveOff, d.bw - grooveOff].forEach(gx => {
515
+ spine.append('line')
516
+ .attr('x1', d.bx + gx).attr('x2', d.bx + gx)
517
+ .attr('y1', d.by + 1).attr('y2', d.by + d.bh - 1)
518
+ .attr('stroke', grooveColor).attr('stroke-width', 0.5)
519
+ .style('pointer-events', 'none');
520
+ });
521
+ }
522
+
523
+ // Headband + tailband
524
+ const headbandH = Math.max(1.5, d.bh * 0.02);
525
+ spine.append('rect')
526
+ .attr('x', d.bx + 0.5).attr('y', d.by + 0.5)
527
+ .attr('width', d.bw - 1).attr('height', headbandH)
528
+ .attr('fill', isDark ? 'rgba(255,255,255,0.15)' : 'rgba(255,255,255,0.4)')
529
+ .style('pointer-events', 'none');
530
+ spine.append('rect')
531
+ .attr('x', d.bx + 0.5).attr('y', d.by + d.bh - headbandH - 0.5)
532
+ .attr('width', d.bw - 1).attr('height', headbandH)
533
+ .attr('fill', isDark ? 'rgba(255,255,255,0.08)' : 'rgba(255,255,255,0.25)')
534
+ .style('pointer-events', 'none');
535
+
536
+ // Two decorative horizontal bands
537
+ if (d.bw > 8) {
538
+ const bandH = Math.max(1.5, d.bh * 0.04);
539
+ const upperY = d.by + d.bh * (0.22 + h3 * 0.08);
540
+ const lowerY = d.by + d.bh * (0.70 + h2 * 0.08);
541
+ const bandFill = isDark ? 'rgba(255,255,255,0.10)' : 'rgba(0,0,0,0.07)';
542
+ [upperY, lowerY].forEach(yy => {
543
+ spine.append('rect')
544
+ .attr('x', d.bx + 1).attr('y', yy)
545
+ .attr('width', d.bw - 2).attr('height', bandH)
546
+ .attr('fill', bandFill).style('pointer-events', 'none');
547
+ });
548
+ }
549
+
550
+ // Gilt/embossed spine text
551
+ if (d.bw >= 16) {
552
+ const fontSize = Math.min(d.bw * 0.42, 10, d.bh * 0.055);
553
+ if (fontSize >= 5) {
554
+ const maxLen = Math.floor(d.bh / (fontSize * 0.65));
555
+ const label = d.model;
556
+ const text = label.length > maxLen ? label.slice(0, maxLen - 1) + '\u2026' : label;
557
+ const tx = d.bx + d.bw / 2;
558
+ const ty = d.by + d.bh * 0.52;
559
+ const rot = `rotate(-90, ${tx}, ${ty})`;
560
+ spine.append('text')
561
+ .attr('x', tx + 0.5).attr('y', ty + 0.8)
562
+ .attr('text-anchor', 'middle').attr('dominant-baseline', 'middle')
563
+ .attr('transform', rot)
564
+ .attr('fill', isDark ? 'rgba(0,0,0,0.45)' : 'rgba(0,0,0,0.2)')
565
+ .attr('font-size', fontSize).attr('font-weight', 700)
566
+ .attr('letter-spacing', '0.03em')
567
+ .style('pointer-events', 'none')
568
+ .text(text);
569
+ spine.append('text')
570
+ .attr('x', tx).attr('y', ty)
571
+ .attr('text-anchor', 'middle').attr('dominant-baseline', 'middle')
572
+ .attr('transform', rot)
573
+ .attr('fill', isDark ? '#d4b87a' : '#8b7340')
574
+ .attr('fill-opacity', isDark ? 0.75 : 0.65)
575
+ .attr('font-size', fontSize).attr('font-weight', 700)
576
+ .attr('letter-spacing', '0.03em')
577
+ .style('pointer-events', 'none')
578
+ .text(text);
579
  }
580
+ }
581
+ });
582
+
583
+ // --- Tilt transform: compress spine Y from bottom to simulate tilting forward ---
584
+ const tiltSy = 0.75;
585
+ function tiltTransform(d) {
586
+ const cx = d.bx + d.bw / 2;
587
+ const bot = d.by + d.bh;
588
+ return `translate(${cx}, ${bot}) scale(1, ${tiltSy}) translate(${-cx}, ${-bot})`;
589
+ }
590
+ // Where the compressed spine top ends up
591
+ function tiltedSpineTop(d) {
592
+ return d.by + d.bh - d.bh * tiltSy;
593
+ }
594
+
595
+ // --- Hover helpers: tilt spine + expand page-top ---
596
+ function updatePageTop(el, d, baseY, depth) {
597
+ const pg = el.select('.book-pages');
598
+ const cw = coverW;
599
+ // Pages (cream area between covers)
600
+ pg.select('.page-face').transition().duration(200)
601
+ .attr('points', [
602
+ [d.bx + cw, baseY], [d.bx + d.bw - cw, baseY],
603
+ [d.bx + d.bw - cw - pageInset, baseY - depth],
604
+ [d.bx + cw + pageInset, baseY - depth]
605
+ ].map(p => p.join(',')).join(' '));
606
+ // Left cover
607
+ pg.select('.cover-left').transition().duration(200)
608
+ .attr('points', [
609
+ [d.bx, baseY], [d.bx + cw, baseY],
610
+ [d.bx + cw + pageInset, baseY - depth], [d.bx + pageInset, baseY - depth]
611
+ ].map(p => p.join(',')).join(' '));
612
+ // Right cover
613
+ pg.select('.cover-right').transition().duration(200)
614
+ .attr('points', [
615
+ [d.bx + d.bw - cw, baseY], [d.bx + d.bw, baseY],
616
+ [d.bx + d.bw - pageInset, baseY - depth], [d.bx + d.bw - cw - pageInset, baseY - depth]
617
+ ].map(p => p.join(',')).join(' '));
618
+ // Vertical page lines
619
+ pg.selectAll('line.page-line').each(function() {
620
+ d3.select(this).transition().duration(200)
621
+ .attr('y1', baseY).attr('y2', baseY - depth);
622
+ });
623
+ pg.select('line.page-edge').transition().duration(200)
624
+ .attr('y1', baseY).attr('y2', baseY);
625
+ }
626
+
627
+ function hoverIn(sel) {
628
+ sel.each(function(d) {
629
+ const el = d3.select(this);
630
+ el.raise();
631
+ el.select('.book-spine')
632
+ .transition().duration(200)
633
+ .attr('transform', tiltTransform(d))
634
+ .attr('filter', 'url(#book-shadow)');
635
+ updatePageTop(el, d, tiltedSpineTop(d), pageTopHover);
636
+ });
637
+ }
638
+
639
+ function hoverOut(sel) {
640
+ sel.each(function(d) {
641
+ const el = d3.select(this);
642
+ el.select('.book-spine')
643
+ .transition().duration(200)
644
+ .attr('transform', null)
645
+ .attr('filter', null);
646
+ updatePageTop(el, d, d.by, pageTopBase);
647
+ });
648
+ }
649
+
650
+ // --- Overlay text ---
651
+ const cx = W / 2;
652
+ const megaFS = Math.min(W * 0.10, H * 0.18, 100);
653
+ const megaY = topPad + shelfZoneH * 0.44;
654
+ const noPtr = el => el.style('pointer-events', 'none');
655
+
656
+ noPtr(svg.append('text')
657
+ .attr('class', 'overlay-text')
658
+ .attr('x', cx).attr('y', megaY)
659
+ .attr('text-anchor', 'middle').attr('dominant-baseline', 'middle')
660
+ .attr('fill', isDark ? 'rgba(255,255,255,0.88)' : 'rgba(26,26,26,0.88)')
661
+ .attr('font-size', megaFS).attr('font-weight', 900)
662
+ .attr('letter-spacing', '-0.04em')
663
+ .text('1T+'));
664
+
665
+ const labelFS = Math.max(9, megaFS * 0.14);
666
+ noPtr(svg.append('text')
667
+ .attr('class', 'overlay-text')
668
+ .attr('x', cx).attr('y', megaY + megaFS * 0.46)
669
+ .attr('text-anchor', 'middle').attr('dominant-baseline', 'middle')
670
+ .attr('fill', isDark ? 'rgba(255,255,255,0.45)' : 'rgba(0,0,0,0.4)')
671
+ .attr('font-size', labelFS).attr('font-weight', 600)
672
+ .attr('letter-spacing', '0.18em')
673
+ .text('TOKENS REPHRASED'));
674
+
675
+ // --- Bottom zone: stats + legend ---
676
+ const bottomY = shelfBottom;
677
+ const bottomH = H - bottomY;
678
+
679
+ const subFS = Math.max(8, Math.min(11, W * 0.011));
680
+ const totalDocsB = (totalDocsM / 1000).toFixed(2);
681
+ noPtr(svg.append('text')
682
+ .attr('class', 'overlay-text')
683
+ .attr('x', cx).attr('y', bottomY + bottomH * 0.32)
684
+ .attr('text-anchor', 'middle').attr('dominant-baseline', 'middle')
685
+ .attr('fill', isDark ? 'rgba(255,255,255,0.4)' : 'rgba(0,0,0,0.38)')
686
+ .attr('font-size', subFS).attr('font-weight', 500)
687
+ .attr('letter-spacing', '0.14em')
688
+ .text(`${numExperiments} EXPERIMENTS \u00B7 ${totalDocsB}B DOCUMENTS`));
689
+
690
+ // Legend
691
+ const familyCounts = {};
692
+ data.forEach(d => { familyCounts[d.family] = (familyCounts[d.family] || 0) + 1; });
693
+ const sortedFamilies = Object.entries(familyCounts).sort((a, b) => b[1] - a[1]);
694
+ const legFS = Math.max(9, Math.min(12, W * 0.012));
695
+ const dotR = Math.max(3, legFS * 0.38);
696
+ const legY = bottomY + bottomH * 0.7;
697
+
698
+ const legG = svg.append('g');
699
+ let tw = 0;
700
+ sortedFamilies.forEach(([fam, count]) => {
701
+ tw += dotR * 2 + 4 + (fam.length + String(count).length + 3) * legFS * 0.55 + 14;
702
+ });
703
+ tw -= 14;
704
+ let lx = cx - tw / 2;
705
+
706
+ sortedFamilies.forEach(([fam, count]) => {
707
+ const ig = legG.append('g').style('cursor', 'pointer');
708
+ ig.append('circle')
709
+ .attr('cx', lx + dotR).attr('cy', legY)
710
+ .attr('r', dotR).attr('fill', familyColors[fam]).attr('fill-opacity', 0.7);
711
+ const t = ig.append('text')
712
+ .attr('x', lx + dotR * 2 + 4).attr('y', legY)
713
+ .attr('dominant-baseline', 'middle')
714
+ .attr('fill', isDark ? 'rgba(255,255,255,0.5)' : 'rgba(0,0,0,0.45)')
715
+ .attr('font-size', legFS).attr('font-weight', 500)
716
+ .text(`${fam} (${count})`);
717
+
718
+ ig.on('mouseenter', () => {
719
+ gBooks.selectAll('g.book').each(function(d) {
720
+ if (d.family === fam) hoverIn(d3.select(this));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
721
  });
722
+ }).on('mouseleave', () => {
723
+ gBooks.selectAll('g.book').each(function(d) {
724
+ if (d.family === fam) hoverOut(d3.select(this));
725
+ });
726
+ });
727
+
728
+ lx += dotR * 2 + 4 + t.node().getComputedTextLength() + 14;
729
+ });
730
+
731
+ // --- Hover: tilt book forward + reveal more page-top + tooltip ---
732
+ bookGroups
733
+ .on('mouseenter', function(event, d) {
734
+ const g = d3.select(this);
735
+ hoverIn(g);
736
+
737
+ const c = familyColors[d.family];
738
+ const dc = d.dclm >= 0 ? '#16a34a' : '#dc2626';
739
+ const ec = d.edu >= 0 ? '#16a34a' : '#dc2626';
740
+ const ac = d.aggDiff != null ? (d.aggDiff >= 0 ? '#16a34a' : '#dc2626') : null;
741
+ const aggRow = d.aggDiff != null
742
+ ? `<span style="opacity:.35">\u0394 Macro</span><span style="color:${ac}">${fmtDelta(d.aggDiff, d.aggBase)}</span>` : '';
743
+
744
+ tip.innerHTML =
745
+ `<div style="display:flex;align-items:center;gap:6px;margin-bottom:4px">` +
746
+ `<span style="width:8px;height:8px;border-radius:50%;background:${c};display:inline-block"></span>` +
747
+ `<span style="font-weight:700;font-size:1.05em;color:var(--text-color)">${d.model}</span></div>` +
748
+ `<div style="opacity:.4;font-size:.88em;margin-bottom:7px">${d.prompt} \u00B7 ${d.cat} \u00B7 ${d.source}</div>` +
749
+ `<div style="display:grid;grid-template-columns:auto 1fr;gap:3px 14px;font-size:.9em">` +
750
+ `<span style="opacity:.35">Output</span><span style="font-weight:600;color:var(--text-color)">${d.outputHuman} tokens</span>` +
751
+ `<span style="opacity:.35">Input</span><span>${d.inputHuman}</span>` +
752
+ `<span style="opacity:.35">GPU time</span><span>${d.gpuTime}</span>` +
753
+ `<span style="opacity:.35">Docs</span><span>${d.docsM.toFixed(1)}M</span>` +
754
+ `<span style="opacity:.35">DCLM</span><span style="color:${dc}">${fmtDelta(d.dclm, d.dclmBase)}</span>` +
755
+ `<span style="opacity:.35">Edu</span><span style="color:${ec}">${fmtDelta(d.edu, d.eduBase)}</span>` +
756
+ aggRow + `</div>`;
757
+ tip.style.opacity = '1';
758
+ })
759
+ .on('mousemove', function(event) {
760
+ const r = container.getBoundingClientRect();
761
+ let tx = event.clientX - r.left + 14;
762
+ let ty = event.clientY - r.top - 10;
763
+ if (tx + 280 > W) tx = event.clientX - r.left - 290;
764
+ if (ty < 8) ty = 8;
765
+ tip.style.left = tx + 'px';
766
+ tip.style.top = ty + 'px';
767
+ })
768
+ .on('mouseleave', function() {
769
+ hoverOut(d3.select(this));
770
+ tip.style.opacity = '0';
771
+ });
772
+ };
773
+
774
+ if (window.ResizeObserver) {
775
+ new ResizeObserver(() => render()).observe(container);
776
+ } else {
777
+ window.addEventListener('resize', render);
778
+ }
779
+ render();
780
+
781
+ new MutationObserver(() => render()).observe(
782
+ document.documentElement, { attributes: true, attributeFilter: ['data-theme'] }
783
+ );
784
+ }).catch(err => {
785
+ container.innerHTML = `<pre style="color:red;padding:12px">${err.message}</pre>`;
786
+ });
787
+ };
788
+
789
+ if (document.readyState === 'loading') {
790
+ document.addEventListener('DOMContentLoaded', () => ensureD3(bootstrap), { once: true });
791
+ } else { ensureD3(bootstrap); }
792
+ })();
793
  </script>