Repository navigation
feat(heatmap): add color_norm with a log option to histogram2d and geo_histogram2d - #95
Merged
Merged
Conversation
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Preserve positional API compatibility and validate unsupported decoded normalization values.
Get a fresh assessment by requesting another Copilot review.
Review effort: Lite
Findings: 2
Open (2)
What changed in this PR
Adds optional logarithmic color normalization for 2D and geographic heatmaps, including Plotly transforms, raw hover values, data-unit ticks, tests, and documentation.
Changes:
- Adds
color_norm="linear"|"log"to histogram APIs and specifications. - Handles log-space coloring, ranges, ticks, and overlays.
- Adds unit/browser coverage and documentation updates.
Required changes:
- Preserve the existing positional
axesargument order inFigureandHistogram2D. - Reject unsupported decoded normalization values instead of silently rendering linearly.
| File | Summary |
|---|---|
tests/test_trace_hist2d.py |
Tests histogram normalization and round trips. |
tests/test_trace_geo_hist2d.py |
Tests geographic histogram normalization. |
tests/test_spec.py |
Tests serialization and mixed styles. |
tests/test_html_adapters.py |
Tests Plotly range conversion. |
tests/test_hist_helpers.py |
Tests normalization validation. |
tests/test_browser.py |
Tests rendering, ticks, hover, and overlays. |
flexviz/trace/hist2d.py |
Adds histogram normalization support. |
flexviz/trace/geo_hist2d.py |
Adds geographic normalization support. |
flexviz/trace/_hist_helpers.py |
Validates normalization options. |
flexviz/spec.py |
Extends display metadata. |
flexviz/figure.py |
Exposes the API and validates styles. |
flexviz/adapters/plotly_adapter.py |
Converts fixed ranges to log space. |
flexviz/adapters/js/plotly/traces.js |
Applies log coloring and custom ticks. |
CHANGELOG.md |
Documents the feature. |
Architecture.md |
Updates architecture documentation. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This was referenced Sep 25, 2026
Open
jvdd
force-pushed
the
feat/heatmap-color-norm
branch
from
September 27, 2026 09:09
f396838 to
d62f944
Compare
jvdd
force-pushed
the
feat/heatmap-color-norm
branch
from
September 27, 2026 09:16
d62f944 to
e6803c8
Compare
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

A density heatmap of a large dataset is often dominated by a few dense bins. With a linear color scale, most of the map then stays dark. This PR adds
color_normtoadd_histogram2dandadd_geo_histogram2d:"linear"(default) or"log".Design
color_normis a style hint inTraceSpec.display, next tocolor_scaleandcolor_range. The traces validate it. Aggregation and deltas do not change, so a delta still carries raw values.log10(z)(applyLogColorNorminplotly/traces.js). It runs when a trace is built from its template, so it covers every delta, from the server or the cube. The template keeps a fixedcolor_rangein data units.text, formatted with.10~r(so0.15, not0.15000000000000002). An empty cell hovers asNaN, as with the linear norm.1e-7,1e15).color_rangemust be above 0 with a log norm.color_normwith the same helper as the traces, and it rejects a log norm oncorr_heatmap. Decoded specs skip trace validation: invalid display values give HTTP 500 at /view, and /share accepts them #99 moves this validation to the server.color_norm, likecolor_scaleandcolor_range. The check now includesgeo_histogram2d, which it skipped before (separate commit).CorrHeatmaphas nocolor_normand stays linear. ECharts ignores it.color_norm, notlog_color: bool, so a later norm (for example equal-histogram) needs no new parameter.Performance
A 1320 × 1150 grid in Chromium, median of 5 renders, log compared with linear:
Building a log layer costs about 60 ms more than a linear one. About half of that is the copy of the raw values for the hover. One pass builds both grids. Plotly renders a pinned range a little faster, which recovers part of the cost.
Tests
geo_histogram2dfigure.<= 0imported style is rejected with the right message.make test: 2390 passed, 2 skipped.make test-browser: 313 passed, 9 skipped.mkdocs build --strictpasses.Not changed
geo_histogram2das an overlay target does not update on a cross-filter. It is older than this PR, and the fix follows this PR./view.color_scalenames, so the default"viridis"renders asReds.histogram2dbin showsz: NaN, with both norms. That issue also decides whether the log norm keeps its copy of the values for the hover (about 10–20 ms per 1320 × 1150 layer).