Skip to content

Commit c83538a

Browse files
committed
make scrollZoom a flaglist w/ dflt 'gl3d+geo+mapbox'
- which match the current "default", but will make scrollZoom:false disable zoom for all subplots!
1 parent f9cfadb commit c83538a

File tree

5 files changed

+87
-6
lines changed

5 files changed

+87
-6
lines changed

src/plot_api/plot_api.js

+19
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,25 @@ function setPlotContext(gd, config) {
507507
// Check if gd has a specified widht/height to begin with
508508
context._hasZeroHeight = context._hasZeroHeight || gd.clientHeight === 0;
509509
context._hasZeroWidth = context._hasZeroWidth || gd.clientWidth === 0;
510+
511+
// fill context._scrollZoom helper to help manage scrollZoom flaglist
512+
var szIn = context.scrollZoom;
513+
var szOut = context._scrollZoom = {};
514+
if(szIn === true) {
515+
szOut.cartesian = 1;
516+
szOut.gl3d = 1;
517+
szOut.geo = 1;
518+
szOut.mapbox = 1;
519+
} else if(typeof szIn === 'string') {
520+
var parts = szIn.split('+');
521+
for(i = 0; i < parts.length; i++) {
522+
szOut[parts[i]] = 1;
523+
}
524+
} else if(szIn !== false) {
525+
szOut.gl3d = 1;
526+
szOut.geo = 1;
527+
szOut.mapbox = 1;
528+
}
510529
}
511530

512531
function plotLegacyPolar(gd, data, layout) {

src/plot_api/plot_config.js

+9-4
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,16 @@ var configAttributes = {
145145
},
146146

147147
scrollZoom: {
148-
valType: 'boolean',
149-
dflt: false,
148+
valType: 'flaglist',
149+
flags: ['cartesian', 'gl3d', 'geo', 'mapbox'],
150+
extras: [true, false],
151+
dflt: 'gl3d+geo+mapbox',
150152
description: [
151-
'Determines whether mouse wheel or two-finger scroll zooms is',
152-
'enable. Has an effect only on cartesian subplots.'
153+
'Determines whether mouse wheel or two-finger scroll zooms is enable.',
154+
'Turned on by default for gl3d, geo and mapbox subplots',
155+
'(as these subplot types do not have zoombox via pan),',
156+
'but turned off by default for cartesian subplots.',
157+
'Set `scrollZoom` to *false* to disable scrolling for all subplots.'
153158
].join(' ')
154159
},
155160
doubleClick: {

src/plots/cartesian/dragbox.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ function makeDragBox(gd, plotinfo, x, y, w, h, ns, ew) {
417417
// deactivate mousewheel scrolling on embedded graphs
418418
// devs can override this with layout._enablescrollzoom,
419419
// but _ ensures this setting won't leave their page
420-
if(!gd._context.scrollZoom && !gd._fullLayout._enablescrollzoom) {
420+
if(!gd._context._scrollZoom.cartesian && !gd._fullLayout._enablescrollzoom) {
421421
return;
422422
}
423423

src/plots/gl2d/scene2d.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ function Scene2D(options, fullLayout) {
3838
this.pixelRatio = options.plotGlPixelRatio || window.devicePixelRatio;
3939
this.id = options.id;
4040
this.staticPlot = !!options.staticPlot;
41-
this.scrollZoom = this.graphDiv._context.scrollZoom;
41+
this.scrollZoom = this.graphDiv._context._scrollZoom.cartesian;
4242

4343
this.fullData = null;
4444
this.updateRefs(fullLayout);

test/jasmine/tests/config_test.js

+57
Original file line numberDiff line numberDiff line change
@@ -760,4 +760,61 @@ describe('config argument', function() {
760760
.then(done);
761761
});
762762
});
763+
764+
describe('scrollZoom:', function() {
765+
var gd;
766+
767+
beforeEach(function() { gd = createGraphDiv(); });
768+
769+
afterEach(destroyGraphDiv);
770+
771+
function plot(config) {
772+
return Plotly.plot(gd, [], {}, config);
773+
}
774+
775+
it('should fill in scrollZoom default', function(done) {
776+
plot(undefined).then(function() {
777+
expect(gd._context.scrollZoom).toBe('gl3d+geo+mapbox');
778+
expect(gd._context._scrollZoom).toEqual({gl3d: 1, geo: 1, mapbox: 1});
779+
})
780+
.catch(failTest)
781+
.then(done);
782+
});
783+
784+
it('should fill in blank scrollZoom value', function(done) {
785+
plot({scrollZoom: null}).then(function() {
786+
expect(gd._context.scrollZoom).toBe(null);
787+
expect(gd._context._scrollZoom).toEqual({gl3d: 1, geo: 1, mapbox: 1});
788+
})
789+
.catch(failTest)
790+
.then(done);
791+
});
792+
793+
it('should honor scrollZoom:true', function(done) {
794+
plot({scrollZoom: true}).then(function() {
795+
expect(gd._context.scrollZoom).toBe(true);
796+
expect(gd._context._scrollZoom).toEqual({gl3d: 1, geo: 1, cartesian: 1, mapbox: 1});
797+
})
798+
.catch(failTest)
799+
.then(done);
800+
});
801+
802+
it('should honor scrollZoom:false', function(done) {
803+
plot({scrollZoom: false}).then(function() {
804+
expect(gd._context.scrollZoom).toBe(false);
805+
expect(gd._context._scrollZoom).toEqual({});
806+
})
807+
.catch(failTest)
808+
.then(done);
809+
});
810+
811+
it('should honor scrollZoom flaglist', function(done) {
812+
plot({scrollZoom: 'mapbox+cartesian'}).then(function() {
813+
expect(gd._context.scrollZoom).toBe('mapbox+cartesian');
814+
expect(gd._context._scrollZoom).toEqual({mapbox: 1, cartesian: 1});
815+
})
816+
.catch(failTest)
817+
.then(done);
818+
});
819+
});
763820
});

0 commit comments

Comments
 (0)