From 532aa3176062a39a4ee9de692df34d65fdc03bdb Mon Sep 17 00:00:00 2001 From: Nick Leaf Date: Thu, 18 Jun 2020 13:48:01 -0700 Subject: [PATCH] Fixed camera zoom in Firefox by using event.deltaY instead of event.wheelDelta (which only worked in Chrome, I guess). While I was at it, I moved more of the zoom calculation to the python side, added a user-accessible zoomScale member to the PVDisplay class, and changed the calculation to make the step size the same for both zoom in and zoom out. Signed-off-by: Nick Leaf --- ipyparaview/widgets.py | 4 +++- js/lib/widgets.js | 8 ++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/ipyparaview/widgets.py b/ipyparaview/widgets.py index cfd5760..2683510 100644 --- a/ipyparaview/widgets.py +++ b/ipyparaview/widgets.py @@ -48,6 +48,7 @@ class PVDisplay(widgets.DOMWidget): # class variables instances = dict() rotateScale = 5.0 + zoomScale = 0.05 @classmethod def GetOrCreate(cls, ren, runAsync=True, **kwargs): @@ -223,6 +224,7 @@ def __panCam(self, mouseDelta): def __zoomCam(self, mouseDelta): #zooms by scaling the distance between camera and focus rlim = 0.00001 #minimum allowable radius + d = (1.0+self.zoomScale)**mouseDelta if self.mode == 'Dask': from dask.distributed import wait wait([r.zoomCam(mouseDelta,rlim) for r in self.renderers]) @@ -230,7 +232,7 @@ def __zoomCam(self, mouseDelta): (self.renv.CameraPosition, self.renv.CameraFocalPoint, self.renv.CameraViewUp) = zoomCameraTurntable( - mouseDelta, + d, self.renv.CameraPosition, self.renv.CameraFocalPoint, self.renv.CameraViewUp, diff --git a/js/lib/widgets.js b/js/lib/widgets.js index 64804e1..36d4eca 100644 --- a/js/lib/widgets.js +++ b/js/lib/widgets.js @@ -115,18 +115,14 @@ var PVDisplayView = widgets.DOMWidgetView.extend({ }; function handleScroll(e){ - const wheelScl = 1.0/40.0; - const dScl = 0.05; - e.preventDefault(); e.stopPropagation(); - let d = e.wheelDelta ? e.wheelDelta*wheelScl : e.detail ? -e.detail : 0; - wheelAccum += d; + wheelAccum += Math.sign(e.deltaY); t = Date.now(); if(t - lastMouseT > 1000.0/model.get('maxEventRate')){ if(wheelAccum){ - view.send({event: 'zoom', 'data': 1.0-dScl*wheelAccum}); + view.send({event: 'zoom', 'data': wheelAccum}); } wheelAccum = 0.0; lastMouseT = t;