Skip to content

Web UI: switchable column color coding modes - #108873

Merged
alexey-milovidov merged 10 commits into
masterfrom
play-color-coding-modes
Jul 1, 2026
Merged

alexey-milovidov merged 10 commits into
masterfrom
play-color-coding-modes

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Jun 29, 2026 •

Copy link
Copy Markdown
Member

Add a per-column color coding switch to the Web UI (play.html).

A 🌈 toggle appears at the right of each column header on hover (or, on touch devices, while the header is pressed) and cycles the column's visualization mode:

  • Numeric and Date/DateTime columns: bar → heatmap → categorical → none.
  • Other columns: none ↔ categorical.

heatmap colors the whole cell background by the value scaled between the column's min and max. categorical hashes the value to a hue. Both use oklch with only the hue varying, while the lightness and chroma are fixed per theme so the cell text stays readable. Date/DateTime/Date32/DateTime64 columns are colored by their time value (default none), and their bar mode spans the min..max range instead of a meaningless zero baseline.

In categorical mode, selecting a cell emphasizes the other cells that share its value with a heavier font and a full-contrast text color (pure white in the dark theme, pure black in the light theme); the active cell itself is left unemphasized. The emphasis is debounced by 100 ms and uses an O(1) fast path when only the value-preserving active cell moves.

The chosen modes are remembered per column in the URL and browser history, so reloads, shared links, and back/forward keep them (default modes are not stored, to keep the URL and state compact). Heatmap/categorical backgrounds fill the whole cell even when a row is taller than one line, and the vertical (transposed) single-row layout shows no color coding.

Changelog category (leave one):

  • New Feature

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Web UI: added a per-column color coding switch (the 🌈 icon in a column header) to toggle between bar, heatmap, categorical, and no visualization. The selected modes are remembered in the URL and browser history.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Test with this query:

WITH arrayStringConcat(['fuck', 'shit', 'trash', 'crap', 'garbage', 'happiness', 'happy'], '|') AS words
SELECT time, author, extract(line, words) AS word, path, line,
FROM "git_clickhouse"."line_changes" WHERE match(line, words) AND sign = 1
ORDER BY time, path LIMIT 1 BY time, path

Add a per-column color coding switch to the Web UI (`play.html`). A 🌈
toggle appears at the right of each column header on hover (or, on touch
devices, while pressed) and cycles the column's visualization mode:

- Numeric and Date/DateTime columns: `bar` -> `heatmap` -> `categorical`
  -> `none`.
- Other columns: `none` <-> `categorical`.

`heatmap` colors the whole cell background by the value scaled between the
column's min and max; `categorical` hashes the value to a hue. Both use
`oklch` with only the hue varying, while the lightness and chroma are fixed
per theme so the cell text stays readable. Date/DateTime/Date32/DateTime64
columns are colored by their time value (default `none`), and their `bar`
mode spans the min..max range instead of a meaningless zero baseline.

In `categorical` mode, selecting a cell emphasizes the other cells that
share its value with a heavier font and a full-contrast text color (pure
white in the dark theme, pure black in the light theme); the active cell
itself is left unemphasized. This refresh is debounced by 100 ms and uses an
O(1) fast path when only the value-preserving active cell moves.

The selected modes are remembered per column in the URL and browser history
(default modes are not stored, to keep them compact). Heatmap/categorical
backgrounds fill the whole cell even when a row is taller than one line, and
the vertical (transposed) single-row layout shows no color coding.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Jun 29, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [8922e01]

Summary: ✅


AI Review

Summary

This PR adds per-column color coding modes to the built-in Web UI, including mode cycling from the column header, URL/history persistence, date/time scaling, categorical same-value emphasis, and a small reference doc. I rechecked the current implementation against the prior review threads and the author's follow-up comments; the previously raised issues around timezone-stable date parsing, multi-query repainting, unsupported mode leakage, totals coloring, coarse-pointer activation, vertical-layout emphasis, and empty-result transpose behavior are addressed or deliberately documented.

Final Verdict

✅ Approve. I found no remaining blockers or major issues in the current diff. I also ran a syntax check on the extracted inline script with node --check.

@clickhouse-gh clickhouse-gh Bot added the pr-feature Pull request with new product feature label Jun 29, 2026
Comment thread programs/server/play.html Resolved
Comment thread programs/server/play.html Resolved
Fix two issues raised in review of the column color coding feature:

- Parse `Date`/`DateTime` values with `Date.UTC` from the calendar
  components instead of the timezone-dependent `Date.parse`, so the
  bar/heatmap scale is stable and monotonic regardless of the viewer's
  browser timezone and DST.
- Since color modes are shared by column name (and persisted in the URL),
  repaint the changed column and refresh its header toggle title across all
  visible `query-result` tables, not only the clicked one, so multi-query
  results stay in sync.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

Addressed both review findings in 705f9e8:

  1. Timezone-dependent Date/DateTime scaling — _parseNumeric now parses the calendar components with a regex and combines them via Date.UTC(...) instead of the local-timezone Date.parse. The value is now independent of the viewer's browser timezone/DST and monotonic. Verified the DST-transition example produces identical, strictly increasing values in America/Los_Angeles, UTC, and Asia/Tokyo.

  2. Stale colors in multi-query tables — since modes are intentionally shared by column name (and persisted in the URL), _cycleColorMode now repaints the changed column and refreshes its header toggle title across all visible query-result elements via a new refreshColumnColor, not just the clicked table. Verified that toggling a shared column in one table updates the background and toggle title in the other.

Comment thread programs/server/play.html Resolved
Comment thread programs/server/play.html Resolved
- Clamp the shared per-column mode to the modes supported by each table's
  column type in `_effectiveColorMode`. In multi-query mode a numeric
  column's `heatmap` no longer leaks into a string column of the same name
  (which showed a wrong title and broke its none <-> categorical cycle); it
  falls back to the column's default there.
- Keep the fractional seconds outside the `Date.UTC` millisecond argument
  (which truncates to an integer) and add them to the returned value, so
  sub-millisecond `DateTime64` values stay ordered and scalable.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

Addressed the second review round in 30146a8:

  1. Mode leaking across same-named columns of different types — _effectiveColorMode now clamps the stored mode to the modes supported by the current column's type (a shared _colorModeCycle helper). A numeric column's heatmap no longer leaks into a string column of the same name: the string column falls back to its default (none), shows the correct title, and its none ↔ categorical cycle works again (no more idx == -1). Verified with SELECT 1 AS x + SELECT 'a' AS x.

  2. Sub-millisecond DateTime64 collapse — the fractional seconds are now added to the returned value outside Date.UTC (whose ms argument truncates to an integer), so sub-millisecond values stay ordered and scalable down to the precision of a JS double. Verified that …000, …000.001, …000.999, …001, …002 parse to strictly increasing, all-distinct values.

Comment thread programs/server/play.html Resolved
alexey-milovidov and others added 2 commits June 30, 2026 02:38
Render totals before applying colors in both the fresh-query and
history-restore paths, so the `WITH TOTALS` row (which `_colorTargetRows`
includes) is colored on the initial render exactly as it is after a later
toggle, instead of staying uncolored until the first toggle.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Document in `_parseNumeric` that the date value is a JS double, exact to
roughly microsecond precision near modern timestamps. `Date`, `DateTime`
and `DateTime64` up to microseconds are ordered/scaled correctly; sub-
microsecond `DateTime64(9)` differences are not distinguished in the color
scale, which is acceptable for a visualization and would otherwise require
BigInt arithmetic throughout the range and normalization code.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

Third review round:

  1. Totals row uncolored on first paint (line 3627) — fixed in bb64a53. renderTotals now runs before applyColumnColors in both the fresh-query and history-restore paths, so the WITH TOTALS row is colored on the initial render exactly as it is after a later toggle. Verified with a GROUP BY ... WITH TOTALS query that the totals cell gets its bar on first paint.

  2. Sub-microsecond DateTime64(9) ordering (line 2081) — documented as a deliberate limitation in 76d957f rather than fixed. The value is a JS double, so it is exact to ~microsecond precision near modern timestamps; Date, DateTime, and DateTime64 up to microseconds order and scale correctly. Distinguishing sub-microsecond differences in a color gradient is not visually meaningful, and supporting it would require threading BigInt arithmetic through the range and heatmap/bar normalization that all numeric columns share — extra complexity and risk in a hot path for no perceptible benefit. The microsecond example from the earlier thread (.000001 vs .000999) is correctly ordered.

Comment thread programs/server/play.html Resolved
alexey-milovidov and others added 2 commits June 30, 2026 17:02
The `.colorize-toggle` icon was `display: none` until `th:active`, so on
touch and other coarse-pointer devices (which have no hover) a tap was
hit-tested against the `th` rather than the still-hidden icon span. The
span's `click` handler that calls `_cycleColorMode` therefore never fired,
and the color switch could not be activated at all on touch devices.

Replace the `th:active` visibility rule with a `@media (hover: none),
(pointer: coarse)` rule that keeps the icon always visible there, so it is
hit-testable and a tap lands directly on it. The icon sits left of the
resizer and does not overlap it, so column resizing is unaffected.

Addresses the review finding on `programs/server/play.html`.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Add a documentation page for the per-column color coding feature of the
built-in Web SQL UI: the `bar`, `heatmap`, `categorical`, and `none` modes,
the per-type defaults and available cycles, the categorical selection
emphasis, and the per-column persistence in the URL and browser history.

This is a user-facing New Feature, so it requires documentation; the change
also satisfies the `feature_docs.py` workflow hook, which fails when a
feature PR touches no file under `docs/`.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

continue-pr status

Pushed 76d957f3c62..1dbf82290ae (2 commits) addressing the two actionable items.

1. Touch-device color toggle (AI Review Major + the one unresolved thread) — fixed in 0404be5.
The .colorize-toggle icon was display: none until th:active, so on touch / coarse-pointer devices (no hover) a tap hit-tested to the th and the span's click handler that calls _cycleColorMode never fired. Replaced the th:active rule with a @media (hover: none), (pointer: coarse) rule that keeps the icon always visible, so it is hit-testable and a tap lands directly on it. The icon sits left of the resizer and does not overlap it, so column resizing is unaffected. There is no browser test harness for play.html in the repo, so the AI's suggested coarse-pointer browser check was verified by reasoning about the CSS hit-testing.

2. Finish Workflow / feature_docs.py failure — fixed in 1dbf822.
The PR is labeled New Feature but previously touched only programs/server/play.html, so the hook failed ("No documentation changes found"). Added docs/en/interfaces/web-ui-color-coding.md documenting the modes, per-type defaults, categorical selection emphasis, and URL/history persistence; checked the documentation box in the PR description.

Remaining CI reds are unrelated to this play.html/docs-only change (zero C++ touched) and already tracked:

Comment thread programs/server/play.html Resolved
Comment thread programs/server/play.html Resolved
alexey-milovidov and others added 2 commits June 30, 2026 20:09
Address two regressions in the transposed/vertical single-row result
layout of `play.html`, reported in review.

`_refreshCategoricalEmphasis` could still apply categorical emphasis in
the vertical layout. After `transposeIfNeeded` the table has no `tHead`
and every value cell has `cellIndex == 1`, so a persisted or global
`categorical` mode for the first column made selecting any value bold
and recolored matching cells, violating the documented contract that
the vertical layout shows no color coding. It now bails out (clearing
any leftover emphasis) when the table has no header row, matching the
existing `refreshColumnColor` guard. The shared clearing logic is
factored into `_clearCategoricalEmphasis`.

`_willTranspose` made the empty wide-result case unreachable: a zero-row
result with more than five columns rendered only a horizontal header and
lost the `empty result` marker, because `!table.rows[0]` short-circuited
to `false`. It now transposes when there are no data rows, and applies
the cell-count check only to single-row results, restoring the previous
behavior.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
`docs/en/interfaces/web-ui-color-coding.md` is a standalone reference
page that is not wired into the docs site sidebar (like the sibling
`web-terminal` page), so the `clickhouse-docs` docusaurus build's
floating-pages check failed it with "Found floating pages without
sidebars".

Mark it with `sidebar: false` in the frontmatter, which the
`checkFloatingPages.js` plugin honors as an explicit opt-out
(`if (data.sidebar === false) continue;`), instead of relying on a
separate exception-list entry in the `clickhouse-docs` repository. This
keeps the fix self-contained in this pull request. The frontmatter
validator permits the extra field and `false` value, so the markdown
check still passes.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=108873&sha=1dbf82290aee8054f2182106721ec7d6491d1824&name_0=PR&name_1=Docs%20check

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

continue-pr status

Pushed 1dbf82290ae..6d6b3606d30 (2 commits) addressing the AI Review ⚠️ Request changes verdict (both Majors) and the two unresolved review threads, plus the docs build red.

1. Categorical emphasis leaked into the vertical layout (play.html, thread @ line 2392) — fixed in d497ea7d35e.
applyColumnColors already skips the transposed/vertical layout, but the delayed selection path did not: after transposeIfNeeded the table has no tHead and every value cell has cellIndex == 1, so a persisted/global categorical mode for the first column made selecting any value bold/recolor matching cells — violating the documented "vertical layout shows no color coding" contract. _refreshCategoricalEmphasis now bails out (clearing any leftover emphasis via the new _clearCategoricalEmphasis helper) when this._dataTable.tHead is absent, matching the existing refreshColumnColor guard.

2. _willTranspose broke empty-result display (play.html) — fixed in d497ea7d35e.
Extracting _willTranspose made !table.rows[0] short-circuit to false for zero-row results, so empty results stopped transposing and lost the empty result marker (the marker is rendered only inside transposeIfNeeded), leaving just a horizontal header. It now returns true when there are no data rows and applies the cells.length > 5 check only to single-row results, exactly restoring the pre-extraction behavior.

3. Docs build (Docs check / Build docusaurus) — fixed in 6d6b3606d30.
The standalone docs/en/interfaces/web-ui-color-coding.md page (added earlier to satisfy feature_docs.py) is not wired into the docs-site sidebar, so the floating-pages check failed it. Added sidebar: false to the frontmatter, which checkFloatingPages.js honors as an explicit opt-out (if (data.sidebar === false) continue;), keeping the fix self-contained instead of needing a separate clickhouse-docs exception-list entry. The frontmatter validator permits the extra field and false value, so check-markdown still passes.

JS syntax of play.html verified with node --check on the extracted inline script. There is no browser test harness for play.html in the repo, so the two behavior fixes were verified by reading the code paths (header <th> are direct <thead> children so table.rows excludes the header; the transposed table has no tHead).

These were the only CI reds on the latest commit. Both review threads resolved.

…odes

# Conflicts:
#	programs/server/play.html
@alexey-milovidov

Copy link
Copy Markdown
Member Author

continue-pr status

Rechecked head 8922e019a59: AI Review ✅ Approve (no remaining blockers or majors), 0 unresolved review threads, MERGEABLE.

No re-merge needed — merge-base cb507a96d4f is under a day old, and master touches neither programs/server/play.html nor the docs page since then.

The sole CI red is a known, unrelated flake. Stateless tests (amd_asan_ubsan, distributed plan, parallel, 2/2) failed on 03360_bool_remote with Unexpected packet from server (expected TablesStatusResponse, got ProfileInfo) (UNEXPECTED_PACKET_FROM_SERVER) — a server-side distributed connection-pool desync. This PR changes only play.html and one documentation file (zero C++), so it cannot cause this. It is exactly the flake being fixed in #108854. Since that job's workflow run had completed, I re-ran the failed job to clear the Mergeable Check gate.

The remaining non-green check is CH Inc sync (PENDING, private) — not a failure.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

continue-pr status

Rechecked head 8922e019a59: the PR is now fully green and merge-ready, superseding the previous status (which still cited a CI red and a pending sync gate).

No re-merge needed — merge-base cb507a96d4f is under a day old, and master has touched neither programs/server/play.html nor the docs page since then.

No code, re-merge, re-run, or sync fix was required. Blocked only on a human approval and merge.

@alexey-milovidov alexey-milovidov self-assigned this Jul 1, 2026

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice.

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Jul 1, 2026
Merged via the queue into master with commit dbf0b4d Jul 1, 2026
343 of 344 checks passed
@alexey-milovidov
alexey-milovidov deleted the play-color-coding-modes branch July 1, 2026 21:05
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 1, 2026
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…g-modes

Web UI: switchable column color coding modes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-feature Pull request with new product feature pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants