Skip to content

Table.CellFill (heatmap cells) + Viridis colormap + ContrastInk - #483

Merged
tannevaled merged 3 commits into
mainfrom
table-cellfill
Oct 8, 2026
Merged

tannevaled merged 3 commits into
mainfrom
table-cellfill

Conversation

@tannevaled

@tannevaled tannevaled commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

What

  • Table.CellFill func(row, col int) (RGBA, bool) — a per-cell background, which turns a Table into a heatmap of the numbers it shows. A filled cell's text is re-inked black or white, whichever has the higher WCAG contrast with the fill. The selected row keeps its accent band (the fill yields to it). nil — the zero value — renders byte-for-byte as before.

  • Viridis(t float64) RGBA — matplotlib's perceptually uniform sequential colormap (nine reference samples, linear interpolation, clamped, NaN → 0). A shared colour scale so every heatmap in the fleet scales values the same way.

  • ContrastInk(bg RGBA) RGBA — black or white, whichever reads on bg.

  • fix(entry): clamp the caret before editing after an external Text().Set. A two-way binding that pushes a shorter value left the caret past the end; Draw clamped it, but a Backspace arriving before the next Draw sliced past the end and panicked (slice bounds out of range [8:1]). TestEntryCaretClampedAfterExternalSet panics without the clamp (negative control run).

Why

The go-ndarray WASM playground (go-ndarray/go-ndarray.github.io, playground/) shows each intermediate 2-D array as a table whose cells are coloured by value. The toolkit had no heatmap and no way to colour a cell, and the house rule is to add the capability here rather than draw it in the app.

Shareable: the go-fft playground (built in parallel) can use Viridis for a spectrogram/magnitude view and Table.CellFill for a coloured value table.

Tests

table_cellfill_test.go: fill painted in a filled cell, row background kept in a declined one, white ink on a dark fill; selection band wins over the fill (negative control: removing the guard makes this test fail); a CellFill that declines everything is byte-identical to none; frozen/scrolled path fills both regions; Viridis endpoints/clamps/NaN/midpoints and monotone luminance; ContrastInk on both ends and the linear sRGB segment. CellFill is a func hook, so the MVVM gate allows it without an allowlist entry. Root package stays at 100.0% statement coverage locally; gofmt and vet clean.

🤖 Generated with Claude Code

tannevaled and others added 2 commits October 8, 2026 09:49
CellFill(row, col) gives a body cell its own background and re-inks its
text black or white by WCAG contrast. The selected row keeps its accent
band. nil (the zero value) renders byte-for-byte as before.

Viridis(t) is the shared sequential colour scale for any heatmap, so apps
do not each invent a ramp; ContrastInk picks the readable ink on a fill.

First consumer: the go-ndarray playground shows 2-D arrays as a heatmap
table.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
A two-way binding that Sets Text() to a shorter value left the caret past
the end; Draw clamped it, but a Backspace arriving before the next Draw
sliced past the end and panicked.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@tannevaled
tannevaled merged commit 2ff4759 into main Oct 8, 2026
1 check passed
@tannevaled
tannevaled deleted the table-cellfill branch October 8, 2026 17:26
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.

1 participant