Fix geo fitbounds to choose a compact range across the antimeridian#7837
Open
SharadhNaidu wants to merge 2 commits into
Open
Fix geo fitbounds to choose a compact range across the antimeridian#7837SharadhNaidu wants to merge 2 commits into
SharadhNaidu wants to merge 2 commits into
Conversation
When `fitbounds` point data straddles +/-180 degrees longitude, the naive [min, max] range from getAutoRange includes the large empty span the long way round the globe, so the map zooms out far more than necessary (plotly/plotly.py#5539). Add getFitboundsLonRange, which finds the widest gap between consecutive longitudes and returns the complementary, antimeridian-crossing range when it is more compact. The override is scoped to longitude point data: it is skipped when a choropleth or location-based scattergeo trace is present (whose region extents are not captured here) and when the data spans the whole globe.
Author
|
can any of the maintainer please review the fix for the issue please ? |
Contributor
|
Hello @SharadhNaidu! Thanks for the PR. I'll try to review this, but it might take a bit to get to. |
Contributor
|
In the meantime, could you provide some examples that this fixes and some testing steps? |
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.
fixes plotly/plotly.py#5539.
With
fitbounds: "locations"on a geo subplot, points that straddle the antimeridian make the map zoom out far more than it should. The longitude range comes straight fromgetAutoRangeas a plain min/max, so it measures the span the long way around the globe. The issue's example (lon131.8855and-179) ends up with a ~311° span, when crossing the antimeridian only needs ~49°.I added a helper,
getFitboundsLonRange, that sorts the longitudes, finds the largest gap between neighbouring points, and if that gap is wider than the one the naive range leaves open across the antimeridian, returns the complementary range instead. The result can exceed 180° (e.g.[131.8855, 181]), butmakeRangeBoxalready handles ranges that cross the antimeridian, so the projection code is untouched.It runs right after
getAutoRange, so it can only shrink the range, never grow it. It deliberately stays out of the way when:Tests: unit tests on the helper (straddling, not straddling, whole globe, too few points) plus an integration test that renders both of the issue's cases and checks the fitted range and the projection rotation. The existing fitbounds mocks and the winkel-tripel draw-time test are all location-based or globe-spanning, so none of them shift.
One open question: the range I return is tight, whereas
getAutoRangepads a little for marker size, so in the crossing case points can sit right on the edge. Happy to mirror that padding if you'd prefer.