Skip to content

fix(adapters): draw a geo_histogram2d overlay target and fade its background - #103

Merged
jvdd merged 1 commit into
mainfrom
fix/geo-overlay-heatmap-extent
Sep 27, 2026
Merged

jvdd merged 1 commit into
mainfrom
fix/geo-overlay-heatmap-extent

Conversation

@jvdd

@jvdd jvdd commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #97.

A geo_histogram2d that another figure filters in overlay mode did not draw correctly. This PR fixes the two bugs behind that.

The crash

heatmapZFiniteExtent read z as rows of cells. A choropleth has a flat z, so the inner loop threw (row || []) is not iterable:

  • With a linear norm, the throw came from syncHeatmapOverlayColorScale and stopped the render. The map kept only its background layer.
  • With a log norm, the throw came from heatmapHasRenderableCells, after the render, in fvFinalizeHeatmapOverlayColorbars. The colorbar stayed on the background layer.

heatmapZFiniteExtent now takes the trace and reads the flat z of a choropleth as one row. It branches on the trace type, as the log norm does, instead of guessing from the data shape.

The background was never faded

Once the crash was fixed, a second bug showed: the background layer of the map was drawn at full strength, so the cells outside the selection looked like filtered data. Plotly's choroplethmap has no trace-level opacity (checked in the Plotly.js 3.0.0 schema), so OVERLAY_BG_OPACITY had no effect on it. Maplibre painted the layer at fill-opacity: 1.

The new applyChoroplethLayerOpacity puts the layer opacity on the marker opacity of each cell. With a log norm, it multiplies with the per-cell values that hide the cells at or below 0.

Before this change, the overlay design for heatmap-like targets was reviewed with a demo on real data. The decision was to keep it as it is for now, and to consider dropping overlay for these targets later: #104.

A review of this PR found a problem that is older than this PR: after a zoom with an active selection, the background of a filtered_only trace keeps its pre-zoom grid, and a box selection on such a zoomed map gets a wrong box. It is recorded in #104 and not fixed here.

Tests

  • New browser test test_overlay_map_fades_background_under_filtered_layer, with three cases: a linear norm, a log norm, and a log norm on a signed histfunc="sum".
    • No page errors, and only the filtered layer shows a colorbar.
    • The filtered cells are a strict subset of the background cells.
    • Each cell has its layer's opacity (0.16 in the background, 1 in the filtered layer), and a log cell at or below 0 has opacity 0 in both layers.
  • The test fails on main, with the crash fix alone, and when the fade overwrites the per-cell log opacities with one value.
  • make test: 2390 passed, 2 skipped. make test-browser: 316 passed, 12 skipped. ruff is clean.
  • A probe on this branch reads the painted maplibre fill-opacity: 0.16 for the background layer and 1 for the filtered layer with a linear norm.

@codspeed

codspeed Bot commented Sep 27, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 31 untouched benchmarks


Comparing fix/geo-overlay-heatmap-extent (a5cb5ea) with main (591171d)

Open in CodSpeed

@jvdd
jvdd requested a lite review from Copilot September 27, 2026 15:19

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@jvdd
jvdd force-pushed the fix/geo-overlay-heatmap-extent branch from 289b462 to a5cb5ea Compare September 27, 2026 15:56
@jvdd
jvdd merged commit 771b7e6 into main Sep 27, 2026
18 checks passed
@jvdd
jvdd deleted the fix/geo-overlay-heatmap-extent branch September 27, 2026 16:16
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.

geo_histogram2d overlay target: heatmapZFiniteExtent cannot read a flat choropleth z

2 participants