Skip to content

Commit f21d53b

Browse files
Ted DriggsTedDriggs
authored andcommitted
Handle both mouse wheel and trackpad
The current code ignores magnitude differences in deltaY, resulting in an experience that is either too fast on trackpad or too slow with a mousewheel. This change allows those to differ within a clamped range, so that one zoomSpeed value works well for both input devices. Fixes #1882
1 parent c2e8bd6 commit f21d53b

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

lib/network/modules/InteractionHandler.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -590,8 +590,6 @@ class InteractionHandler {
590590

591591
/**
592592
* Event handler for mouse wheel event, used to zoom the timeline
593-
* See http://adomas.org/javascript-mouse-wheel/
594-
* https://github.com/EightMedia/hammer.js/issues/256
595593
*
596594
* @param {MouseEvent} event
597595
* @private
@@ -604,8 +602,14 @@ class InteractionHandler {
604602
if (event.deltaY !== 0) {
605603
// calculate the new scale
606604
let scale = this.body.view.scale;
607-
scale *=
608-
1 + (event.deltaY < 0 ? 1 : -1) * (this.options.zoomSpeed * 0.1);
605+
const scaledY = event.deltaY / 8;
606+
/**
607+
* Rapid mouse wheel movement can cause the graph to zoom so fast
608+
* that the entire graph disappears; therefore limit it to two
609+
* "wheel clicks" per event.
610+
*/
611+
const clampedY = Math.sign(scaledY) * Math.min(Math.abs(scaledY), 2);
612+
scale *= 1 - clampedY * (this.options.zoomSpeed * 0.1);
609613

610614
// calculate the pointer location
611615
const pointer = this.getPointer({ x: event.clientX, y: event.clientY });

0 commit comments

Comments
 (0)