Skip to content

Commit 8151197

Browse files
committed
fix uirevision behavior on geo subplots
1 parent fb85e65 commit 8151197

File tree

2 files changed

+64
-2
lines changed

2 files changed

+64
-2
lines changed

src/plots/geo/zoom.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,14 @@ function sync(geo, projection, cb) {
5353
var fullLayout = gd._fullLayout;
5454
var fullOpts = fullLayout[id];
5555

56+
var preGUI = {};
5657
var eventData = {};
5758

5859
function set(propStr, val) {
59-
var fullNp = Lib.nestedProperty(fullOpts, propStr);
60+
preGUI[id + '.' + propStr] = Lib.nestedProperty(userOpts, propStr).get();
61+
Registry.call('_storeDirectGUIEdit', layout, fullLayout._preGUI, preGUI);
6062

63+
var fullNp = Lib.nestedProperty(fullOpts, propStr);
6164
if(fullNp.get() !== val) {
6265
fullNp.set(val);
6366
Lib.nestedProperty(userOpts, propStr).set(val);
@@ -67,7 +70,6 @@ function sync(geo, projection, cb) {
6770

6871
cb(set);
6972
set('projection.scale', projection.scale() / geo.fitScale);
70-
Registry.call('_storeDirectGUIEdit', layout, fullLayout._preGUI, eventData);
7173
gd.emit('plotly_relayout', eventData);
7274
}
7375

test/jasmine/tests/plot_api_react_test.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1870,4 +1870,64 @@ describe('Test Plotly.react + interactions under uirevision:', function() {
18701870
.catch(failTest)
18711871
.then(done);
18721872
});
1873+
1874+
it('geo subplots should preserve viewport changes after panning', function(done) {
1875+
function _react() {
1876+
return Plotly.react(gd, [{
1877+
type: 'scattergeo',
1878+
lon: [3, 1, 2],
1879+
lat: [2, 3, 1]
1880+
}], {
1881+
width: 500,
1882+
height: 500,
1883+
uirevision: true
1884+
});
1885+
}
1886+
1887+
function _drag(x0, y0, dx, dy) {
1888+
mouseEvent('mousemove', x0, y0);
1889+
mouseEvent('mousedown', x0, y0);
1890+
mouseEvent('mousemove', x0 + dx, y0 + dy);
1891+
mouseEvent('mouseup', x0 + dx, y0 + dy);
1892+
}
1893+
1894+
// should be same before & after 2nd react()
1895+
function _assertGUI(msg) {
1896+
var TOL = 2;
1897+
1898+
var geo = gd.layout.geo || {};
1899+
expect(((geo.projection || {}).rotation || {}).lon).toBeCloseTo(-52.94, TOL, msg);
1900+
expect((geo.center || {}).lon).toBeCloseTo(-52.94, TOL, msg);
1901+
expect((geo.center || {}).lat).toBeCloseTo(52.94, TOL, msg);
1902+
1903+
var fullGeo = gd._fullLayout.geo;
1904+
expect(fullGeo.projection.rotation.lon).toBeCloseTo(-52.94, TOL, msg);
1905+
expect(fullGeo.center.lon).toBeCloseTo(-52.94, TOL, msg);
1906+
expect(fullGeo.center.lat).toBeCloseTo(52.94, TOL, msg);
1907+
1908+
var preGUI = gd._fullLayout._preGUI;
1909+
expect(preGUI['geo.projection.rotation.lon']).toBe(null, msg);
1910+
expect(preGUI['geo.center.lon']).toBe(null, msg);
1911+
expect(preGUI['geo.center.lat']).toBe(null, msg);
1912+
expect(preGUI['geo.projection.scale']).toBe(null, msg);
1913+
}
1914+
1915+
_react()
1916+
.then(function() {
1917+
expect(gd.layout.geo).toEqual({});
1918+
1919+
var fullGeo = gd._fullLayout.geo;
1920+
expect(fullGeo.projection.rotation.lon).toBe(0);
1921+
expect(fullGeo.center.lon).toBe(0);
1922+
expect(fullGeo.center.lat).toBe(0);
1923+
1924+
expect(gd._fullLayout._preGUI).toEqual({});
1925+
})
1926+
.then(function() { return _drag(200, 200, 50, 50); })
1927+
.then(function() { _assertGUI('before'); })
1928+
.then(_react)
1929+
.then(function() { _assertGUI('after'); })
1930+
.catch(failTest)
1931+
.then(done);
1932+
});
18731933
});

0 commit comments

Comments
 (0)