Skip to content

Commit ee3106f

Browse files
committed
Merge remote-tracking branch 'origin-plotly/master' into fix-edit-shapes
2 parents 58c811a + f7c4692 commit ee3106f

File tree

11 files changed

+138
-16
lines changed

11 files changed

+138
-16
lines changed

draftlogs/7358_add.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Add modebardisable attribute to cartesian axes, to allow fine control over which buttons affect which axes [[#7358](https://github.com/plotly/plotly.js/pull/7358)]

draftlogs/7474_fix.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Fix scroll wheel zoom for geo subplots in Safari [#7474](https://github.com/plotly/plotly.js/pull/7474)

package-lock.json

Lines changed: 16 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,5 +178,10 @@
178178
"transform-loader": "^0.2.4",
179179
"true-case-path": "^2.2.1",
180180
"virtual-webgl": "^1.0.6"
181+
},
182+
"overrides": {
183+
"falafel": {
184+
"acorn": "^8.1.1"
185+
}
181186
}
182-
}
187+
}

src/components/modebar/buttons.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,12 +256,15 @@ function handleCartesian(gd, ev) {
256256
var mag = (val === 'in') ? 0.5 : 2;
257257
var r0 = (1 + mag) / 2;
258258
var r1 = (1 - mag) / 2;
259-
var axName;
259+
var axName, allowed;
260260

261261
for(i = 0; i < axList.length; i++) {
262262
ax = axList[i];
263+
allowed = ax.modebardisable === 'none' || ax.modebardisable.indexOf(
264+
(val === 'auto' || val === 'reset') ? 'autoscale' : 'zoominout'
265+
) === -1;
263266

264-
if(!ax.fixedrange) {
267+
if(allowed && !ax.fixedrange) {
265268
axName = ax._name;
266269
if(val === 'auto') {
267270
aobj[axName + '.autorange'] = true;

src/components/modebar/manage.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,8 @@ function areAllAxesFixed(fullLayout) {
269269
var axList = axisIds.list({_fullLayout: fullLayout}, null, true);
270270

271271
for(var i = 0; i < axList.length; i++) {
272-
if(!axList[i].fixedrange) {
272+
var disabled = axList[i].modebardisable;
273+
if(!axList[i].fixedrange && disabled !== 'autoscale+zoominout' && disabled !== 'zoominout+autoscale') {
273274
return false;
274275
}
275276
}

src/lib/events.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,16 @@ var Events = {
5959
internalEv.emit(event, data);
6060
};
6161

62+
/*
63+
* Add a dummy event handler for 'wheel' event for Safari
64+
* to enable mouse wheel zoom.
65+
* https://github.com/d3/d3/issues/3035
66+
* https://github.com/plotly/plotly.js/issues/7452
67+
*/
68+
if(typeof plotObj.addEventListener === 'function') {
69+
plotObj.addEventListener("wheel", () => {});
70+
}
71+
6272
return plotObj;
6373
},
6474

src/plots/cartesian/layout_attributes.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,18 @@ module.exports = {
389389
'If true, then zoom is disabled.'
390390
].join(' ')
391391
},
392+
modebardisable: {
393+
valType: 'flaglist',
394+
flags: ['autoscale', 'zoominout'],
395+
extras: ['none'],
396+
dflt: 'none',
397+
editType: 'modebar',
398+
description: [
399+
'Disables certain modebar buttons for this axis.',
400+
'*autoscale* disables the autoscale buttons, *zoominout*',
401+
'disables the zoom-in and zoom-out buttons.'
402+
].join(' ')
403+
},
392404
insiderange: {
393405
valType: 'info_array',
394406
items: [

src/plots/cartesian/layout_defaults.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,7 @@ module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) {
338338
});
339339

340340
coerce('fixedrange');
341+
coerce('modebardisable');
341342

342343
addMissingMatchedAxis();
343344

@@ -366,6 +367,7 @@ module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) {
366367
}
367368

368369
coerce('fixedrange');
370+
coerce('modebardisable');
369371
}
370372

371373
for(i = 0; i < yNames.length; i++) {
@@ -378,6 +380,7 @@ module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) {
378380
var fixedRangeDflt = getComponentMethod('rangeslider', 'isVisible')(anchoredAxis);
379381

380382
coerce('fixedrange', fixedRangeDflt);
383+
coerce('modebardisable');
381384
}
382385

383386
// Finally, handle scale constraints and matching axes.

test/jasmine/tests/modebar_test.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,6 +1193,62 @@ describe('ModeBar', function() {
11931193
assertRange('xaxis2', [-1, 4]);
11941194
assertRange('yaxis2', [0, 4]);
11951195
});
1196+
1197+
it('should respect modebardisable attribute', function(done) {
1198+
Plotly.relayout(gd, {
1199+
'xaxis.modebardisable': 'zoominout+autoscale',
1200+
'xaxis2.modebardisable': 'zoominout',
1201+
'yaxis.modebardisable': 'autoscale',
1202+
}).then(function() {
1203+
var buttonZoomIn = selectButton(modeBar, 'zoomIn2d');
1204+
var buttonZoomOut = selectButton(modeBar, 'zoomOut2d');
1205+
1206+
assertRange('xaxis', ['2016-01-01', '2016-04-01']);
1207+
assertRange('yaxis', [1, 3]);
1208+
assertRange('xaxis2', [-1, 4]);
1209+
assertRange('yaxis2', [0, 4]);
1210+
1211+
// xaxis and xaxis2 should not be affected by zoom in/out
1212+
// yaxis and yaxis2 should be affected as in previous test
1213+
buttonZoomIn.click();
1214+
assertRange('xaxis', ['2016-01-01', '2016-04-01']);
1215+
assertRange('yaxis', [1.5, 2.5]);
1216+
assertRange('xaxis2', [-1, 4]);
1217+
assertRange('yaxis2', [1, 3]);
1218+
1219+
buttonZoomOut.click();
1220+
assertRange('xaxis', ['2016-01-01', '2016-04-01']);
1221+
assertRange('yaxis', [1, 3]);
1222+
assertRange('xaxis2', [-1, 4]);
1223+
assertRange('yaxis2', [0, 4]);
1224+
1225+
return Plotly.relayout(gd, {
1226+
'xaxis.range': ['2016-01-23 17:45', '2016-03-09 05:15'],
1227+
'yaxis.range': [1.5, 2.5],
1228+
'xaxis2.range': [0.25, 2.75],
1229+
'yaxis2.range': [1, 3],
1230+
});
1231+
})
1232+
.then(function() {
1233+
var buttonAutoScale = selectButton(modeBar, 'autoScale2d');
1234+
var buttonResetScale = selectButton(modeBar, 'resetScale2d');
1235+
1236+
// xaxis and yaxis should not be affected by autorange
1237+
// xaxis2 and yaxis2 should be affected as in previous test
1238+
buttonAutoScale.click();
1239+
assertRange('xaxis', ['2016-01-23 17:45', '2016-03-09 05:15']);
1240+
assertRange('yaxis', [1.5, 2.5]);
1241+
assertRange('xaxis2', [-0.5, 2.5]);
1242+
assertRange('yaxis2', [0, 2.105263]);
1243+
1244+
buttonResetScale.click();
1245+
assertRange('xaxis', ['2016-01-23 17:45', '2016-03-09 05:15']);
1246+
assertRange('yaxis', [1.5, 2.5]);
1247+
assertRange('xaxis2', [-1, 4]);
1248+
assertRange('yaxis2', [0, 4]);
1249+
})
1250+
.then(done, done.fail)
1251+
});
11961252
});
11971253

11981254
describe('buttons zoom2d, pan2d, select2d and lasso2d', function() {

0 commit comments

Comments
 (0)