Skip to content

Commit 4b0a0fd

Browse files
committed
plotly_relayouting for geo plots
1 parent f8203a3 commit 4b0a0fd

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

src/plots/geo/zoom.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ 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});
8990
}
9091

9192
function syncCb(set) {
@@ -164,6 +165,7 @@ function zoomNonClipped(geo, projection) {
164165

165166
didZoom = true;
166167
geo.render();
168+
geo.graphDiv.emit('plotly_relayouting', {'projection.scale': projection.scale() / geo.fitScale});
167169
}
168170

169171
function handleZoomend() {

test/jasmine/tests/geo_test.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2066,4 +2066,31 @@ describe('Test geo zoom/pan/drag interactions:', function() {
20662066
.catch(failTest)
20672067
.then(done);
20682068
});
2069+
2070+
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);
2093+
});
2094+
});
2095+
});
20692096
});

0 commit comments

Comments
 (0)