fix(viewers): summary row as the table's last row, identifiers left out

The CSV summary row read as a floating card: rounded, a repeated "Avg"
label in every cell, distinct counts under text columns and an average
of the seed column.

- The footer follows the column grid: square edges, a 2px top rule and
  the header's solid fill. It stays at the bottom of the scroll area,
  which no longer has vertical padding, so no rows show past it; a
  short table ends on it.
- One "Average" select in the first column (or the row-number column)
  sets the aggregate for every numeric column. Cells show only the
  value, right-aligned, semibold. A column can override it from its
  menu, marked by a small label in its cell.
- Text, date and identifier columns are empty in the footer; their
  distinct counts stay in the column menu.
- Identifiers (seed, id, run, fold, index, year by name, or small
  consecutive whole numbers that repeat) are left out of the summary,
  group averages and default charts. "Treat as number" in the column
  menu brings one back (#table:num=seed).
- Markdown and notebook tables get the same footer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Thomas DurieuxandClaude Opus 5.5 committed 2026-11-29 10:22:05 +00:00
1 parent 43e92bef53
commit 4fc3a8b2df
11 files changed
+231 -148

No files matched your search

+18 -23
View File
@@ -99,32 +99,31 @@ function enhance(table) {
});
apply();
// Σ: a footer row with one aggregate for every numeric column (Average first).
const numeric = model.columns.some((c) => c.type === "number");
// Σ: a footer row like the table viewer's: one aggregate for every measure,
// chosen with a single select in the first column (or beside Σ when the
// first column holds a value). Text and identifier columns stay empty.
const measure = (c) => c.type === "number" && !c.identifier;
const numeric = model.columns.some(measure);
const labelInFirst = model.columns.length > 1 && !measure(model.columns[0]);
const tools = doc.createElement("div");
tools.className = "md-table-tools";
let foot = null, fn = "mean", select = null;
let foot = null, fn = "mean";
const select = doc.createElement("select");
select.className = "md-table-agg";
select.setAttribute("aria-label", "Summary row");
AGGREGATES.forEach(([k, text]) => { const o = doc.createElement("option"); o.value = k; o.textContent = text; select.appendChild(o); });
select.addEventListener("change", () => { fn = select.value; renderFoot(); });
const renderFoot = () => {
if (!foot) return;
const all = original.map((_, i) => i);
const tr = foot.rows[0];
tr.textContent = "";
let labelled = false;
model.columns.forEach((c, i) => {
const td = doc.createElement("td");
const align = data.headerCells[i]?.getAttribute("align") || data.headerCells[i]?.style.textAlign;
if (align) td.style.textAlign = align;
if (c.type === "number") {
td.className = "is-num";
td.textContent = summarize(c, all, fn).text;
} else if (!labelled && i === 0) {
td.className = "md-summary-label";
td.textContent = AGGREGATES.find(([k]) => k === fn)[1];
labelled = true;
} else {
td.className = "is-muted";
td.textContent = summarize(c, all).text;
}
if (i === 0 && labelInFirst) { td.className = "md-summary-label"; td.appendChild(select); }
else if (measure(c)) { td.className = "is-num"; td.textContent = summarize(c, all, fn).text; }
tr.appendChild(td);
});
};
@@ -135,17 +134,12 @@ function enhance(table) {
sigma.setAttribute("aria-pressed", "false");
sigma.title = "Show a summary row";
sigma.innerHTML = '<span aria-hidden="true">Σ</span><span class="md-table-btn-text">Summary</span>';
select = doc.createElement("select");
select.className = "md-table-agg";
select.setAttribute("aria-label", "Summary");
select.hidden = true;
AGGREGATES.forEach(([k, text]) => { const o = doc.createElement("option"); o.value = k; o.textContent = text; select.appendChild(o); });
select.addEventListener("change", () => { fn = select.value; renderFoot(); });
if (!labelInFirst) select.hidden = true;
sigma.addEventListener("click", () => {
const on = !foot;
sigma.setAttribute("aria-pressed", on ? "true" : "false");
sigma.classList.toggle("is-on", on);
select.hidden = !on;
if (!labelInFirst) select.hidden = !on;
if (on) {
foot = doc.createElement("tfoot");
foot.className = "md-summary";
@@ -154,7 +148,8 @@ function enhance(table) {
renderFoot();
} else { foot.remove(); foot = null; }
});
tools.append(sigma, select);
tools.appendChild(sigma);
if (!labelInFirst) tools.appendChild(select);
}
const open = doc.createElement("button");
open.type = "button";