Skip to content

Commit 394014e

Browse files
committed
Normalize zoom speed and wheel behavior across trace types
1 parent 549ee38 commit 394014e

File tree

7 files changed

+37
-30
lines changed

7 files changed

+37
-30
lines changed

src/components/fx/layout_attributes.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,17 @@ module.exports = {
3131
'3D scenes.'
3232
].join(' ')
3333
},
34+
zoomspeed: {
35+
valType: 'number',
36+
role: 'info',
37+
dflt: 1,
38+
min: 0,
39+
editType: 'none',
40+
description: [
41+
'Sets the speed at which the mouse wheel zooms the plot. Larger',
42+
'values are faster.'
43+
].join(' ')
44+
},
3445
hovermode: {
3546
valType: 'enumerated',
3647
role: 'info',

src/components/fx/layout_defaults.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) {
1717
}
1818

1919
coerce('dragmode');
20+
coerce('zoomspeed');
2021

2122
var hovermodeDflt;
2223
if(layoutOut._has('cartesian')) {

src/plots/cartesian/dragbox.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ module.exports = function dragBox(gd, plotinfo, x, y, w, h, ns, ew) {
380380
return;
381381
}
382382

383-
var zoom = Math.exp(-Math.min(Math.max(wheelDelta, -20), 20) / 100),
383+
var zoom = Math.exp(-Math.min(Math.max(wheelDelta, -20), 20) / 100 * fullLayout.zoomspeed),
384384
gbb = mainplot.draglayer.select('.nsewdrag')
385385
.node().getBoundingClientRect(),
386386
xfrac = (e.clientX - gbb.left) / gbb.width,

src/plots/gl2d/camera.js

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -262,34 +262,27 @@ function createCamera(scene) {
262262
var lastX = result.lastPos[0],
263263
lastY = result.lastPos[1];
264264

265-
switch(scene.fullLayout.dragmode) {
266-
case 'zoom':
267-
break;
268-
269-
case 'pan':
270-
var scale = Math.exp(0.1 * dy / (viewBox[3] - viewBox[1]));
271-
272-
var cx = lastX /
273-
(viewBox[2] - viewBox[0]) * (dataBox[2] - dataBox[0]) +
274-
dataBox[0];
275-
var cy = lastY /
276-
(viewBox[3] - viewBox[1]) * (dataBox[3] - dataBox[1]) +
277-
dataBox[1];
278-
279-
dataBox[0] = (dataBox[0] - cx) * scale + cx;
280-
dataBox[2] = (dataBox[2] - cx) * scale + cx;
281-
dataBox[1] = (dataBox[1] - cy) * scale + cy;
282-
dataBox[3] = (dataBox[3] - cy) * scale + cy;
283-
284-
scene.setRanges(dataBox);
285-
286-
result.lastInputTime = Date.now();
287-
unSetAutoRange();
288-
scene.cameraChanged();
289-
scene.handleAnnotations();
290-
scene.relayoutCallback();
291-
break;
292-
}
265+
var scale = Math.exp(scene.fullLayout.zoomspeed * 10.0 * dy / (viewBox[3] - viewBox[1]));
266+
267+
var cx = lastX /
268+
(viewBox[2] - viewBox[0]) * (dataBox[2] - dataBox[0]) +
269+
dataBox[0];
270+
var cy = lastY /
271+
(viewBox[3] - viewBox[1]) * (dataBox[3] - dataBox[1]) +
272+
dataBox[1];
273+
274+
dataBox[0] = (dataBox[0] - cx) * scale + cx;
275+
dataBox[2] = (dataBox[2] - cx) * scale + cx;
276+
dataBox[1] = (dataBox[1] - cy) * scale + cy;
277+
dataBox[3] = (dataBox[3] - cy) * scale + cy;
278+
279+
scene.setRanges(dataBox);
280+
281+
result.lastInputTime = Date.now();
282+
unSetAutoRange();
283+
scene.cameraChanged();
284+
scene.handleAnnotations();
285+
scene.relayoutCallback();
293286

294287
return true;
295288
});

src/plots/gl3d/camera.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ function createCamera(element, options) {
256256
if(Math.abs(dx) > Math.abs(dy)) {
257257
view.rotate(t, 0, 0, -dx * flipX * Math.PI * camera.rotateSpeed / window.innerWidth);
258258
} else {
259-
var kzoom = -camera.zoomSpeed * flipY * dy / window.innerHeight * (t - view.lastT()) / 100.0;
259+
var kzoom = -camera.zoomSpeed * flipY * dy / window.innerHeight * (t - view.lastT()) / 10.0;
260260
view.pan(t, 0, 0, distance * (Math.exp(kzoom) - 1));
261261
}
262262
}, true);

src/plots/gl3d/scene.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ function initializeGLPlot(scene, fullLayout, canvas, gl) {
205205
center: [cameraData.center.x, cameraData.center.y, cameraData.center.z],
206206
eye: [cameraData.eye.x, cameraData.eye.y, cameraData.eye.z],
207207
up: [cameraData.up.x, cameraData.up.y, cameraData.up.z],
208+
zoomSpeed: fullLayout.zoomspeed,
208209
zoomMin: 0.1,
209210
zoomMax: 100,
210211
mode: 'orbit'

src/plots/plots.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1332,6 +1332,7 @@ plots.purge = function(gd) {
13321332
delete gd._transitionData;
13331333
delete gd._transitioning;
13341334
delete gd._initialAutoSize;
1335+
delete gd._transitioningWithDuration;
13351336

13361337
// remove all event listeners
13371338
if(gd.removeAllListeners) gd.removeAllListeners();

0 commit comments

Comments
 (0)