Skip to content

Commit 6829a09

Browse files
committed
[sigma] Stops scrolljacking when no zoom
This commit addresses some legit issue discussed in #1492. Details: - In MouseCaptor#handleWheel, stops calling e.preventDefault when zooming is disabled or when the ratio does not change - In the mouse-manipulations story, adds zoom boundaries to ease checking that the scroll-jacking ends when the user zooms or unzooms to the max
1 parent 03ef2fe commit 6829a09

File tree

2 files changed

+17
-9
lines changed
  • packages
    • sigma/src/core/captors
    • storybook/stories/2-advanced-usecases/mouse-manipulations

2 files changed

+17
-9
lines changed

packages/sigma/src/core/captors/mouse.ts

+16-8
Original file line numberDiff line numberDiff line change
@@ -307,10 +307,8 @@ export default class MouseCaptor<
307307
}
308308

309309
handleWheel(e: WheelEvent): void {
310-
if (!this.enabled) return;
311-
312-
e.preventDefault();
313-
e.stopPropagation();
310+
const camera = this.renderer.getCamera();
311+
if (!this.enabled || !camera.enabledZooming) return;
314312

315313
const delta = getWheelDelta(e);
316314

@@ -319,16 +317,26 @@ export default class MouseCaptor<
319317
const wheelCoords = getWheelCoords(e, this.container);
320318
this.emit("wheel", wheelCoords);
321319

322-
if (wheelCoords.sigmaDefaultPrevented) return;
320+
if (wheelCoords.sigmaDefaultPrevented) {
321+
e.preventDefault();
322+
e.stopPropagation();
323+
return;
324+
}
323325

324326
// Default behavior
327+
const currentRatio = camera.getState().ratio;
325328
const ratioDiff = delta > 0 ? 1 / this.settings.zoomingRatio : this.settings.zoomingRatio;
326-
const camera = this.renderer.getCamera();
327-
const newRatio = camera.getBoundedRatio(camera.getState().ratio * ratioDiff);
329+
const newRatio = camera.getBoundedRatio(currentRatio * ratioDiff);
328330
const wheelDirection = delta > 0 ? 1 : -1;
329331
const now = Date.now();
330332

331-
// Cancel events that are too close too each other and in the same direction:
333+
// Exit early without preventing default behavior when ratio doesn't change:
334+
if (currentRatio === newRatio) return;
335+
336+
e.preventDefault();
337+
e.stopPropagation();
338+
339+
// Cancel events that are too close each other and in the same direction:
332340
if (
333341
this.currentWheelDirection === wheelDirection &&
334342
this.lastWheelTriggerTime &&

packages/storybook/stories/2-advanced-usecases/mouse-manipulations/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export default () => {
2424
layout.start();
2525

2626
// Create the sigma
27-
const renderer = new Sigma(graph, container);
27+
const renderer = new Sigma(graph, container, { minCameraRatio: 0.5, maxCameraRatio: 2 });
2828

2929
//
3030
// Drag'n'drop feature

0 commit comments

Comments
 (0)