cascade-lab / index.html
vin268's picture
site update
a4f42e8 verified
Raw History Blame Contribute Delete
23.7 kB
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
<title>Cascade Research Lab</title>
<meta name="description" content="A live crypto liquidation recorder and an open research notebook on liquidation cascades.">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;500&family=IBM+Plex+Sans+Condensed:wght@500;600&family=IBM+Plex+Sans:wght@400;500&display=swap">
<style>
/* One reading column: live recorder first (what is running now), then the
studies and their gates, then the dated notebook. */
:root {
--paper: #f6f7f9; --panel: #ffffff; --ink: #141820; --ink-2: #4f5866; --rule: #dde1e8;
--accent: #2147c4; --accent-soft: #e6ecfb;
--long: #c2412d; --short: #14806b; --ok: #18684a; --warn: #8a5300;
--k-pre: #2147c4; --k-pre-bg: #e6ecfb; --k-caught: #8a5300; --k-caught-bg: #fbefd9;
--k-null: #5b3fa6; --k-null-bg: #efe9fb; --k-find: #18684a; --k-find-bg: #e2f3ea;
--k-plain: #4f5866; --k-plain-bg: #eceef2;
--display: "IBM Plex Sans Condensed", "Arial Narrow", system-ui, sans-serif;
--body: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
--mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Consolas, monospace;
color-scheme: light;
}
@media (prefers-color-scheme: dark) {
:root {
--paper: #0f1217; --panel: #161b22; --ink: #e6e9ee; --ink-2: #9ba4b1; --rule: #2a313b;
--accent: #8aa6ff; --accent-soft: #1d2840; --long: #f08a70; --short: #5fd1b5; --ok: #6fd1a2; --warn: #f0b75c;
--k-pre: #8aa6ff; --k-pre-bg: #1d2840; --k-caught: #f0b75c; --k-caught-bg: #3a2c12;
--k-null: #b9a4f5; --k-null-bg: #2a2340; --k-find: #6fd1a2; --k-find-bg: #15302a;
--k-plain: #9ba4b1; --k-plain-bg: #222831;
color-scheme: dark;
}
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--paper); color: var(--ink); font: 400 16px/1.6 var(--body); }
.page { max-width: 56rem; margin: 0 auto; padding-block: 48px 64px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); display: grid; gap: 56px; }
.mono { font-family: var(--mono); font-size: 13px; }
h1, h2, h3 { text-wrap: balance; margin: 0; }
h2 { font: 600 24px/1.2 var(--display); letter-spacing: .01em; }
h3 { font: 500 17px/1.35 var(--body); }
p { margin: 0; }
a { color: var(--accent); text-underline-offset: 3px; }
a:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.note { color: var(--ink-2); max-width: 64ch; }
.section-head { display: grid; gap: 8px; margin-bottom: 20px; }
.hero { display: grid; gap: 16px; }
.eyebrow { color: var(--ink-2); text-transform: uppercase; letter-spacing: .08em; font-size: 12px; }
.hero h1 { font: 600 clamp(30px, 5.2vw, 46px)/1.08 var(--display); max-width: 22ch; }
.summary { font-size: 18px; color: var(--ink-2); max-width: 60ch; }
/* live panel */
.live { background: var(--panel); border: 1px solid var(--rule); border-radius: 6px; padding: 24px; display: grid; gap: 20px; }
.live-head { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; justify-content: space-between; }
.pill { display: inline-flex; align-items: center; gap: 8px; font: 500 13px/1 var(--mono); padding: 6px 10px; border-radius: 999px; border: 1px solid var(--rule); }
.pill i { width: 8px; height: 8px; border-radius: 50%; background: var(--ink-2); }
.pill.on i { background: var(--ok); }
.pill.stale i { background: var(--warn); }
.figs { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 9.5rem), 1fr)); gap: 16px; }
.fig { display: grid; gap: 2px; align-content: start; }
.fig .lab { font-size: 13px; color: var(--ink-2); }
.fig .val { font: 500 26px/1.15 var(--display); font-variant-numeric: tabular-nums; }
.fig .sub { font: 400 12px/1.3 var(--mono); color: var(--ink-2); }
.val.long { color: var(--long); } .val.short { color: var(--short); }
.chart { position: relative; min-height: 220px; }
.chart svg { display: block; width: 100%; height: auto; }
.legend { display: flex; flex-wrap: wrap; gap: 8px 20px; font-size: 13px; color: var(--ink-2); }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }
.tip { position: absolute; pointer-events: none; background: var(--panel); border: 1px solid var(--rule); border-radius: 4px; padding: 6px 10px; font-size: 12px; white-space: nowrap; box-shadow: 0 2px 8px rgba(0,0,0,.12); }
.two { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 20rem), 1fr)); gap: 24px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
th, td { padding: 6px 8px; text-align: right; border-bottom: 1px solid var(--rule); white-space: nowrap; }
th { color: var(--ink-2); font-weight: 500; font-size: 13px; }
th:first-child, td:first-child { text-align: left; }
.scroll { overflow-x: auto; }
.caveat { font-size: 13px; color: var(--ink-2); }
.empty { color: var(--ink-2); font-size: 14px; }
/* studies */
.studies { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.study { background: var(--panel); border: 1px solid var(--rule); border-radius: 6px; padding: 20px; display: grid; grid-template-columns: 3.25rem minmax(0, 1fr); gap: 4px 16px; }
.study.is-planned { background: transparent; }
.study-id { font: 500 22px/1.2 var(--mono); color: var(--ink-2); }
.study.is-active .study-id { color: var(--accent); }
.study-main { display: grid; gap: 12px; min-width: 0; }
.study .q { color: var(--ink-2); max-width: 66ch; }
.track { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 4px; }
.seg { display: grid; gap: 6px; }
.seg i { display: block; height: 4px; border-radius: 2px; background: var(--rule); }
.seg.done i { background: var(--accent); }
.seg.next i { background: transparent; box-shadow: inset 0 0 0 1px var(--accent); }
.seg span { font: 400 11px/1.3 var(--mono); color: var(--ink-2); overflow-wrap: anywhere; }
.seg.done span, .seg.next span { color: var(--ink); }
@media (max-width: 34rem) { .seg span { display: none; } .seg.next span { display: block; } }
.headline { margin: 0; padding: 0; list-style: none; display: grid; gap: 6px; }
.headline li { padding-left: 16px; position: relative; }
.headline li::before { content: ""; position: absolute; left: 0; top: .62em; width: 7px; height: 7px; border-radius: 50%; background: var(--k-find); }
.study-foot { display: flex; flex-wrap: wrap; gap: 8px 20px; align-items: baseline; }
.status { color: var(--ink-2); font-size: 14px; }
.study-links { display: flex; flex-wrap: wrap; gap: 8px 16px; font-size: 14px; }
/* notebook */
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.chip { font: 400 13px/1 var(--mono); padding: 7px 12px; border-radius: 999px; border: 1px solid var(--rule); background: transparent; color: var(--ink); cursor: pointer; }
.chip[aria-pressed="true"] { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.log { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--rule); }
.entry { display: grid; grid-template-columns: 11rem minmax(0, 1fr); gap: 4px 24px; padding-block: 18px; border-bottom: 1px solid var(--rule); }
.entry time { color: var(--ink-2); padding-top: 2px; }
.entry-main { display: grid; gap: 6px; min-width: 0; }
.meta { display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: center; }
.kind { font: 500 12px/1 var(--mono); padding: 5px 8px; border-radius: 4px; color: var(--k-plain); background: var(--k-plain-bg); }
.kind[data-k="Pre-registration"] { color: var(--k-pre); background: var(--k-pre-bg); }
.kind[data-k="Caught"] { color: var(--k-caught); background: var(--k-caught-bg); }
.kind[data-k="Null result"] { color: var(--k-null); background: var(--k-null-bg); }
.kind[data-k="Finding"] { color: var(--k-find); background: var(--k-find-bg); }
.meta .mono { color: var(--ink-2); }
.entry p { color: var(--ink-2); max-width: 66ch; }
@media (max-width: 40rem) { .entry { grid-template-columns: minmax(0, 1fr); } }
.foot { border-top: 1px solid var(--rule); padding-top: 16px; color: var(--ink-2); font-size: 14px; display: grid; gap: 4px; }
</style>
</head>
<body>
<main class="page">
<header class="hero">
<p class="eyebrow mono">Open research notebook</p>
<h1 id="focus">Liquidation cascades in crypto</h1>
<p class="summary" id="summary"></p>
</header>
<section id="live" aria-labelledby="live-h">
<div class="section-head">
<h2 id="live-h">Live: liquidation recorder</h2>
<p class="note">Every liquidation order Binance pushes on its USD-M perpetual futures, all symbols, plus open interest for five large coins every minute. Aggregated each hour and published to a public dataset.</p>
</div>
<div class="live">
<div class="live-head">
<span class="pill" id="pill"><i></i><span id="pill-text">Loading</span></span>
<span class="mono" id="updated"></span>
</div>
<div class="figs">
<div class="fig"><span class="lab">Liquidations, last 24 h</span><span class="val" id="f-n">—</span><span class="sub" id="f-n-sub"></span></div>
<div class="fig"><span class="lab">Longs liquidated</span><span class="val long" id="f-long">—</span><span class="sub">sell orders</span></div>
<div class="fig"><span class="lab">Shorts liquidated</span><span class="val short" id="f-short">—</span><span class="sub">buy orders</span></div>
<div class="fig"><span class="lab">Largest single</span><span class="val" id="f-big">—</span><span class="sub" id="f-big-sub"></span></div>
<div class="fig"><span class="lab">Recorder coverage, 24 h</span><span class="val" id="f-cov">—</span><span class="sub" id="f-cov-sub"></span></div>
</div>
<div>
<div class="chart" id="chart"></div>
<div class="legend"><span><span class="sw" style="background: var(--long)"></span>Longs liquidated (USD, up)</span><span><span class="sw" style="background: var(--short)"></span>Shorts liquidated (USD, down)</span><span>Faded bars: the recorder was connected for less than the full hour</span></div>
</div>
<div class="two">
<div>
<h3>Most liquidated, last 24 h</h3>
<div class="scroll"><table><thead><tr><th>Symbol</th><th>Orders</th><th>USD</th><th>Longs</th></tr></thead><tbody id="top"></tbody></table></div>
</div>
<div>
<h3>Open interest, change over 24 h</h3>
<div class="scroll"><table><thead><tr><th>Coin</th><th>Change</th></tr></thead><tbody id="oi"></tbody></table></div>
</div>
</div>
<p class="caveat">Binance pushes at most one liquidation per symbol per second, so counts and USD values are lower bounds when liquidations cluster. Research only; nothing here is investment advice.</p>
</div>
</section>
<section id="studies" aria-labelledby="studies-h">
<div class="section-head">
<h2 id="studies-h">Studies</h2>
<p class="note">Six studies, worked through in order, from what happens in a cascade to a paper-trading forward test. Each must pass its gate before the next step; failures are published too.</p>
</div>
<ol class="studies" id="study-list"><li class="empty">Loading the studies…</li></ol>
</section>
<section id="notebook" aria-labelledby="notebook-h">
<div class="section-head">
<h2 id="notebook-h">Lab notebook</h2>
<p class="note">Dated entries as the work happens, including the bugs caught and the tests that failed.</p>
</div>
<div class="filters" id="filters" role="group" aria-label="Filter by study"></div>
<ol class="log" id="log"></ol>
</section>
<footer class="foot">
<span>Every number on this page is read from the public ledger, <a id="ledger-link" href="#" target="_blank" rel="noopener">a Hugging Face dataset</a>. Each hourly update is a commit, so its history is the project's timestamped record.</span>
<span>Data: Binance USD-M futures public market data. Charts and code are the project's own.</span>
</footer>
</main>
<script>
(() => {
const DATASET = 'vin268/cascade-lab-ledger';
const onHub = /(\.hf\.space|huggingface\.co)$/.test(location.hostname);
const BASE = onHub ? `https://huggingface.co/datasets/${DATASET}/resolve/main` : './data';
document.getElementById('ledger-link').href = `https://huggingface.co/datasets/${DATASET}`;
const $ = (id) => document.getElementById(id);
const el = (tag, cls, text) => { const e = document.createElement(tag); if (cls) e.className = cls; if (text != null) e.textContent = text; return e; };
const link = (href, text) => { const a = el('a', null, text); a.href = href; a.target = '_blank'; a.rel = 'noopener'; return a; };
const usd = (v) => v >= 1e6 ? '$' + (v / 1e6).toFixed(2) + 'm' : v >= 1e3 ? '$' + (v / 1e3).toFixed(1) + 'k' : '$' + Math.round(v);
const pct = (v) => (v > 0 ? '+' : v < 0 ? '−' : '') + Math.abs(v).toFixed(2) + '%';
const fmtDay = (iso) => new Date(iso.length === 10 ? iso + 'T00:00:00Z' : iso).toLocaleDateString('en-GB', { day: 'numeric', month: 'short', year: 'numeric', timeZone: 'UTC' });
const fmtTime = (iso) => new Date(iso).toLocaleTimeString('en-GB', { hour: '2-digit', minute: '2-digit', timeZone: 'UTC' });
const fetchJson = (path) => fetch(`${BASE}/${path}?t=${Date.now()}`).then((r) => { if (!r.ok) throw new Error(r.status); return r.json(); });
// ---------- live panel ----------
function renderLive(d) {
const ageMin = (Date.now() - Date.parse(d.updated)) / 60000;
const stale = ageMin > 120 || (d.recorder && d.recorder.connected === false);
$('pill').className = 'pill ' + (stale ? 'stale' : 'on');
$('pill-text').textContent = stale ? 'Not updating' : 'Recording';
$('updated').textContent = `Updated ${fmtDay(d.updated)} ${fmtTime(d.updated)} UTC` + (d.recording_since ? ` · recording since ${fmtDay(d.recording_since)}` : '');
$('f-n').textContent = d.n_liquidations.toLocaleString('en-GB');
$('f-n-sub').textContent = `${d.n_symbols} symbols`;
$('f-long').textContent = usd(d.usd_long_liquidated);
$('f-short').textContent = usd(d.usd_short_liquidated);
if (d.largest) {
$('f-big').textContent = usd(d.largest.usd);
$('f-big-sub').textContent = `${d.largest.symbol} ${d.largest.side === 'SELL' ? 'long' : 'short'} · ${fmtTime(d.largest.time)} UTC`;
}
$('f-cov').textContent = (100 * d.coverage_24h).toFixed(1) + '%';
$('f-cov-sub').textContent = 'of the last 24 h connected';
const top = $('top'); top.replaceChildren();
if (!d.top_symbols.length) { const tr = el('tr'); const td = el('td', 'empty', 'No liquidations yet'); td.colSpan = 4; tr.appendChild(td); top.appendChild(tr); }
d.top_symbols.forEach((s) => {
const tr = el('tr');
[s.symbol, s.n.toLocaleString('en-GB'), usd(s.usd), s.long_share == null ? '—' : Math.round(100 * s.long_share) + '%'].forEach((v) => tr.appendChild(el('td', null, v)));
top.appendChild(tr);
});
const oi = $('oi'); oi.replaceChildren();
const entries = Object.entries(d.oi_change_24h_pct || {});
if (!entries.length) { const tr = el('tr'); const td = el('td', 'empty', 'Not enough polls yet'); td.colSpan = 2; tr.appendChild(td); oi.appendChild(tr); }
entries.forEach(([c, v]) => { const tr = el('tr'); tr.appendChild(el('td', null, c)); tr.appendChild(el('td', null, pct(v))); oi.appendChild(tr); });
drawChart(d.hourly_7d || []);
}
function drawChart(rows) {
const box = $('chart'); box.replaceChildren();
if (!rows.length) { box.appendChild(el('p', 'empty', 'The hourly chart appears after the first full hour of recording.')); return; }
const W = Math.max(320, box.clientWidth), H = 220, M = { t: 10, r: 8, b: 24, l: 64 };
const max = Math.max(1, ...rows.map((r) => Math.max(r.usd_long_liquidated, r.usd_short_liquidated)));
const mid = M.t + (H - M.t - M.b) / 2, half = (H - M.t - M.b) / 2;
// fixed 7-day axis, one slot per hour, ending at the latest hour
const SLOTS = 168, HOUR = 3600e3;
const endMs = Date.parse(rows[rows.length - 1].hour);
const startMs = endMs - (SLOTS - 1) * HOUR;
const bw = (W - M.l - M.r) / SLOTS;
const slot = (iso) => Math.round((Date.parse(iso) - startMs) / HOUR);
rows = rows.filter((r) => slot(r.hour) >= 0);
const y = (v) => (v / max) * half;
const ns = 'http://www.w3.org/2000/svg';
const svg = document.createElementNS(ns, 'svg');
svg.setAttribute('viewBox', `0 0 ${W} ${H}`);
svg.setAttribute('role', 'img');
svg.setAttribute('aria-label', 'Hourly USD of long and short liquidations');
const add = (tag, attrs, text) => { const e = document.createElementNS(ns, tag); Object.entries(attrs).forEach(([k, v]) => e.setAttribute(k, v)); if (text != null) e.textContent = text; svg.appendChild(e); return e; };
const ink2 = getComputedStyle(document.body).getPropertyValue('--ink-2');
const rule = getComputedStyle(document.body).getPropertyValue('--rule');
add('line', { x1: M.l, x2: W - M.r, y1: mid, y2: mid, stroke: rule });
[['↑ ' + usd(max), mid - half + 8], ['0', mid + 4], ['↓ ' + usd(max), mid + half]].forEach(([t, yy]) => add('text', { x: M.l - 6, y: yy, 'text-anchor': 'end', 'font-size': 11, fill: ink2, 'font-family': 'IBM Plex Mono, monospace' }, t));
const tip = el('div', 'tip'); tip.hidden = true; box.appendChild(tip);
rows.forEach((r) => {
const i = slot(r.hour);
const x = M.l + i * bw + bw * 0.12, w = Math.max(1.5, bw * 0.76);
const op = r.coverage >= 0.999 ? 1 : 0.35;
add('rect', { x, y: mid - y(r.usd_long_liquidated), width: w, height: y(r.usd_long_liquidated), fill: 'var(--long)', opacity: op, rx: 1 });
add('rect', { x, y: mid, width: w, height: y(r.usd_short_liquidated), fill: 'var(--short)', opacity: op, rx: 1 });
const hit = add('rect', { x: M.l + i * bw, y: M.t, width: bw, height: H - M.t - M.b, fill: 'transparent' });
hit.addEventListener('pointerenter', () => {
tip.replaceChildren(el('div', 'mono', `${fmtDay(r.hour)} ${fmtTime(r.hour)} UTC`), el('div', null, `Longs ${usd(r.usd_long_liquidated)} (${r.n_long_liquidated})`), el('div', null, `Shorts ${usd(r.usd_short_liquidated)} (${r.n_short_liquidated})`), el('div', null, `Coverage ${Math.round(100 * r.coverage)}%`));
tip.hidden = false;
const px = (M.l + i * bw) * (box.clientWidth / W);
tip.style.left = Math.min(box.clientWidth - tip.offsetWidth, Math.max(0, px + 12)) + 'px';
tip.style.top = '0px';
});
hit.addEventListener('pointerleave', () => { tip.hidden = true; });
});
// day ticks at UTC midnight
for (let i = 0; i < SLOTS; i++) {
const t = new Date(startMs + i * HOUR);
if (t.getUTCHours() !== 0) continue;
add('line', { x1: M.l + i * bw, x2: M.l + i * bw, y1: M.t, y2: H - M.b, stroke: rule });
add('text', { x: M.l + i * bw + 3, y: H - 6, 'font-size': 11, fill: ink2, 'font-family': 'IBM Plex Mono, monospace' }, t.toLocaleDateString('en-GB', { day: 'numeric', month: 'short', timeZone: 'UTC' }));
}
box.insertBefore(svg, tip);
}
// ---------- journey ----------
function fmtAt(iso) { return fmtDay(iso.slice(0, 10)) + ' · ' + fmtTime(iso) + ' UTC'; }
function renderJourney(lab) {
$('focus').textContent = lab.lab.focus;
$('summary').textContent = lab.lab.summary;
const repo = lab.lab.repo;
const list = $('study-list'); list.replaceChildren();
const LINK = { dashboard: 'Interactive dashboard', findings: 'Findings', code: 'Code' };
lab.studies.forEach((s) => {
const li = el('li', 'study ' + (s.stage > 0 ? 'is-active' : 'is-planned'));
li.appendChild(el('div', 'study-id', s.id));
const main = el('div', 'study-main');
main.appendChild(el('h3', null, s.title));
main.appendChild(el('p', 'q', s.question));
const track = el('div', 'track');
track.setAttribute('role', 'img');
track.setAttribute('aria-label', `${s.stage} of ${lab.stages.length} stages done`);
lab.stages.forEach((name, i) => {
const seg = el('div', 'seg' + (i < s.stage ? ' done' : i === s.stage ? ' next' : ''));
seg.appendChild(el('i'));
seg.appendChild(el('span', null, i === s.stage ? 'Next: ' + name : name));
track.appendChild(seg);
});
main.appendChild(track);
if (s.headline && s.headline.length) { const ul = el('ul', 'headline'); s.headline.forEach((h) => ul.appendChild(el('li', null, h))); main.appendChild(ul); }
const foot = el('div', 'study-foot');
foot.appendChild(el('span', 'status', s.status));
const sl = el('div', 'study-links');
Object.entries(s.links || {}).forEach(([k, v]) => { if (v && !v.includes('claude.ai')) sl.appendChild(link(v, LINK[k] || k)); });
if (sl.children.length) foot.appendChild(sl);
main.appendChild(foot);
li.appendChild(main);
list.appendChild(li);
});
const log = $('log'); log.replaceChildren();
const entries = [...lab.notebook].sort((a, b) => (a.at < b.at ? 1 : a.at > b.at ? -1 : 0));
entries.forEach((n) => {
const li = el('li', 'entry'); li.dataset.study = n.study;
const t = el('time', 'mono', fmtAt(n.at)); t.dateTime = n.at; li.appendChild(t);
const main = el('div', 'entry-main');
const meta = el('p', 'meta');
const k = el('span', 'kind', n.kind); k.dataset.k = n.kind; meta.appendChild(k);
meta.appendChild(el('span', 'mono', n.study === 'live' ? 'Live system' : 'Study ' + n.study));
if (n.ref) meta.appendChild(repo ? link(repo.replace(/\/$/, '') + '/commit/' + n.ref, n.ref) : el('span', 'mono', n.ref));
main.appendChild(meta);
main.appendChild(el('h3', null, n.title));
main.appendChild(el('p', null, n.body));
li.appendChild(main);
log.appendChild(li);
});
const filters = $('filters'); filters.replaceChildren();
const ids = [...new Set(entries.map((n) => n.study))].sort();
let picked = 'all';
const apply = () => {
filters.querySelectorAll('.chip').forEach((c) => c.setAttribute('aria-pressed', String(c.dataset.v === picked)));
log.querySelectorAll('.entry').forEach((e) => { e.hidden = picked !== 'all' && e.dataset.study !== picked; });
};
[['all', 'All']].concat(ids.map((i) => [i, i === 'live' ? 'Live system' : 'Study ' + i])).forEach(([v, label]) => {
const b = el('button', 'chip', label); b.type = 'button'; b.dataset.v = v;
b.addEventListener('click', () => { picked = v; apply(); });
filters.appendChild(b);
});
filters.hidden = ids.length < 2;
apply();
}
fetchJson('latest.json').then(renderLive).catch(() => { $('pill').className = 'pill stale'; $('pill-text').textContent = 'Ledger not reachable'; });
fetchJson('journey/lab.json').then(renderJourney).catch(() => { $('study-list').replaceChildren(el('li', 'empty', 'Could not load the studies.')); });
let lastW = 0;
window.addEventListener('resize', () => { const w = $('chart').clientWidth; if (Math.abs(w - lastW) > 40) { lastW = w; fetchJson('latest.json').then(renderLive).catch(() => {}); } });
})();
</script>
</body>
</html>