Skip to content

fix: Improve handling of auto-fitting with many features and the antimeridian on geo traces - #7948

Merged
camdecoster merged 10 commits into
v4.0from
cam/7943/handle-polygons-points-antimeridian
Aug 7, 2026
Merged

fix: Improve handling of auto-fitting with many features and the antimeridian on geo traces#7948
camdecoster merged 10 commits into
v4.0from
cam/7943/handle-polygons-points-antimeridian

Conversation

@camdecoster

@camdecoster camdecoster commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Description

Improve handling of geo trace auto-fitting with multiple features and geometry that crosses the antimeridian.

Closes #7943.

Changes

  • Refactor geo traces to take all feature geometry into account when determining the fit range
  • Add tests for plots involving the antimeridian
  • Add tests for new helpers

Screenshots

Before After
image image

Testing

  • Be on v4.0
  • Load Plotly devtools
  • Enter the following into the browser console:
      Plotly.newPlot(gd, [{
          type: 'choropleth',
          locations: ['CAN', 'USA', 'MEX'],
          locationmode: 'ISO-3',
          z: [3, 2, 1],
          showscale: false
      }], {
          geo: { projection: { type: 'equirectangular' } },
          width: 700, height: 450
      });
  • Note that the plot is split across the antimeridian
  • Switch to this branch
  • Run that snippet again
  • Note the the plot is fitted properly

Notes

  • This change is necessary is because geometry that didn't cross the antimeridian wasn't being normalized in the same way that geometry that did cross the antimeridian was
  • I reworked the way the range is padded as well to better match what happens in getAutoRange
  • A number of geo trace helpers were eliminated/changed/added to support this new method of fitting

Comment thread src/lib/geo_location_utils.js Outdated
* @param {object} trace - a `fullData` trace
* @param {object} geoLayout - the subplot's `fullLayout` entry
* @return {Array|null} `[west, south, east, north]`, or null whenever
* `fitGeojsonCoords` is empty — in which case the caller falls back to the data.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't like this pattern of describing what the calling function will do. The docstring should document this function's behavior, not the behavior of the calling function.

Suggested change
* `fitGeojsonCoords` is empty in which case the caller falls back to the data.
* `fitGeojsonCoords` is empty.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

From a data-visualization perspective, probably better to turn off auto-fitting for this mock.

@emilykl emilykl left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice

@camdecoster
camdecoster marked this pull request as ready for review August 7, 2026 23:07
@camdecoster
camdecoster merged commit dbded83 into v4.0 Aug 7, 2026
163 of 166 checks passed
@camdecoster
camdecoster deleted the cam/7943/handle-polygons-points-antimeridian branch August 7, 2026 23:35
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.

2 participants