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

+30 -7
View File
@@ -79,7 +79,28 @@ describe("Table analysis", function () {
expect(T.summarize(t.columns[3], all(t), "mean").text).to.equal("443.8");
expect(T.summarize(t.columns[3], all(t), "count").text).to.equal("5");
expect(T.summarize(t.columns[3], all(t), "sum").text).to.equal("2,219");
expect(T.summarize(t.columns[0], all(t)).text).to.equal("3 distinct");
// Text and identifier columns stay empty in the summary row.
expect(T.summarize(t.columns[0], all(t))).to.deep.equal({ kind: "none", text: "" });
expect(T.summarize(t.columns[1], all(t), "mean").kind).to.equal("none");
expect(T.summarize(t.columns[1], all(t), "mean", () => true).text).to.equal("1.5");
});
});
describe("identifier columns", () => {
const ids = (text) => table(text).columns.map((c) => c.identifier);
it("recognizes seed, id, run, fold, index and year by name", () => {
expect(ids("seed,run_id,fold,index,year,Trial,accuracy\n1,10,0,5,2024,3,71.2\n2,11,1,6,2025,4,71.4\n")).to.deep.equal([true, true, true, true, true, true, false]);
expect(ids("modelId,seeds,n_runs\n4,1,7\n9,2,8\n")).to.deep.equal([true, true, true]);
});
it("recognizes small consecutive whole numbers that repeat across rows", () => {
expect(ids("k,v\n1,5\n2,9\n3,4\n1,7\n2,2\n3,1\n")).to.deep.equal([true, false]);
expect(ids("k\n0\n1\n0\n1\n")).to.deep.equal([true]);
});
it("leaves measures alone: decimals, percents, gaps, big ranges, negatives, unique values", () => {
expect(ids("a,b,c,d,e\n1.0,1%,1,410,-1\n2.0,2%,3,414,0\n1.0,1%,1,445,-1\n2.0,2%,3,449,0\n")).to.deep.equal([false, false, false, false, false]);
expect(ids("epochs,plausible\n10,410\n20,414\n")).to.deep.equal([false, false]);
expect(ids("seed,name\nx,y\n")).to.deep.equal([false, false]);
expect(ids("seed\n1.5\n2.5\n")).to.deep.equal([false]);
});
});
@@ -120,18 +141,20 @@ describe("Table analysis", function () {
it("reproduces the mean per model over seeds", () => {
const t = table(RESULTS);
const g = T.groupTable(t, all(t), 0, "mean");
expect(g.header).to.deep.equal(["model", "Rows", "seed", "accuracy", "plausible"]);
expect(g.body).to.deep.equal([["Baseline", "2", "1.5", "71.2", "412.0"], ["+ Aug.", "2", "1.5", "74.0", "447.0"], ["Ours", "2", "1.5", "78.9", "501.0"]]);
expect(g.columns[3].agg).to.equal("mean");
expect(g.columns[3].keys[0]).to.be.closeTo(71.2, 1e-9);
expect(g.header).to.deep.equal(["model", "Rows", "accuracy", "plausible"]);
expect(g.body).to.deep.equal([["Baseline", "2", "71.2", "412.0"], ["+ Aug.", "2", "74.0", "447.0"], ["Ours", "2", "78.9", "501.0"]]);
// "Treat as number" brings the seed back.
expect(T.groupTable(t, all(t), 0, "mean", (c) => true).header).to.deep.equal(["model", "Rows", "seed", "accuracy", "plausible"]);
expect(g.columns[2].agg).to.equal("mean");
expect(g.columns[2].keys[0]).to.be.closeTo(71.2, 1e-9);
});
it("groups only the filtered rows and can be sorted, counted and exported", () => {
const t = table(RESULTS);
const g = T.groupTable(t, T.filterIndices(t, { ranges: { 1: [1, 1] } }), 0, "max");
expect(g.body.map((r) => r[0])).to.deep.equal(["Baseline", "+ Aug.", "Ours"]);
const order = T.sortIndices(g, [0, 1, 2], 3, "desc");
const order = T.sortIndices(g, [0, 1, 2], 2, "desc");
expect(order.map((i) => g.body[i][0])).to.deep.equal(["Ours", "+ Aug.", "Baseline"]);
expect(T.toMarkdown(g.header, order.map((i) => g.body[i]), g.columns.map((c) => c.type === "number")).split("\n")[1]).to.equal("| --- | ---: | ---: | ---: | ---: |");
expect(T.toMarkdown(g.header, order.map((i) => g.body[i]), g.columns.map((c) => c.type === "number")).split("\n")[1]).to.equal("| --- | ---: | ---: | ---: |");
});
it("labels empty groups", () => {
const t = table("k,v\na,1\n,2\na,3\n");