Skip to content

geo_histogram2d overlay target: heatmapZFiniteExtent cannot read a flat choropleth z #97

Closed

Description

@jvdd

Problem

heatmapZFiniteExtent (flexviz/adapters/js/plotly/traces.js) reads z as rows of cells. A heatmap has that shape. A choropleth (geo_histogram2d) has a flat z, one value per drawn cell. The inner loop then throws TypeError: (row || []) is not iterable.

Two callers pass a choropleth z when a geo_histogram2d is the target of an overlay cross-filter:

  • syncHeatmapOverlayColorScale, for an auto color_range with a linear color_norm. The error stops the render: the map shows only the background layer, and the figure logs flexviz render failed for figure ….
  • heatmapHasRenderableCells, which fvFinalizeHeatmapOverlayColorbars calls after the render. With color_norm="log" (PR feat(heatmap): add color_norm with a log option to histogram2d and geo_histogram2d #95), the render gets past the sync, because the log norm sets its own range. Then this call throws an uncaught error. Both layers draw, but the colorbar stays on the background layer.

Reachability

Public API only: a dashboard with a geo_histogram2d and another figure, overlay mode, and a selection on the other figure. Reproduced in a browser on feat/heatmap-color-norm (f396838), with a linear and with a log norm. The linear auto-range path is the same code on main.

Fix

Let heatmapZFiniteExtent read both shapes, so that every caller works:

  // z is 2-D for a heatmap and flat for a choropleth.
  const rows = Array.isArray(z && z[0]) ? z : [z || []];
  for (const row of rows) {

Checked in a scratch copy of the branch: with this change, both norms draw both layers, the colorbar moves to the filtered layer, and the console has no errors.

Regression test

For tests/test_browser.py, for example in TestHeatmapColorNormBrowser (it uses _color_norm_url from PR #95). It fails on f396838 for both norms, because the colorbar never moves to the filtered layer. It passes with the fix.

Browser test
    @pytest.mark.parametrize("color_norm", ["linear", "log"])
    def test_geo_histogram2d_overlay_target_renders_both_layers(
        self, page: Page, server_port: int, color_norm
    ):
        errors: list[str] = []
        page.on("pageerror", lambda exc: errors.append(str(exc)))
        page.on(
            "console",
            lambda msg: (
                errors.append(msg.text) if "render failed" in msg.text else None
            ),
        )
        df = pl.DataFrame(
            {
                "ts": list(range(500)),
                "val": [float(i) for i in range(500)],
                "lat": [float(i % 25) for i in range(500)],
                "lon": [float((i * 7) % 25) for i in range(500)],
            }
        )

        def build(dash):
            dash.add_figure(title="Source").add_line(x="ts", y="val", n_points=200)
            dash.add_figure(title="Map").add_geo_histogram2d(
                lat="lat", lon="lon", lat_bins=5, lon_bins=5, color_norm=color_norm
            )

        url = _color_norm_url(
            server_port, f"_browser_geo_overlay_{color_norm}", df, build
        )
        page.goto(url)
        _wait_for_init(page, "plotly")

        page.click("#fv-btn-cfmode")
        page.evaluate("""() => {
            const figUids = DASHBOARD_SPEC.figures.map(f => f.uid);
            DASHBOARD_SPEC.state.selections = [{
                source_figure_uid: figUids[0],
                predicates: [{ clauses: [{ column: 'ts', range: [100, 200] }] }],
            }];
            return postDashboardUpdate({
                type: 'selection',
                selections: DASHBOARD_SPEC.state.selections,
                force_update: true,
            });
        }""")
        # The colorbar moves to the filtered layer once the overlay render ends.
        page.wait_for_function(
            """() => {
                const gd = document.querySelectorAll('.js-plotly-plot')[1];
                const fg = gd.data.find(t => t.uid.endsWith('__fv_layer_fg'));
                return fg && fg.showscale === true;
            }""",
            timeout=10_000,
        )
        assert errors == []

Activity

  1. added
    bug
    on Sep 25, 2026
  2. jvdd commented on Sep 26, 2026

    @jvdd
    ContributorAuthor

    Reproduced on unmodified main (471c09b), not only on the PR #95 branch. Setup: a line figure and a geo_histogram2d (4x4 bins), overlay mode, then a selection on the line (ts in [50, 150]). The map keeps only its __fv_layer_bg trace. The console logs flexviz render failed for figure … TypeError: (row || []) is not iterable at heatmapZFiniteExtent. The error is logged as a warning, so it stays silent: a map that is an overlay target never shows the filtered layer.

  3. jvdd commented on Sep 29, 2026

    @jvdd
    ContributorAuthor

    Fixed by #103.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions