Skip to content

Commit 2545746

Browse files
committed
improve coverage of plotly_relayouting for geo plots
1 parent 7a66daf commit 2545746

File tree

2 files changed

+61
-24
lines changed

2 files changed

+61
-24
lines changed

Diff for: src/plots/geo/zoom.js

+24-2
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,13 @@ function zoomScoped(geo, projection) {
8686
.scale(d3.event.scale)
8787
.translate(d3.event.translate);
8888
geo.render();
89-
geo.graphDiv.emit('plotly_relayouting', {'projection.scale': projection.scale() / geo.fitScale});
89+
90+
var center = projection.invert(geo.midPt);
91+
geo.graphDiv.emit('plotly_relayouting', {
92+
'geo.projection.scale': projection.scale() / geo.fitScale,
93+
'geo.center.lon': center[0],
94+
'geo.center.lat': center[1]
95+
});
9096
}
9197

9298
function syncCb(set) {
@@ -165,7 +171,16 @@ function zoomNonClipped(geo, projection) {
165171

166172
didZoom = true;
167173
geo.render();
168-
geo.graphDiv.emit('plotly_relayouting', {'projection.scale': projection.scale() / geo.fitScale});
174+
175+
var rotate = projection.rotate();
176+
var center = projection.invert(geo.midPt);
177+
geo.graphDiv.emit('plotly_relayouting', {
178+
'geo.projection.scale': projection.scale() / geo.fitScale,
179+
'geo.center.lon': center[0],
180+
'geo.center.lat': center[1],
181+
'geo.projection.rotation.lon': -rotate[0]
182+
183+
});
169184
}
170185

171186
function handleZoomend() {
@@ -263,6 +278,13 @@ function zoomClipped(geo, projection) {
263278
})
264279
.on('zoom.redraw', function() {
265280
geo.render();
281+
282+
var _rotate = projection.rotate();
283+
geo.graphDiv.emit('plotly_relayouting', {
284+
'geo.projection.scale': projection.scale() / geo.fitScale,
285+
'geo.projection.rotation.lon': -_rotate[0],
286+
'geo.projection.rotation.lat': -_rotate[1]
287+
});
266288
});
267289

268290
function zoomstarted(dispatch) {

Diff for: test/jasmine/tests/geo_test.js

+37-22
Original file line numberDiff line numberDiff line change
@@ -2068,28 +2068,43 @@ describe('Test geo zoom/pan/drag interactions:', function() {
20682068
});
20692069

20702070
describe('plotly_relayouting', function() {
2071-
['pan', 'zoom'].forEach(function(dragmode) {
2072-
it('should emit plotly_relayouting events on', function(done) {
2073-
var events = []; var path = [[300, 300], [350, 300], [350, 400]]; var relayoutCallback;
2074-
var fig = Lib.extendDeep({}, require('@mocks/geo_choropleth-usa'));
2075-
fig.layout.dragmode = dragmode;
2076-
2077-
gd = createGraphDiv();
2078-
Plotly.plot(gd, fig)
2079-
.then(function() {
2080-
relayoutCallback = jasmine.createSpy('relayoutCallback');
2081-
gd.on('plotly_relayout', relayoutCallback);
2082-
gd.on('plotly_relayouting', function(e) {
2083-
events.push(e);
2084-
});
2085-
return drag(path);
2086-
})
2087-
.then(function() {
2088-
expect(events.length).toEqual(path.length - 1);
2089-
expect(relayoutCallback).toHaveBeenCalledTimes(1);
2090-
})
2091-
.catch(failTest)
2092-
.then(done);
2071+
var mocks = {
2072+
'non-clipped': require('@mocks/geo_winkel-tripel'),
2073+
'clipped': require('@mocks/geo_orthographic'),
2074+
'scoped': require('@mocks/geo_europe-bubbles')
2075+
};
2076+
['non-clipped', 'clipped', 'scoped'].forEach(function(zoomHandler) {
2077+
['pan'].forEach(function(dragmode) {
2078+
it('should emit events on ' + dragmode + ' for ' + zoomHandler, function(done) {
2079+
var events = []; var path = [[300, 300], [350, 300], [350, 400]];
2080+
var relayoutCnt = 0; var relayoutEvent;
2081+
var fig = Lib.extendDeep({}, mocks[zoomHandler]);
2082+
fig.layout.dragmode = dragmode;
2083+
fig.layout.width = 700;
2084+
fig.layout.height = 500;
2085+
2086+
gd = createGraphDiv();
2087+
Plotly.plot(gd, fig)
2088+
.then(function() {
2089+
gd.on('plotly_relayout', function(e) {
2090+
relayoutCnt++;
2091+
relayoutEvent = e;
2092+
});
2093+
gd.on('plotly_relayouting', function(e) {
2094+
events.push(e);
2095+
});
2096+
return drag(path);
2097+
})
2098+
.then(function() {
2099+
expect(events.length).toEqual(path.length - 1);
2100+
expect(relayoutCnt).toEqual(1);
2101+
Object.keys(relayoutEvent).sort().forEach(function(key) {
2102+
expect(Object.keys(events[0])).toContain(key);
2103+
});
2104+
})
2105+
.catch(failTest)
2106+
.then(done);
2107+
});
20932108
});
20942109
});
20952110
});

0 commit comments

Comments
 (0)