Skip to content

Fix degenerate MultiPolygon centroids#7921

Open
swjturay wants to merge 2 commits into
plotly:masterfrom
swjturay:agent/fix-degenerate-geojson-centroid
Open

Fix degenerate MultiPolygon centroids#7921
swjturay wants to merge 2 commits into
plotly:masterfrom
swjturay:agent/fix-degenerate-geojson-centroid

Conversation

@swjturay

Copy link
Copy Markdown

Overview

Fixes #7874.

Prevent a zero-area MultiPolygon feature from aborting choropleth rendering. When centroid selection cannot find a positive-area sub-polygon, the feature now receives the existing [NaN, NaN] centroid sentinel. Its geometry remains available for rendering, while valid sibling features continue through extraction.

Root cause and user impact

The MultiPolygon centroid path initialized maxArea to zero and only selected sub-polygons whose area was strictly greater. If every sub-polygon had zero area, the selected polygon remained undefined and was passed to Turf's centroid helper, causing an uncaught TypeError that stopped the entire plot.

The guard is limited to that no-positive-area case. Centroid calculation for valid Polygon and MultiPolygon features is unchanged.

Validation

  • Added a regression test using the issue's two-distinct-vertex degenerate ring alongside a valid polygon.
  • Verified the regression test failed before the source change with Cannot read properties of undefined (reading 'type').
  • npm run test-jasmine -- lib_geo_location_utils choropleth --nowatch --report-spec — 37/37 passed (Chromium-based Edge via CHROME_BIN).
  • npm run test-syntax
  • npm run lint
  • git diff --check

@swjturay
swjturay marked this pull request as ready for review July 26, 2026 13:01
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.

[BUG]: choropleth with custom GeoJSON: a single malformed feature throws an uncaught TypeError and blanks the entire plot

1 participant