Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions draftlogs/7976_fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Fix geo `albers`, `bertin1953`, `gringorten quincuncial`, `peirce quincuncial`, `sinu mollweide` and `wiechel` projections losing their D3 default rotation to the default `projection.rotation` values, and compose user-specified rotation on top of the projection's canonical orientation [[#7976](https://github.com/plotly/plotly.js/pull/7976)]
14 changes: 13 additions & 1 deletion src/plots/geo/geo.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,11 @@ proto.updateProjection = function(geoCalcData, fullLayout) {
// set 'pre-fit' projection
projection
.center([center.lon - rotation.lon, center.lat - rotation.lat])
.rotate([-rotation.lon, -rotation.lat, rotation.roll])
.rotate([
-rotation.lon + projection.defaultRotation[0],
-rotation.lat + projection.defaultRotation[1],
rotation.roll + projection.defaultRotation[2]
])
.parallels(projLayout.parallels);

// fit projection 'scale' and 'translate' to set lon/lat ranges
Expand Down Expand Up @@ -716,6 +720,12 @@ function getProjection(geoLayout) {
projName = 'geo' + Lib.titleCase(projName);
var projFn = geo[projName] || geoProjection[projName];
var projection = projFn();
// Capture the rotation the projection factory ships with (identity for
// most projections, but e.g. albers defaults to [96, 0, 0]) so that the
// default projection.rotation attributes do not discard the canonical
// orientation. See #7949.
var projDefaultRotation = typeof projection.rotate === 'function' ?
projection.rotate() : [0, 0, 0];

var clipAngle =
geoLayout._isSatellite ? Math.acos(1 / projLayout.distance) * 180 / Math.PI :
Expand Down Expand Up @@ -754,6 +764,8 @@ function getProjection(geoLayout) {
return projection.getPath().bounds(object);
};

projection.defaultRotation = projDefaultRotation;

projection.precision(constants.precision);

if(geoLayout._isSatellite) {
Expand Down
Binary file modified test/image/baselines/canada_geo_projections.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/geo_fitbounds-locations.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/various_geo_projections.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 39 additions & 0 deletions test/jasmine/tests/geo_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2876,3 +2876,42 @@ describe('plotly_relayouting', function() {
});
});
});

describe('Test geo projection D3 default rotation (#7949)', function() {
var gd;

beforeEach(function() { gd = createGraphDiv(); });
afterEach(destroyGraphDiv);

function subplot() { return gd._fullLayout.geo._subplot; }

it('preserves the projection factory rotation at default projection.rotation', function(done) {
Plotly.newPlot(gd, [{ type: 'scattergeo', lon: [], lat: [] }], {
geo: { projection: { type: 'albers' } }
}).then(function() {
// d3-geo albers ships with rotation [96, 0, 0]; plotly's default
// projection.rotation attributes must not discard it.
// Compare with a tight numeric tolerance: the composed factory +
// user rotation can pick up float64 dust (e.g. 96.00000000000001
// on linux runners), so exact equality is environment-dependent.
[0, 1, 2].forEach(function(axis) {
expect(subplot().projection.defaultRotation[axis]).toBeCloseTo([96, 0, 0][axis], 9);
expect(subplot().projection.rotate()[axis]).toBeCloseTo([96, 0, 0][axis], 9);
});
}).then(function() {
return Plotly.relayout(gd, { 'geo.projection.rotation.lon': 10 });
}).then(function() {
// user rotation composes on top of the factory rotation
expect(subplot().projection.rotate()[0]).toBeCloseTo(86, 9);
}).then(done, done.fail);
});

it('keeps identity-rotation projections exactly as before', function(done) {
Plotly.newPlot(gd, [{ type: 'scattergeo', lon: [], lat: [] }], {
geo: { projection: { type: 'mercator' } }
}).then(function() {
expect(subplot().projection.defaultRotation).toEqual([0, 0, 0]);
expect(subplot().projection.rotate()).toEqual([0, 0, 0]);
}).then(done, done.fail);
});
});
Loading