Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make scrollZoom speed configurable #1085

Open
rreusser opened this issue Oct 25, 2016 · 10 comments
Open

Make scrollZoom speed configurable #1085

rreusser opened this issue Oct 25, 2016 · 10 comments

Comments

@rreusser
Copy link
Contributor

rreusser commented Oct 25, 2016

I find scrollZoom speed painfully slow. Making this configurable may mean propagating a scale factor to some other gl modules or something, but then again it might just be a simple scalar. Maybe scrollZoomSpeed?

(Side note: it's not clear to me why scrollZoom is camelCased and belongs to config instead of to layout.)

I don't think it's entirely straightforward to get the speed itself just right across browsers and system configs, but maybe this is something: http://stackoverflow.com/questions/5527601/normalizing-mousewheel-speed-across-browsers#answer-30134826

@etpinard
Copy link
Contributor

etpinard commented Sep 29, 2017

cc #2041

@mzechmeister
Copy link

mzechmeister commented Jul 1, 2019

Is there are progress here?
Can't see a quick way to adjust the zoom speed for the mouse wheel. It is really slow.

@mzechmeister
Copy link

mzechmeister commented Jul 1, 2019

As a quick hack one can adjust manually the hardcoded normalisation factor in
plotly.min.js:

var r=-e.deltaY;if(isFinite(r)||(r=e.wheelDelta/10),isFinite(r)){var n,i=Math.exp(-Math.min(Math.max(r,-20),20)/200),...

I replaced /200 by /10.

@mitja-p
Copy link

mitja-p commented Dec 11, 2019

If using in Javascript, I solved this by overtaking the wheel event (capture phase) and emitted my own event with modified deltaY. This works on cartesian plots, I did not check others.

function handler(event)
{
      if (!event.isTrusted) return;
      event.stopPropagation();
      var newEv = new WheelEvent('wheel', {
        clientX: event.clientX,
        clientY:event.clientY, 
        deltaY:event.deltaY*2,
      });
      event.target.dispatchEvent(newEv);
}

@danielfrunza
Copy link

danielfrunza commented Apr 1, 2021

If using in Javascript, I solved this by overtaking the wheel event (capture phase) and emitted my own event with modified deltaY. This works on cartesian plots, I did not check others.

function handler(event)
{
      if (!event.isTrusted) return;
      event.stopPropagation();
      var newEv = new WheelEvent('wheel', {
        clientX: event.clientX,
        clientY:event.clientY, 
        deltaY:event.deltaY*2,
      });
      event.target.dispatchEvent(newEv);
}

What is the element that you attached the 'handler'? I tried on 'document' and plot element and does not work....

@mitja-p
Copy link

mitja-p commented Apr 1, 2021

I attached it to plot element but on wheel event in capture mode.

@danielfrunza
Copy link

danielfrunza commented Apr 1, 2021

Thank you! I've missed the 'capture mode' from the initial post. Now it worked.

@caotoulei
Copy link

caotoulei commented Feb 19, 2022

What's the 'capture mode' you guys talking about? Could you share the script of this part, please?

@mitja-p
Copy link

mitja-p commented Feb 21, 2022

Use the same element, Plotly.react is called on. So if you initialize plot with Plotly.react(plotEl, data, layout, options) you should do something like this:
plotEl.addEventListener('wheel', handler, true);

The last true, means capture events. For explanation on capture events, search for "event bubbling capturing"

@caotoulei
Copy link

caotoulei commented Feb 22, 2022

capture events

Thanks a lot, @mitja-p. I'm using angular-plotly.js, based on your suggestion, I did it this way, and it works now. (in case somebody using angular-plotly.js needs it in the future. )

<plotly-plot *ngIf="isPlotDataReady" [data]="graph.data" [layout]="graph.layout">
...

ngAfterViewInit() {
this.elementRef.nativeElement.addEventListener('wheel', this.handler, true);
}

public handler(event: any) {
console.log(event.deltaY);
if (!event.isTrusted) return;
event.stopPropagation();
var newEv = new WheelEvent('wheel', {
clientX: event.clientX,
clientY: event.clientY,
deltaY: event.deltaY / 20,
view: window,
bubbles: true,
cancelable: true
});

event.target.dispatchEvent(newEv);

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants