8000 new cartesian axis modebarbuttons attribute · plotly/plotly.js@e34618b · GitHub
[go: up one dir, main page]

Skip to content

Commit e34618b

Browse files
committed
new cartesian axis modebarbuttons attribute
1 parent 046d0ec commit e34618b

File tree

6 files changed

+105
-3
lines changed

6 files changed

+105
-3
lines changed

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.modebarbuttons === 'all' || ax.modebarbuttons.indexOf(
264+
(val === 'auto' || val === 'reset') ? 'auto' : 'inout'
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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ 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+
if(!axList[i].fixedrange && axList[i].modebarbuttons !== 'none') {
273273
return false;
274274
}
275275
}

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+
modebarbuttons: {
393+
valType: 'flaglist',
394+
flags: ['auto', 'inout'],
395+
extras: ['all', 'none'],
396+
dflt: 'all',
397+
editType: 'modebar',
398+
description: [
399+
'Determines which modebar buttons impact this axis.',
400+
'*auto* allows the autoscale buttons, *inout* allows the',
401+
'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('modebarbuttons');
341342

342343
addMissingMatchedAxis();
343344

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

368369
coerce('fixedrange');
370+
coerce('modebarbuttons');
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('modebarbuttons');
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 modebarbuttons attribute', function(done) {
1198+
Plotly.relayout(gd, {
1199+
'xaxis.modebarbuttons': 'none',
1200+
'xaxis2.modebarbuttons': 'auto',
1201+
'yaxis.modebarbuttons': 'inout',
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() {

test/plot-schema.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13912,6 +13912,20 @@
1391213912
"allticks"
1391313913
]
1391413914
},
13915+
"modebarbuttons": {
13916+
"description": "Determines which modebar buttons impact this axis. *auto* allows the autoscale buttons, *inout* allows the zoom-in and zoom-out buttons.",
13917+
"dflt": "all",
13918+
"editType": "modebar",
13919+
"extras": [
13920+
"all",
13921+
"none"
13922+
],
13923+
"flags": [
13924+
"auto",
13925+
"inout"
13926+
],
13927+
"valType": "flaglist"
13928+
},
1391513929
"nticks": {
1391613930
"description": "Specifies the maximum number of ticks for the particular axis. The actual number of ticks will be chosen automatically to be less than or equal to `nticks`. Has an effect only if `tickmode` is set to *auto*.",
1391713931
"dflt": 0,
@@ -15463,6 +15477,20 @@
1546315477
"allticks"
1546415478
]
1546515479
},
15480+
"modebarbuttons": {
15481+
"description": "Determines which modebar buttons impact this axis. *auto* allows the autoscale buttons, *inout* allows the zoom-in and zoom-out buttons.",
15482+
"dflt": "all",
15483+
"editType": "modebar",
15484+
"extras": [
15485+
"all",
15486+
"none"
15487+
],
15488+
"flags": [
15489+
"auto",
15490+
"inout"
15491+
],
15492+
"valType": "flaglist"
15493+
},
1546615494
"nticks": {
1546715495
"description": "Specifies the maximum number of ticks for the particular axis. The actual number of ticks will be chosen automatically to be less than or equal to `nticks`. Has an effect only if `tickmode` is set to *auto*.",
1546815496
"dflt": 0,

0 commit comments

Comments
 (0)
0