MCPcopy Index your code
hub / github.com/plotly/plotly.js / zoomWheel

Function zoomWheel

src/plots/cartesian/dragbox.js:462–546  ·  view source on GitHub ↗
(e)

Source from the content-addressed store, hash-verified

460 var mainplot = plotinfo.mainplot ? gd._fullLayout._plots[plotinfo.mainplot] : plotinfo;
461
462 function zoomWheel(e) {
463 // deactivate mousewheel scrolling on embedded graphs
464 // devs can override this with layout._enablescrollzoom,
465 // but _ ensures this setting won't leave their page
466 if(!gd._context._scrollZoom.cartesian && !gd._fullLayout._enablescrollzoom) {
467 return;
468 }
469
470 clearAndResetSelect();
471
472 // If a transition is in progress, then disable any behavior:
473 if(gd._transitioningWithDuration) {
474 e.preventDefault();
475 e.stopPropagation();
476 return;
477 }
478
479 recomputeAxisLists();
480
481 clearTimeout(redrawTimer);
482
483 var wheelDelta = -e.deltaY;
484 if(!isFinite(wheelDelta)) wheelDelta = e.wheelDelta / 10;
485 if(!isFinite(wheelDelta)) {
486 Lib.log('Did not find wheel motion attributes: ', e);
487 return;
488 }
489
490 var zoom = Math.exp(-Math.min(Math.max(wheelDelta, -20), 20) / 200);
491 var gbb = mainplot.draglayer.select('.nsewdrag').node().getBoundingClientRect();
492 var xfrac = (e.clientX - gbb.left) / gbb.width;
493 var yfrac = (gbb.bottom - e.clientY) / gbb.height;
494 var i;
495
496 function zoomWheelOneAxis(ax, centerFraction, zoom) {
497 if(ax.fixedrange) return;
498
499 var axRange = Lib.simpleMap(ax.range, ax.r2l);
500 var v0 = axRange[0] + (axRange[1] - axRange[0]) * centerFraction;
501 function doZoom(v) { return ax.l2r(v0 + (v - v0) * zoom); }
502 ax.range = axRange.map(doZoom);
503 }
504
505 if(editX) {
506 // if we're only zooming this axis because of constraints,
507 // zoom it about the center
508 if(!ew) xfrac = 0.5;
509
510 for(i = 0; i < xaxes.length; i++) {
511 zoomWheelOneAxis(xaxes[i], xfrac, zoom);
512 }
513 updateMatchedAxRange('x');
514
515 scrollViewBox[2] *= zoom;
516 scrollViewBox[0] += scrollViewBox[2] * xfrac * (1 / zoom - 1);
517 }
518 if(editY) {
519 if(!ns) yfrac = 0.5;

Callers

nothing calls this directly

Calls 7

clearAndResetSelectFunction · 0.85
recomputeAxisListsFunction · 0.85
zoomWheelOneAxisFunction · 0.85
updateMatchedAxRangeFunction · 0.85
updateSubplotsFunction · 0.85
ticksAndAnnotationsFunction · 0.85
dragTailFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…