Skip to content

Commit 26618dd

Browse files
committed
resolves #2998 - implement scrollZoom:false for gl3d subplots
1 parent b56591d commit 26618dd

File tree

3 files changed

+47
-29
lines changed

3 files changed

+47
-29
lines changed

src/plots/gl3d/camera.js

+3
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ function createCamera(element, options) {
4848

4949
var camera = {
5050
keyBindingMode: 'rotate',
51+
enableWheel: true,
5152
view: view,
5253
element: element,
5354
delay: options.delay || 16,
@@ -257,7 +258,9 @@ function createCamera(element, options) {
257258
}
258259

259260
camera.wheelListener = mouseWheel(element, function(dx, dy) {
261+
// TODO remove now that we can disable scroll via scrollZoom?
260262
if(camera.keyBindingMode === false) return;
263+
if(!camera.enableWheel) return;
261264

262265
var flipX = camera.flipX ? 1 : -1;
263266
var flipY = camera.flipY ? 1 : -1;

src/plots/gl3d/scene.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,15 @@ function initializeGLPlot(scene, canvas, gl) {
227227
scene.graphDiv.emit('plotly_relayout', update);
228228
};
229229

230-
scene.glplot.canvas.addEventListener('mouseup', relayoutCallback.bind(null, scene));
231-
scene.glplot.canvas.addEventListener('wheel', relayoutCallback.bind(null, scene), passiveSupported ? {passive: false} : false);
230+
scene.glplot.canvas.addEventListener('mouseup', function() {
231+
relayoutCallback(scene);
232+
});
233+
234+
scene.glplot.canvas.addEventListener('wheel', function() {
235+
if(gd._context._scrollZoom.gl3d) {
236+
relayoutCallback(scene);
237+
}
238+
}, passiveSupported ? {passive: false} : false);
232239

233240
if(!scene.staticMode) {
234241
scene.glplot.canvas.addEventListener('webglcontextlost', function(event) {
@@ -385,7 +392,6 @@ function computeTraceBounds(scene, trace, bounds) {
385392
}
386393

387394
proto.plot = function(sceneData, fullLayout, layout) {
388-
389395
// Save parameters
390396
this.plotArgs = [sceneData, fullLayout, layout];
391397

@@ -412,6 +418,7 @@ proto.plot = function(sceneData, fullLayout, layout) {
412418
// Update camera and camera mode
413419
this.setCamera(fullSceneLayout.camera);
414420
this.updateFx(fullSceneLayout.dragmode, fullSceneLayout.hovermode);
421+
this.camera.enableWheel = this.graphDiv._context._scrollZoom.gl3d;
415422

416423
// Update scene
417424
this.glplot.update({});
@@ -776,7 +783,6 @@ proto.updateFx = function(dragmode, hovermode) {
776783
fullCamera.up = zUp;
777784
Lib.nestedProperty(layout, attr).set(zUp);
778785
} else {
779-
780786
// none rotation modes [pan or zoom]
781787
camera.keyBindingMode = dragmode;
782788
}

test/jasmine/tests/gl3d_plot_interact_test.js

+34-25
Original file line numberDiff line numberDiff line change
@@ -1097,6 +1097,11 @@ describe('Test gl3d drag and wheel interactions', function() {
10971097
}
10981098
};
10991099

1100+
function _assertAndReset(cnt) {
1101+
expect(relayoutCallback).toHaveBeenCalledTimes(cnt);
1102+
relayoutCallback.calls.reset();
1103+
}
1104+
11001105
Plotly.plot(gd, mock)
11011106
.then(function() {
11021107
relayoutCallback = jasmine.createSpy('relayoutCallback');
@@ -1115,48 +1120,32 @@ describe('Test gl3d drag and wheel interactions', function() {
11151120
return scroll(sceneTarget);
11161121
})
11171122
.then(function() {
1118-
expect(relayoutCallback).toHaveBeenCalledTimes(1);
1119-
relayoutCallback.calls.reset();
1120-
1123+
_assertAndReset(1);
11211124
return scroll(sceneTarget2);
11221125
})
11231126
.then(function() {
1124-
expect(relayoutCallback).toHaveBeenCalledTimes(1);
1125-
relayoutCallback.calls.reset();
1126-
1127+
_assertAndReset(1);
11271128
return drag(sceneTarget2, [0, 0], [100, 100]);
11281129
})
11291130
.then(function() {
1130-
expect(relayoutCallback).toHaveBeenCalledTimes(1);
1131-
relayoutCallback.calls.reset();
1132-
1131+
_assertAndReset(1);
11331132
return drag(sceneTarget, [0, 0], [100, 100]);
11341133
})
11351134
.then(function() {
1136-
expect(relayoutCallback).toHaveBeenCalledTimes(1);
1137-
relayoutCallback.calls.reset();
1138-
1139-
return Plotly.relayout(gd, {
1140-
'scene.dragmode': false,
1141-
'scene2.dragmode': false
1142-
});
1135+
_assertAndReset(1);
1136+
return Plotly.relayout(gd, {'scene.dragmode': false, 'scene2.dragmode': false});
11431137
})
11441138
.then(function() {
1145-
expect(relayoutCallback).toHaveBeenCalledTimes(1);
1146-
relayoutCallback.calls.reset();
1147-
1139+
_assertAndReset(1);
11481140
return drag(sceneTarget, [0, 0], [100, 100]);
11491141
})
11501142
.then(function() {
11511143
return drag(sceneTarget2, [0, 0], [100, 100]);
11521144
})
11531145
.then(function() {
1154-
expect(relayoutCallback).toHaveBeenCalledTimes(0);
1146+
_assertAndReset(0);
11551147

1156-
return Plotly.relayout(gd, {
1157-
'scene.dragmode': 'orbit',
1158-
'scene2.dragmode': 'turntable'
1159-
});
1148+
return Plotly.relayout(gd, {'scene.dragmode': 'orbit', 'scene2.dragmode': 'turntable'});
11601149
})
11611150
.then(function() {
11621151
expect(relayoutCallback).toHaveBeenCalledTimes(1);
@@ -1168,7 +1157,27 @@ describe('Test gl3d drag and wheel interactions', function() {
11681157
return drag(sceneTarget2, [0, 0], [100, 100]);
11691158
})
11701159
.then(function() {
1171-
expect(relayoutCallback).toHaveBeenCalledTimes(2);
1160+
_assertAndReset(2);
1161+
return Plotly.plot(gd, [], {}, {scrollZoom: false});
1162+
})
1163+
.then(function() {
1164+
return scroll(sceneTarget);
1165+
})
1166+
.then(function() {
1167+
return scroll(sceneTarget2);
1168+
})
1169+
.then(function() {
1170+
_assertAndReset(0);
1171+
return Plotly.plot(gd, [], {}, {scrollZoom: 'gl3d'});
1172+
})
1173+
.then(function() {
1174+
return scroll(sceneTarget);
1175+
})
1176+
.then(function() {
1177+
return scroll(sceneTarget2);
1178+
})
1179+
.then(function() {
1180+
_assertAndReset(2);
11721181
})
11731182
.catch(failTest)
11741183
.then(done);

0 commit comments

Comments
 (0)