Skip to content

Commit 8fd0ab1

Browse files
committed
Pad the compact fitbounds longitude range like getAutoRange
The antimeridian fix replaced the padded naive range with a tight [min, max], so markers ended up flush against the frame on straddling maps while every other fitbounds map leaves a margin. Scale the padding getAutoRange already applied to the naive range down to the narrower crossing range and apply it. The padding is symmetric, so the mid-longitude the projection centers on is unchanged. Loosen the integration test's range assertion to match.
1 parent d962b56 commit 8fd0ab1

2 files changed

Lines changed: 25 additions & 4 deletions

File tree

src/plots/geo/geo.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,21 @@ proto.updateProjection = function(geoCalcData, fullLayout) {
261261

262262
if(!hasLocationData) {
263263
var fitLonRange = getFitboundsLonRange(lons);
264-
if(fitLonRange) axLon.range = fitLonRange;
264+
if(fitLonRange) {
265+
// getFitboundsLonRange returns a tight [min, max]. getAutoRange
266+
// pads the naive range (for marker size and the standard
267+
// margin), so scale that padding to the narrower crossing range
268+
// and apply it, keeping markers off the frame edge as on any
269+
// other fitbounds map. The padding is symmetric, so the
270+
// mid-longitude the projection centers on is unchanged.
271+
var lonDataSpan = Lib.aggNums(Math.max, null, lons) -
272+
Lib.aggNums(Math.min, null, lons);
273+
var lonPad = lonDataSpan > 0 ?
274+
(axLon.range[1] - axLon.range[0] - lonDataSpan) / 2 *
275+
(fitLonRange[1] - fitLonRange[0]) / lonDataSpan :
276+
0;
277+
axLon.range = [fitLonRange[0] - lonPad, fitLonRange[1] + lonPad];
278+
}
265279
}
266280
}
267281

test/jasmine/tests/geo_test.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,18 @@ describe('Test geo fitbounds with antimeridian-straddling points', function() {
8383

8484
it('centers on the compact crossing view when points straddle the antimeridian', function(done) {
8585
// lon = [131.8855, -179] spans ~311deg the naive way; the compact view
86-
// crosses the antimeridian, giving range [131.8855, 181] and a projection
87-
// rotated to its mid-longitude (~156.4deg), not to the naive mid (~-24deg).
86+
// crosses the antimeridian, giving a range around [131.8855, 181] (padded
87+
// for markers like any fitbounds map) and a projection rotated to its
88+
// mid-longitude (~156.4deg), not to the naive mid (~-24deg).
8889
_plot([131.8855, -179]).then(function() {
8990
var geoLayout = gd._fullLayout.geo;
90-
expect(geoLayout.lonaxis._ax.range).toEqual([131.8855, 181]);
91+
var lonRange = geoLayout.lonaxis._ax.range;
92+
// crosses the antimeridian (upper bound past 180) and stays compact
93+
// (~49deg plus a little padding), nowhere near the naive ~311deg.
94+
expect(lonRange[0]).toBeLessThan(131.8855);
95+
expect(lonRange[1]).toBeGreaterThan(181);
96+
expect(lonRange[1] - lonRange[0]).toBeGreaterThan(49);
97+
expect(lonRange[1] - lonRange[0]).toBeLessThan(70);
9198
expect(geoLayout._subplot.projection.rotate()[0]).toBeCloseTo(-156.4, 0);
9299
})
93100
.then(done, done.fail);

0 commit comments

Comments
 (0)