Skip to content

Commit 7a66daf

Browse files
committed
plotly_relayouting for gl3d plots
1 parent e268cda commit 7a66daf

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

src/plots/gl3d/scene.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,15 @@ function initializeGLPlot(scene, pixelRatio, canvas, gl) {
272272
}
273273
}, passiveSupported ? {passive: false} : false);
274274

275+
scene.glplot.canvas.addEventListener('mousemove', function() {
276+
if(scene.fullSceneLayout.dragmode === false) return;
277+
if(scene.camera.mouseListener.buttons === 0) return;
278+
279+
var update = {};
280+
update[scene.id + '.camera'] = getLayoutCamera(scene.camera);
281+
scene.graphDiv.emit('plotly_relayouting', update);
282+
});
283+
275284
if(!scene.staticMode) {
276285
scene.glplot.canvas.addEventListener('webglcontextlost', function(event) {
277286
if(gd && gd.emit) {

test/jasmine/tests/gl3d_plot_interact_test.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -929,6 +929,54 @@ describe('Test gl3d drag and wheel interactions', function() {
929929
.catch(failTest)
930930
.then(done);
931931
});
932+
933+
it('@gl should fire plotly_relayouting events', function(done) {
934+
var sceneLayout, sceneTarget, relayoutCallback, relayoutingCallback;
935+
936+
var mock = {
937+
data: [
938+
{ type: 'scatter3d', x: [1, 2, 3], y: [2, 3, 1], z: [3, 1, 2] }
939+
],
940+
layout: {
941+
scene: { camera: { projection: {type: 'orthographic'}, eye: { x: 0.1, y: 0.1, z: 1 }}},
942+
width: 400, height: 400
943+
}
944+
};
945+
946+
var nsteps = 10;
947+
function _drag(target, start, end, n) {
948+
return new Promise(function(resolve) {
949+
mouseEvent('mousedown', start[0], start[1], {element: target, buttons: 1});
950+
var dx = (end[0] - start[0]) / n;
951+
var dy = (end[1] - start[1]) / n;
952+
for(var i = 1; i <= n; i++) {
953+
mouseEvent('mousemove', start[0] + dx * n, start[1] + dy * n, {element: target, buttons: 1});
954+
}
955+
mouseEvent('mouseup', end[0], end[1], {element: target, buttons: 1});
956+
setTimeout(resolve, 0);
957+
});
958+
}
959+
960+
Plotly.plot(gd, mock)
961+
.then(function() {
962+
relayoutCallback = jasmine.createSpy('relayoutCallback');
963+
gd.on('plotly_relayout', relayoutCallback);
964+
965+
relayoutingCallback = jasmine.createSpy('relayoutingCallback');
966+
gd.on('plotly_relayouting', relayoutingCallback);
967+
968+
sceneLayout = gd._fullLayout.scene;
969+
sceneTarget = gd.querySelector('.svg-container .gl-container #scene canvas');
970+
971+
return _drag(sceneTarget, [200, 200], [100, 100], nsteps);
972+
})
973+
.then(function() {
974+
expect(relayoutCallback).toHaveBeenCalledTimes(1);
975+
expect(relayoutingCallback).toHaveBeenCalledTimes(nsteps);
976+
})
977+
.catch(failTest)
978+
.then(done);
979+
});
932980
});
933981

934982
describe('Test gl3d relayout calls', function() {

0 commit comments

Comments
 (0)