Skip to content

feat(inputs): add header option to table input - #1429

Open
kasivisu4 wants to merge 2 commits into
uwdata:mainfrom
kasivisu4:feat/table-header
Open

kasivisu4 wants to merge 2 commits into
uwdata:mainfrom
kasivisu4:feat/table-header

Conversation

@kasivisu4

@kasivisu4 kasivisu4 commented Nov 24, 2026 •

Copy link
Copy Markdown

Why

The table input shows raw column names in its header row, so a table over dep_delay cannot say "Departure delay (min)". Closes #1408. The table in @observablehq/inputs has the same header option.

What changed

File Change
packages/vgplot/inputs/src/Table.js New header option. It maps a column name to a label, either a string or an HTML or SVG element.
packages/vgplot/spec/src/spec/Input.ts header?: { [column: string]: string } on the Table spec type, so YAML and JSON specs can set it.
packages/vgplot/vgplot-python/vgplot/plot.py header argument on vg.table_input.
docs/api/inputs/table.md Documents the option.
packages/vgplot/inputs/test/table.test.js Four new tests.

The core of the change is the label lookup in Table.prepare():

const label = Object.hasOwn(this.header, column) ? (this.header[column] ?? column) : column;
th.appendChild(label instanceof HTMLElement || label instanceof SVGElement
  ? label
  : document.createTextNode(String(label)));

Usage:

vg.table({ from: 'flights', header: { delay: 'Arrival delay (min)', time: html`<b>Time</b>` } })
input: table
from: flights
header: { delay: Arrival delay (min) }
vg.table_input(source=flights, header={"delay": "Arrival delay (min)"})

Scope

A label changes only the header text. Sorting, align, width, format, and the output selection still use the column name.

Notes

  • Object.hasOwn is used instead of in, so a column named constructor shows its own name.
  • A null or undefined label falls back to the column name.
  • Element labels follow the same rule as format cells: an HTMLElement or SVGElement is appended as is, and any other value is shown as text. An element is moved, not cloned, so the docs say to use one element per column.
  • Tables without header render exactly as before.

Verification

  • pnpm test (936 passed), pnpm lint, pnpm docs:build, ruff, and the vgplot-python tests pass.
  • Five new tests cover string, HTML, and SVG labels, nullish fallback, prototype-named columns, and sorting by a relabeled column. Each test fails when its behavior is broken on purpose.
  • Checked in pnpm dev with a YAML spec, ESM mode, and the JavaScript API, and with vg.table_input(...).to_json() in Python.
  • Tested with the pstack workflow, including an independent agent that tried to break the change.

🤖 Generated with Claude Code

Lets a table show readable labels in place of raw column names, matching
the header option of the Observable Inputs table. Closes uwdata#1408.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Match the rule table cells already use for formatted values: an
HTMLElement or SVGElement is appended, and anything else is shown as
text. A DocumentFragment label was emptied on the first render, and a
Document or Attr label threw while building the header.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support custom table headers

1 participant