diff --git a/app/nullius/compare/comparison.py b/app/nullius/compare/comparison.py index 0a0b69f8..604fda73 100644 --- a/app/nullius/compare/comparison.py +++ b/app/nullius/compare/comparison.py @@ -24,9 +24,10 @@ def value(self) -> str: return f"{self.workspace}:{self.job_id}" @classmethod - def parse(cls, value: str) -> "RunRef": + def parse(cls, value: str, empty: bool = False) -> "RunRef": + """``empty``: also a column with no run yet, ``:``.""" name, separator, job_id = value.partition(":") - if not separator or not job_id: + if not separator or not (job_id or empty): raise ValueError("A run selection must include its workspace and run id.") # Empty means the active source, for legacy selections without a saved # workspace. Named workspaces use the same slug alphabet as workspace.py. diff --git a/app/static/compare/columns.js b/app/static/compare/columns.js new file mode 100644 index 00000000..54f09072 --- /dev/null +++ b/app/static/compare/columns.js @@ -0,0 +1,128 @@ +/* Compare's columns (templates/compare/compare.html): each header's workspace and run. The page's URL is the + comparison, its ordered pick= values: a run picked opens it with that run in its column; a workspace picked + lists its runs in place (/compare/runs). The run list searches as the table toolkit does. */ +window.NulliusCompare = { + /* This page's URL with column `k` holding `value` (`:`, `:` for none). */ + url(values, k, value) { + const u = new URL(location.href); + u.searchParams.delete('pick'); + u.searchParams.delete('job'); + values.forEach((v, i) => u.searchParams.append('pick', i === k ? value : v)); + return u.pathname + u.search; + }, + + /* `node` showing the run `r`: agent · model, a check or its shards marked, the date at the right, where it + ran from below; its id in the tooltip. */ + entry(node, r) { + const span = (cls, text) => { const s = document.createElement('span'); s.setAttribute('class', cls); s.textContent = text; return s; }; + const line = span('run-line', [r.agent, r.model].filter(Boolean).join(' · ')); + if (r.check) line.appendChild(span('chip-control', 'check')); + if (r.shards > 1) line.appendChild(span('run-shards', `${r.shards} shards`)); + node.textContent = ''; + [line, span('run-date', r.date), span('run-where', r.where)].forEach(s => node.appendChild(s)); + node.setAttribute('title', r.id); + }, + + /* The listbox `list` of `runs`, the `same` first (the baseline's dataset) and a labelled line after them, a + line between launches. `n` names the options. */ + fill(list, runs, same, n) { + const line = text => { + const li = document.createElement('li'); + li.setAttribute('role', 'separator'); + li.setAttribute('class', text ? 'run-sep labelled' : 'run-sep'); + li.textContent = text; + return li; + }; + list.textContent = ''; + runs.forEach((r, i) => { + if (i && i === same) list.appendChild(line('Other datasets')); + else if (i && r.launch !== runs[i - 1].launch) list.appendChild(line('')); + const li = document.createElement('li'); + li.setAttribute('role', 'option'); + li.setAttribute('id', `${n}-${i}`); + li.setAttribute('class', 'run-entry'); + li.dataset.value = r.value; + li.dataset.search = [r.agent, r.model, r.where, r.date, r.id, r.check ? 'check' : '', r.shards > 1 ? `${r.shards} shards` : ''].join(' '); + + this.entry(li, r); + list.appendChild(li); + }); + }, + + /* One column's `cells`, its header `th` first: its workspace select, its run button and the searchable list it + opens. */ + column(cells, cfg) { + const th = cells[0], find = s => cells.map(c => c.querySelector(s)).find(Boolean); + const k = +th.dataset.column, ws = find('[data-ws]'), btn = find('[data-run-btn]'); + const menu = find('[data-run-menu]'), q = menu.querySelector('input'), list = menu.querySelector('[role="listbox"]'); + const none = menu.querySelector('[data-none]'); + let at = -1; + const shown = () => [...list.querySelectorAll('[role="option"]')].filter(o => !o.hidden); + const able = () => shown().filter(o => o.getAttribute('aria-disabled') !== 'true'); + const mark = i => { + const os = able(); + at = Math.max(Math.min(i, os.length - 1), os.length ? 0 : -1); + os.forEach((o, j) => o.setAttribute('aria-selected', String(j === at))); + if (at < 0) q.removeAttribute('aria-activedescendant'); + else { q.setAttribute('aria-activedescendant', os[at].id); os[at].scrollIntoView?.({block: 'nearest'}); } + }; + const search = () => { + list.querySelectorAll('[role="option"]').forEach(o => { o.hidden = !NulliusTable.matches(o.dataset.search, q.value); }); + list.querySelectorAll('[role="separator"]').forEach(s => { s.hidden = Boolean(q.value.trim()); }); + none.hidden = shown().length > 0; + mark(0); + }; + const show = data => { + this.fill(list, data.runs, data.same, list.id); + // the page's picks name whole runs (a shard's id stands for its run): another column's is greyed, this one's checked + list.querySelectorAll('[role="option"]').forEach(o => { + const j = cfg.values.indexOf(o.dataset.value); + if (j === k) o.setAttribute('aria-checked', 'true'); + else if (j >= 0) { o.setAttribute('aria-disabled', 'true'); o.setAttribute('title', `Already in column ${j + 1}`); } + }); + search(); + }; + const pick = o => { location.href = this.url(cfg.values, k, o.dataset.value); }; + q.addEventListener('input', search); + q.addEventListener('keydown', e => { + if (e.key === 'ArrowDown' || e.key === 'ArrowUp') { e.preventDefault(); mark(at + (e.key === 'ArrowDown' ? 1 : -1)); } + else if (e.key === 'Enter' && able()[at]) { e.preventDefault(); pick(able()[at]); } + }); + list.addEventListener('click', e => { const o = e.target.closest('[role="option"]'); if (o && o.getAttribute('aria-disabled') !== 'true') pick(o); }); + // fixed under its button (the table's scroll box would clip it), placed before it opens and takes the focus, + // so the focus never scrolls the table + const place = () => { + const b = btn.getBoundingClientRect(), w = Math.min(Math.max(b.width, 320), innerWidth - 16); + Object.assign(menu.style, {top: `${b.bottom + 4}px`, left: `${Math.max(8, Math.min(b.left, innerWidth - w - 8))}px`, width: `${w}px`}); + }; + btn.addEventListener('click', place); + NulliusTable.menu(btn, menu); + + addEventListener('resize', place); + document.addEventListener('scroll', e => { if (!menu.contains(e.target)) place(); }, true); + + ws.addEventListener('change', () => { + nulliusFetch(cfg.runs + '?' + new URLSearchParams({workspace: ws.value, dataset: cfg.dataset})) + .then(r => r.ok ? r.json() : Promise.reject(r.status)) + .then(data => { + show(data); + // an empty column keeps its workspace in the URL; one with a run keeps it until another is picked + if (!th.dataset.run) { cfg.values[k] = ws.value + ':'; history.replaceState(null, '', this.url(cfg.values, k, cfg.values[k])); } + if (menu.hidden) btn.click(); + }); + }); + show(cfg.lists[ws.value] || {runs: [], same: 0}); + const mine = (cfg.lists[ws.value]?.runs || []).find(r => r.value === cfg.values[k]); + if (mine) this.entry(btn.querySelector('[data-run-label]'), mine); + }, + + /* Every column of the page, its cells in the rows they share, and the Order menu. A list opens only on its + button. */ + wire(cfg) { + const order = document.querySelector('[data-order-btn]'); + if (order) NulliusTable.menu(order, order.nextElementSibling); + const cols = []; + document.querySelectorAll('[data-column]').forEach(c => (cols[+c.dataset.column] ||= []).push(c)); + cols.forEach(cells => this.column(cells, cfg)); + }, +}; diff --git a/app/static/compare/comparison.css b/app/static/compare/comparison.css index a9e8a52c..c55ea594 100644 --- a/app/static/compare/comparison.css +++ b/app/static/compare/comparison.css @@ -1,10 +1,5 @@ /* Comparison controls share the shell's theme and leave data colours alone. */ .compare-title { justify-content: space-between; align-items: center; } -.cohort-tools { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 1rem; margin: 1.5rem 0; } -.cohort-switch { display: inline-flex; padding: 4px; gap: 4px; border: 1px solid var(--border-soft); border-radius: 8px; background: var(--surface); } -.cohort-switch a { padding: .5rem .9rem; border-radius: 5px; font-size: .84rem; color: var(--text-dim); } -.cohort-switch a:hover { background: var(--surface-2); text-decoration: none; } -.cohort-switch a[aria-current="true"] { background: var(--accent-soft); color: var(--accent); } .cohort-note { margin: 1rem 0 1.6rem; padding: 1rem 1.2rem; background: var(--surface-2); border-radius: 7px; color: var(--text-dim); font-size: .85rem; line-height: 1.7; } .cohort-note p { margin: 0; } .cohort-note p + p { margin-top: .55rem; } @@ -12,20 +7,42 @@ .compare-excluded { color: var(--text-faint); font-size: .73rem; margin-top: .35rem; } .compare-attempts { display: block; color: var(--text-faint); font-size: .72rem; margin-top: .4rem; } .compare-task-dataset { display: block; color: var(--text-faint); font: .7rem var(--sans); margin: .3rem 0 0 1.5rem; } -.compare-picker { max-width: 1100px; } -.compare-pick-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1.4rem; } -.compare-pick-side { min-width: 0; display: flex; flex-direction: column; gap: .6rem; } -.compare-pick-side > label { color: var(--text-dim); font-size: .82rem; } -.compare-pick-side select { width: 100%; min-width: 0; padding: .75rem .85rem; border: 1px solid var(--border); border-radius: 7px; font: .88rem var(--sans); color: var(--text); background: var(--surface); } -.compare-pick-side option { color: var(--text); background: var(--surface); } -.compare-pick-caption { color: var(--text-faint); font-size: .8rem; margin: .2rem 0 0; } -.compare-pick-actions { display: flex; align-items: center; gap: 1rem; margin-top: 1.4rem; flex-wrap: wrap; } -.compare-pick-actions > label { display: inline-flex; gap: .45rem; align-items: center; color: var(--text-dim); font-size: .85rem; } -.compare-pick-step { color: var(--text-faint); font: .7rem var(--mono); letter-spacing: .08em; text-transform: uppercase; margin: 0 0 1.4rem; } -@media (max-width: 640px) { - .compare-pick-grid { grid-template-columns: 1fr; gap: 1rem; } - .cohort-tools { align-items: flex-start; flex-direction: column; } -} +.compare-warn { color: var(--patch_failed_tests); font-size: .86rem; margin: 0 0 1.4rem; } + +/* A column's tools in its header, its workspace and run in the rows below; an empty column greyed, with no numbers. */ +.compare-col { vertical-align: top; text-transform: none; letter-spacing: 0; font-weight: 400; } +.col-head { display: flex; flex-direction: column; gap: .4rem; min-width: 0; } +.col-tools { display: flex; align-items: center; gap: .15rem; } +.col-id { display: flex; flex-wrap: wrap; gap: .2rem .8rem; } +.col-tools .icon-btn { width: 26px; height: 26px; font-size: .9rem; text-decoration: none; } +.compare-baseline { margin-right: auto; color: var(--accent); font-size: .7rem; letter-spacing: .07em; text-transform: uppercase; } +.col-ws, .col-run { width: 100%; min-width: 0; padding: .45rem .6rem; border: 1px solid var(--border); border-radius: 7px; font: .82rem var(--sans); color: var(--text); background: var(--surface); text-align: left; } +.col-run { cursor: pointer; } +.col-run:hover, .col-ws:hover { border-color: var(--text-faint); } +.compare-col.empty .col-ws, .compare-col.empty .col-run { color: var(--text-dim); background: var(--surface-2); border-style: dashed; } +.compare-empty { background-image: linear-gradient(color-mix(in srgb, var(--surface-2) 45%, transparent) 0 0); } /* an image: a pinned row's opaque colour stays under it */ +/* a run as its list and its button show it */ +.run-entry { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: .1rem .6rem; min-width: 0; } +.run-line { overflow-wrap: anywhere; color: var(--text); } +.run-line .chip-control, .run-shards { margin-left: .4rem; } +.run-shards { color: var(--text-faint); font-size: .72rem; white-space: nowrap; } +.run-date { color: var(--text-faint); font-size: .72rem; white-space: nowrap; } +.run-where { grid-column: 1 / -1; color: var(--text-dim); font-size: .72rem; overflow-wrap: anywhere; } +.run-menu { position: fixed; z-index: 30; padding: .5rem; } + +.run-menu .st-search { margin: 0 0 .4rem; } +.run-list { list-style: none; margin: 0; padding: 0; max-height: min(60vh, 26rem); overflow-y: auto; } +.run-list [role="option"] { padding: .45rem .5rem; border-radius: 6px; cursor: pointer; font-size: .82rem; } +.run-list [role="option"]:not([aria-disabled="true"]):hover, .run-list [aria-selected="true"] { background: var(--surface-2); } +.run-list [aria-selected="true"] { box-shadow: inset 2px 0 0 var(--accent); } +.run-list [aria-disabled="true"] { opacity: .45; cursor: default; } /* another column's run */ +.run-list [aria-checked="true"] .run-line::before { content: "✓ "; color: var(--accent); } /* this column's run */ +.run-sep { border-top: 1px solid var(--border-soft); margin: .25rem 0; } +.run-sep.labelled { padding: .4rem .5rem .1rem; color: var(--text-faint); font-size: .7rem; letter-spacing: .07em; text-transform: uppercase; } +/* a summary cell's difference from the baseline, in the row's unit */ +.delta { display: block; font-size: .72rem; font-weight: 400; color: var(--text-faint); } +.delta.ok { color: var(--resolved); } +.delta.bad { color: var(--bad); } /* One column contract for the overview, task rows and expanded metrics. */ .compare-table-wrap { @@ -48,6 +65,8 @@ padding-inline: var(--compare-cell-inset); } .compare-table-wrap .grid.compare.tasks > tbody > .compare-task-row > td { vertical-align: middle; } +/* the task table's header row, under its columns' controls: read as a table head */ +.grid.compare.tasks .compare-task-head > th { color: var(--text-dim); font-weight: 500; font-size: .78rem; border-bottom-color: var(--border); } .compare-task-name { display: flex; align-items: center; gap: .4rem; min-width: 0; } .compare-task-name .disclose { flex: none; margin: 0; min-height: 1.8rem; } .compare-task-label { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; min-width: 0; overflow: hidden; overflow-wrap: anywhere; font-size: .82rem; } @@ -78,13 +97,15 @@ } @media (max-width: 640px) { .compare-table-wrap { --compare-label-width: 14rem; } + /* the summary keeps room for a run column beside its pinned names */ + .compare-table-wrap .grid.compare:not(.tasks) { --compare-label-width: 8.5rem; min-width: calc(var(--compare-label-width) + var(--cols, 2) * 15rem); } /* Let a whole agent column enter the viewport when scrolling on a phone. */ - .compare-table-wrap .grid.compare th.rowhead, - .compare-table-wrap .grid.inner th.rowhead, - .compare-table-wrap .grid.compare.tasks > thead > tr > th:first-child, - .compare-table-wrap .grid.compare.tasks > tbody > .compare-task-row > td:first-child { position: static; } + .compare-table-wrap .grid.compare.tasks .sticky-col, + .compare-table-wrap .grid.inner .sticky-col { position: static; } } + + /* Side-by-side trial headings: section-title margins must not offset badges. */ .cmp-head .compare-trial-heading { display: flex; diff --git a/app/static/controls.js b/app/static/controls.js index 4cdc42b3..7e7637c4 100644 --- a/app/static/controls.js +++ b/app/static/controls.js @@ -74,7 +74,7 @@ if (active && (!active.select.isConnected || active.select.disabled)) close(); for (const [select, button] of controls) if (!select.isConnected) { button.remove(); controls.delete(select); } document.querySelectorAll('select:not([multiple])').forEach(select => { - if (select.size > 1) return; + if (select.size > 1 || select.closest('[inert]')) return; // an inert copy (a sticky row's placeholder) needs no menu let button = controls.get(select); if (!button) { button = document.createElement('button'); button.type = 'button'; button.className = 'ui-select-trigger'; diff --git a/app/static/onboarding.js b/app/static/onboarding.js index d7af20bb..786aa021 100644 --- a/app/static/onboarding.js +++ b/app/static/onboarding.js @@ -89,12 +89,13 @@

A one-minute look at the main pages, then a checklist that takes you to a first result:

  • Set up a key and where runs happen
  • A free check run: oracle and nop call no model
  • Read the result, then compare an agent's run
`; + const back = document.activeElement; document.body.append(layer); layer.querySelector('[data-a=yes]').focus(); layer.addEventListener('click', e => { const a = e.target.closest('[data-a]')?.dataset.a; if (!a) return; - S.asked = true; S.open = a === 'yes'; save(); layer.remove(); + S.asked = true; S.open = a === 'yes'; save(); layer.remove(); back?.focus(); if (a === 'yes') startTour(); else renderPanel(); }); } diff --git a/app/static/style.css b/app/static/style.css index 5e903da3..9a003d91 100644 --- a/app/static/style.css +++ b/app/static/style.css @@ -362,6 +362,14 @@ button.seg:hover { filter: brightness(1.25); } .table-buttons, .table-slot { display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: center; gap: .75rem; } .table-buttons { margin-left: auto; } .table-buttons .menu { left: auto; right: 0; } /* opens leftwards, inside the page */ +.table-controls { --tool-h: 2.1rem; } /* every control in the row is as tall as a small button with its icon */ +.table-controls :is(.btn, .seg-toggle, .filter-pill) { height: var(--tool-h); } +.table-controls .filter-pill { min-height: 0; padding-block: 0; } +/* a segmented toggle: a bordered group of links or buttons, the current one marked */ +.seg-toggle { display: inline-flex; padding: 3px; gap: 3px; border: 1px solid var(--border-soft); border-radius: 8px; background: var(--surface); } +.seg-toggle > * { display: inline-flex; align-items: center; padding: .3rem .75rem; border: 0; border-radius: 5px; background: transparent; font: inherit; font-size: .8rem; line-height: 1.2; color: var(--text-dim); cursor: pointer; } +.seg-toggle > :hover { background: var(--surface-2); text-decoration: none; } +.seg-toggle > [aria-current="true"], .seg-toggle > [aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); } /* a search box, its icon first (the Settings page's too) */ .st-search { display: flex; align-items: center; gap: 8px; margin: 0 0 12px; padding: 8px 10px; border: 1px solid transparent; border-radius: 8px; background: var(--surface-2); color: var(--text-dim); } .st-search .ic { flex: none; width: 17px; height: 17px; } @@ -376,11 +384,11 @@ button.seg:hover { filter: brightness(1.25); } padding: .5rem; min-width: 168px; box-shadow: 0 8px 24px rgba(0, 0, 0, .3); display: flex; flex-direction: column; gap: .1rem; } -.menu label { +.menu label, .tools-menu > a { display: flex; align-items: center; gap: .5rem; cursor: pointer; font-size: .84rem; color: var(--text-dim); padding: .3rem .45rem; border-radius: 6px; } -.menu label:hover { background: var(--surface-2); color: var(--text); } +.menu label:hover, .tools-menu > a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; } .menu input { accent-color: var(--accent); } .table-note { color: var(--text-faint); font-size: .8rem; } .table-pager { margin-top: .6rem; } @@ -409,12 +417,6 @@ button.seg:hover { filter: brightness(1.25); } overflow-x: auto; overscroll-behavior-x: contain; border-radius: var(--radius); } -/* NOTE: no sticky header here. `overflow-x: auto` makes the wrapper a scroll - container on BOTH axes (per spec, a non-visible overflow-x forces overflow-y - to compute to auto), so `top: 64px` positioned the header 64px down from the - wrapper — on top of the first rows — instead of pinning it to the viewport. - The left-pinned columns below work correctly, because the wrapper really - does scroll horizontally. */ /* a table's .sticky-col cells stay put while it scrolls sideways, at --sticky-left (tables.js `sticky`), so a row never loses its identity; .sticky-edge draws the line after the last one */ @@ -425,6 +427,14 @@ button.seg:hover { filter: brightness(1.25); } .table-wrap .grid thead th.sticky-col { z-index: 4; background: var(--bg); } /* opaque sticky cells would hide the row hover, so repaint them to match */ .table-wrap .grid tbody tr:hover td.sticky-col { background: var(--surface); } +/* `overflow-x: auto` makes the wrapper a scroll container on both axes, so a sticky row could pin only to it: the + sticky rows float in a fixed box instead (tables.js `sticky`), sideways scrolled with the table, under the + controls row, a hidden copy holding their place */ +.table-wrap.table-float { position: fixed; z-index: 4; background: var(--bg); scrollbar-width: none; } +.table-wrap.table-float::-webkit-scrollbar { display: none; } +.table-float > .grid { table-layout: fixed; } +.sticky-ghost { visibility: hidden; } +.table-tools.sticky-tools { position: sticky; top: var(--topbar-height); z-index: 5; background: var(--bg); margin-bottom: 0; padding-bottom: .6rem; } /* compact density — same data, ~35% less width */ .grid.compact { font-size: .88rem; } @@ -490,16 +500,9 @@ button.seg:hover { filter: brightness(1.25); } .grid.compare th.rowhead, .grid.inner th.rowhead { color: var(--text-dim); font-weight: 500; font-size: .78rem; text-transform: uppercase; letter-spacing: .07em; width: 11rem; text-align: left; - position: sticky; left: 0; z-index: 2; background: var(--bg); -} -.grid.compare.tasks td:first-child { - position: sticky; left: 0; z-index: 2; background: var(--bg); - box-shadow: 1px 0 0 var(--border-soft); -} -.grid.compare.tasks tbody tr:hover td:first-child { background: var(--surface); } -.grid.compare.tasks thead th:first-child { - position: sticky; left: 0; z-index: 3; background: var(--bg); width: 20rem; } +.grid.compare.tasks thead th:first-child { width: 20rem; } + /* the detail row spans the table, so its inner table must not re-scroll */ .detail-row > td { overflow-x: auto; } .grid.compare tbody tr:hover { background: var(--surface); } diff --git a/app/static/tables.js b/app/static/tables.js index f5e72df6..ad394d5c 100644 --- a/app/static/tables.js +++ b/app/static/tables.js @@ -2,6 +2,12 @@ into (the macros of templates/_tables.html; their styles in style.css, "the table toolkit"), and the card toolkit's (templates/_cards.html). */ window.NulliusTable = { + /* Whether `text` holds every word of `query`, in any order and case. */ + matches(text, query) { + const t = (text ?? '').toLowerCase(); + return query.toLowerCase().split(/\s+/).every(w => t.includes(w)); + }, + /* A header with data-type sorts its column on a click or Enter; num sorts descending first. A cell's data-sort wins over its text. A header that carries data-sorted at load is the sort the rows came in. The sorted @@ -124,15 +130,17 @@ window.NulliusTable = { ancestor (the page's
): that is not leaving. */ menu(btn, menu) { const close = () => { menu.hidden = true; btn.setAttribute('aria-expanded', 'false'); }; + // a modal over the page (the first-visit guide) takes the focus and the clicks without closing the menu under it + const away = to => !menu.contains(to) && !btn.contains(to) && !to.closest?.('[aria-modal="true"]'); btn.addEventListener('click', () => { const open = menu.hidden; menu.hidden = !open; btn.setAttribute('aria-expanded', String(open)); - if (open) menu.querySelector('input:not(:disabled), button')?.focus(); + if (open) menu.querySelector('input:not(:disabled), button, a[href]')?.focus(); }); - document.addEventListener('click', e => { if (!menu.hidden && !menu.contains(e.target) && !btn.contains(e.target)) close(); }); + document.addEventListener('click', e => { if (!menu.hidden && away(e.target)) close(); }); document.addEventListener('keydown', e => { if (e.key === 'Escape' && !menu.hidden) { close(); btn.focus(); } }); - const left = e => { const to = e.relatedTarget; if (to && !menu.contains(to) && !btn.contains(to) && !to.contains(menu)) close(); }; + const left = e => { const to = e.relatedTarget; if (to && away(to) && !to.contains(menu)) close(); }; menu.addEventListener('focusout', left); btn.addEventListener('focusout', left); }, @@ -152,10 +160,7 @@ window.NulliusTable = { q.addEventListener('input', changed); q.addEventListener('keydown', e => { if (e.key === 'Escape' && q.value) { e.preventDefault(); q.value = ''; changed(); } }); } - const found = row => { - const text = (row.dataset.search ?? '').toLowerCase(); - return !q || q.value.toLowerCase().split(/\s+/).every(w => text.includes(w)); - }; + const found = row => !q || this.matches(row.dataset.search, q.value); const menus = [...(fmenu ? [[fbtn, fmenu, () => 1]] : []), ...[...tools.querySelectorAll('[data-dropdown]')].map(b => [b, b.parentNode.querySelector('.menu'), set => set.size])]; const mark = () => menus.forEach(([btn, menu, n]) => { @@ -272,15 +277,54 @@ window.NulliusTable = { }, /* Sticky columns, those whose header is a .sticky-col: each cell under it - pinned at the summed widths of the sticky columns before it, again as - they resize, hide or rows come in. A row without a cell under each - header (a colspan, an empty row) is left as it is. */ + pinned at the summed widths of the sticky columns before it. Sticky rows, + the rows with data-sticky (data-sticky="wide": only from 900px wide, where + a tall row leaves room for the rest): once the first scrolls above the + table's controls row (id -tools), which sticks, they float under + it in a box of the wrapper's classes until the table ends, its sideways + scroll kept with the table's. The rows themselves move, so their controls + keep working; a hidden copy holds each one's place. Again as they resize, + hide or rows come in. A row without a cell under each header (a colspan, + an empty row) is left as it is. */ sticky(table) { const heads = [...table.tHead.rows[0].cells], pinned = heads.filter(th => th.classList.contains('sticky-col')); + const wrap = table.closest('.table-wrap'), wide = matchMedia('(min-width: 900px)'); + const box = document.createElement('div'), float = table.cloneNode(false), cols = document.createElement('colgroup'); + const rows = () => [...table.querySelectorAll('tr[data-sticky]'), ...float.rows]; + const floats = rows().length > 0, tools = floats && table.id && document.getElementById(table.id + '-tools'); + const active = r => r.dataset.sticky !== 'wide' || wide.matches, ghosts = new Map(); // a floating row -> the copy holding its place + const land = () => { ghosts.forEach((ghost, row) => ghost.replaceWith(row)); ghosts.clear(); }; + const lift = () => { + const on = rows().filter(active), t = table.getBoundingClientRect(); + const under = tools ? tools.getBoundingClientRect().bottom : parseFloat(getComputedStyle(document.documentElement).getPropertyValue('--topbar-height')); + const up = on.length > 0 && Math.min(...on.map(r => (ghosts.get(r) || r).getBoundingClientRect().top)) < under && t.bottom > under; + if (!up || on.length !== ghosts.size || on.some(r => !ghosts.has(r))) { + land(); + if (up) [...table.querySelectorAll('tr[data-sticky]')].filter(active).forEach(row => { + const ghost = row.cloneNode(true), into = row.parentNode.tagName === 'THEAD' ? float.tHead : float.tBodies[0]; + [ghost, ...ghost.querySelectorAll('[id]')].forEach(e => e.removeAttribute('id')); + ghost.removeAttribute('data-sticky'); + ghost.classList.add('sticky-ghost'); + ghost.setAttribute('aria-hidden', 'true'); + ghost.inert = true; + row.replaceWith(ghost); + into.appendChild(row); + ghosts.set(row, ghost); + }); + seen.takeRecords(); // its own moves are no change to the table + } + box.hidden = !up; + if (!up) return; + const widths = [...table.tHead.rows[0].cells].map(c => c.getBoundingClientRect().width); + cols.replaceChildren(...widths.map(w => { const c = document.createElement('col'); c.style.width = w + 'px'; return c; })); + float.style.width = t.width + 'px'; + Object.assign(box.style, {top: Math.min(under, t.bottom - box.offsetHeight) + 'px', left: wrap.getBoundingClientRect().left + wrap.clientLeft + 'px', width: wrap.clientWidth + 'px'}); + box.scrollLeft = wrap.scrollLeft; + }; const place = () => { let left = 0; pinned.forEach(th => { - for (const row of table.rows) { + for (const row of [...table.rows, ...float.rows]) { if (row.cells.length !== heads.length) continue; const cell = row.cells[th.cellIndex]; cell.classList.add('sticky-col'); @@ -289,10 +333,27 @@ window.NulliusTable = { } left += th.getBoundingClientRect().width; }); + if (floats) lift(); }; + const seen = new MutationObserver(place); + if (tools) tools.classList.add('sticky-tools'); + if (floats) { + float.removeAttribute('id'); + float.removeAttribute('data-table'); + float.append(cols, document.createElement('thead'), document.createElement('tbody')); + box.className = wrap.className + ' table-float'; + box.hidden = true; + box.appendChild(float); + wrap.before(box); + wrap.addEventListener('scroll', () => { box.scrollLeft = wrap.scrollLeft; }); + box.addEventListener('scroll', () => { wrap.scrollLeft = box.scrollLeft; }); + addEventListener('scroll', lift, {passive: true}); + addEventListener('resize', lift); + wide.addEventListener('change', lift); + } const resized = new ResizeObserver(place); - pinned.forEach(th => resized.observe(th)); - new MutationObserver(place).observe(table, {childList: true, subtree: true}); + [...pinned, table].forEach(el => resized.observe(el)); + seen.observe(table, {childList: true, subtree: true}); place(); }, @@ -344,11 +405,11 @@ window.NulliusTable = { }, }; -/* Every table with sticky columns, every table of the table macro and every collection of the cards macro, set up +/* Every table with sticky columns or rows, every table of the table macro and every collection of the cards macro, set up once the page is read. */ const nulliusTables = () => { document.querySelectorAll('table.grid').forEach(t => { - if (t.querySelector('.sticky-col')) NulliusTable.sticky(t); + if (t.querySelector('.sticky-col, [data-sticky]')) NulliusTable.sticky(t); if (t.hasAttribute('data-table')) NulliusTable.wire(t); }); document.querySelectorAll('[data-cards]').forEach(c => NulliusTable.cards(c)); diff --git a/app/templates/_tables.html b/app/templates/_tables.html index df867a92..f69afa77 100644 --- a/app/templates/_tables.html +++ b/app/templates/_tables.html @@ -32,8 +32,10 @@ and its pages. `id` names it, and keys what a viewer chooses; `class` adds to its classes; `tr`: a macro writing a row's attributes. The call block writes a cell: it is called with a row and a column, in the order of `cols`, and writes that cell with the cell macro. Opt-ins: `search`, `columns`, `choices`, `only`, `views`, `actions` as - controls'; `empty` and `noun` as pager's. #} -{% macro table(id, cols, rows, tr, class='', search='', columns=false, choices={}, only={}, empty='No rows match.', noun='rows', views=none, actions=none) %} + controls'; `empty` and `noun` as pager's; `sticky_head`: its header row pinned while it scrolls down, and `tr`'s + rows with data-sticky under it (tables.js `sticky`), the controls row with them up to the table's end. #} +{% macro table(id, cols, rows, tr, class='', search='', columns=false, choices={}, only={}, empty='No rows match.', noun='rows', views=none, actions=none, sticky_head=false) %} +{%- if sticky_head %}
{% endif %} {%- set cols = cols|rejectattr('table', 'sameas', false)|list %} {{ controls(id, cols, search, columns, choices, only, views, actions) }} {%- for c in cols if c.width == 'expand' %} @@ -43,7 +45,7 @@
- {{ heads(cols) }} + {{ heads(cols) }} {%- for r in rows %} @@ -55,6 +57,7 @@
{{ pager(id, empty, noun) }} +{%- if sticky_head %}{% endif %} {% endmacro %} {#- One cell of the column `c`, as the table macro's call block gets it: its data-col, alignment and pinning from diff --git a/app/templates/base.html b/app/templates/base.html index f76cacf0..d2511789 100644 --- a/app/templates/base.html +++ b/app/templates/base.html @@ -71,6 +71,7 @@ + @@ -162,7 +163,7 @@ - -

Task by task

-

Tasks whose pass rate moved most are listed first. A blank cell means that run - didn't include the task.

+{% else %} {% if judgement %}
Judgement experimental · {{ judgement.judged }} of {{ judgement.pairs }} matched pair{{ '' if judgement.pairs == 1 else 's' }} judged{% if judgement.unjudged %}, {{ judgement.unjudged }} not judged{% endif %}{% if judgement.earlier %} ({{ judgement.earlier }} under an earlier vocabulary){% endif %} {% if judgement.unjudged and judgement.keyed %} -
+
@@ -148,26 +195,27 @@

Task by task

{% endif %}
- +
{{ comparison_columns() }} - - - - {% for j in jobs %} - + Task + {% for c in columns %} + {% set j = jobs[c.i] if c.i is not none else none %} + {% endfor %} {% if judgement %}{% endif %} - - {% for taskrow in tasks %} {% set task_index = loop.index0 %} {% set row = taskrow.trials %} - - {% for t in row %} + {% call(i) each() %}{% set t = row[i] %} - {% endfor %} + {% endcall %} {% if judgement %} - - {% else %}{% endfor %} + {% else %}{% endfor %}
Task - {{ j.agent_label or j.job_id }} + {{ column_controls('Task', 1 if judgement else 0) }} +
+ {%- if j is not none %} + {{ j.agent_label or j.job_id }}{% if j.model_name %} · {{ j.model_name }}{% endif %} {%- if j.is_control %} control{% endif %} + {%- endif %} Better of two
+
{# One glyph, rotated by CSS on aria-expanded. #}
{% if not comparison.datasets_match or not comparison.datasets_known %}{{ 'Dataset not recorded' if taskrow.dataset.startswith('[unidentified:') else taskrow.dataset|dsname }}{% endif %}
{% if t %}
- + {{ t.outcome_label }} {% if t.score is not none %}{{ '%.2f'|format(t.score) }}{% endif %} @@ -194,16 +242,16 @@

Task by task

Total time{{ t.dur_total|secs }} {% set used_tokens = (t.n_input_tokens or 0) + (t.n_output_tokens or 0) %} - Tokens{{ used_tokens|tokens(jobs[loop.index0].kind) }} + Tokens{{ used_tokens|tokens(jobs[i].kind) }}
- {%- set tried = taskrow.tried[loop.index0] %} + {%- set tried = taskrow.tried[i] %} {% if tried.n > 1 %}{{ attempt_count(tried) }}{% endif %} {% else %} — {% endif %}
{% set jr = judgement.rows.get(taskrow.task) %} {% if jr and jr.earlier %}{{ {'A': jobs[0].agent_label or 'A', 'B': jobs[1].agent_label or 'B', 'same': 'same'}[jr.choice] if jr.choice in ('A', 'B', 'same') else jr.choice }} {{ '%.0f'|format((jr.p or 0) * 100) }}% earlier vocabulary @@ -224,24 +272,30 @@

Task by task

{# detail rows: the same metrics for each side, so differences line up #}
No tasks in this comparison cohort.
No tasks in this comparison cohort.
+{% endif %} +