Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 2k
Make scrollZoom config option a flaglist#3422
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
c83538ab56591d26618dd16a01e709f1af5File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -48,6 +48,7 @@ function createCamera(element, options) { | ||
| var camera = { | ||
| keyBindingMode: 'rotate', | ||
| enableWheel: true, | ||
archmoj marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| view: view, | ||
| element: element, | ||
| delay: options.delay || 16, | ||
| @@ -257,7 +258,9 @@ function createCamera(element, options) { | ||
| } | ||
| camera.wheelListener = mouseWheel(element, function(dx, dy) { | ||
| // TODO remove now that we can disable scroll via scrollZoom? | ||
| if(camera.keyBindingMode === false) return; | ||
| if(!camera.enableWheel) return; | ||
| var flipX = camera.flipX ? 1 : -1; | ||
| var flipY = camera.flipY ? 1 : -1; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -227,8 +227,15 @@ function initializeGLPlot(scene, canvas, gl) { | ||
| scene.graphDiv.emit('plotly_relayout', update); | ||
| }; | ||
| scene.glplot.canvas.addEventListener('mouseup', relayoutCallback.bind(null, scene)); | ||
| scene.glplot.canvas.addEventListener('wheel', relayoutCallback.bind(null, scene), passiveSupported ? {passive: false} : false); | ||
| scene.glplot.canvas.addEventListener('mouseup', function() { | ||
| relayoutCallback(scene); | ||
| }); | ||
| scene.glplot.canvas.addEventListener('wheel', function() { | ||
| if(gd._context._scrollZoom.gl3d) { | ||
| relayoutCallback(scene); | ||
| } | ||
| }, passiveSupported ? {passive: false} : false); | ||
Comment on lines
+234
to
+238
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've disabled scrollZoom in the plot config, but the mouse is still getting captured when scrolling by the canvas. Looks like it's because of the wheel event listener that's being registered here anyway. After I remove the wheel listener on scene element from chrome inspector, scrolling the page no longer gets captured by the canvas. @etpinard, can we not add the listener at all if scrollzoom is disabled? Collaborator There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @zfei thanks for the debugging. This comment is going to get lost here on a merged PR though, can you make a new issue for this? Or better yet a PR, looks like it's probably a pretty easy fix 😎 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks @alexcjohnson. I've never touched the Plotly codebase and haven't set up my mind to go through the learning curve yet. 😉 Will just leave it as an issue for now. | ||
| if(!scene.staticMode) { | ||
| scene.glplot.canvas.addEventListener('webglcontextlost', function(event) { | ||
| @@ -385,7 +392,6 @@ function computeTraceBounds(scene, trace, bounds) { | ||
| } | ||
| proto.plot = function(sceneData, fullLayout, layout) { | ||
| // Save parameters | ||
| this.plotArgs = [sceneData, fullLayout, layout]; | ||
| @@ -412,6 +418,7 @@ proto.plot = function(sceneData, fullLayout, layout) { | ||
| // Update camera and camera mode | ||
| this.setCamera(fullSceneLayout.camera); | ||
| this.updateFx(fullSceneLayout.dragmode, fullSceneLayout.hovermode); | ||
| this.camera.enableWheel = this.graphDiv._context._scrollZoom.gl3d; | ||
| // Update scene | ||
| this.glplot.update({}); | ||
| @@ -776,7 +783,6 @@ proto.updateFx = function(dragmode, hovermode) { | ||
| fullCamera.up = zUp; | ||
| Lib.nestedProperty(layout, attr).set(zUp); | ||
| } else { | ||
| // none rotation modes [pan or zoom] | ||
| camera.keyBindingMode = dragmode; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -760,4 +760,63 @@ describe('config argument', function() { | ||
| .then(done); | ||
| }); | ||
| }); | ||
| describe('scrollZoom:', function() { | ||
| var gd; | ||
| beforeEach(function() { gd = createGraphDiv(); }); | ||
| afterEach(destroyGraphDiv); | ||
| function plot(config) { | ||
| return Plotly.plot(gd, [], {}, config); | ||
| } | ||
| it('should fill in scrollZoom default', function(done) { | ||
| plot(undefined).then(function() { | ||
| expect(gd._context.scrollZoom).toBe('gl3d+geo+mapbox'); | ||
| expect(gd._context._scrollZoom).toEqual({gl3d: 1, geo: 1, mapbox: 1}); | ||
archmoj marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| expect(gd._context._scrollZoom.cartesian).toBe(undefined, 'no cartesian!'); | ||
| }) | ||
| .catch(failTest) | ||
| .then(done); | ||
| }); | ||
| it('should fill in blank scrollZoom value', function(done) { | ||
| plot({scrollZoom: null}).then(function() { | ||
| expect(gd._context.scrollZoom).toBe(null); | ||
| expect(gd._context._scrollZoom).toEqual({gl3d: 1, geo: 1, mapbox: 1}); | ||
archmoj marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| expect(gd._context._scrollZoom.cartesian).toBe(undefined, 'no cartesian!'); | ||
| }) | ||
| .catch(failTest) | ||
| .then(done); | ||
| }); | ||
| it('should honor scrollZoom:true', function(done) { | ||
| plot({scrollZoom: true}).then(function() { | ||
| expect(gd._context.scrollZoom).toBe(true); | ||
| expect(gd._context._scrollZoom).toEqual({gl3d: 1, geo: 1, cartesian: 1, mapbox: 1}); | ||
| }) | ||
| .catch(failTest) | ||
| .then(done); | ||
| }); | ||
| it('should honor scrollZoom:false', function(done) { | ||
| plot({scrollZoom: false}).then(function() { | ||
| expect(gd._context.scrollZoom).toBe(false); | ||
| expect(gd._context._scrollZoom).toEqual({}); | ||
| }) | ||
| .catch(failTest) | ||
| .then(done); | ||
| }); | ||
| it('should honor scrollZoom flaglist', function(done) { | ||
| plot({scrollZoom: 'mapbox+cartesian'}).then(function() { | ||
| expect(gd._context.scrollZoom).toBe('mapbox+cartesian'); | ||
| expect(gd._context._scrollZoom).toEqual({mapbox: 1, cartesian: 1}); | ||
| }) | ||
| .catch(failTest) | ||
| .then(done); | ||
| }); | ||
| }); | ||
| }); | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.