8000 add 'modebarButtonsToRemove' config argument: · siqitech/plotly.js@40e3021 · GitHub
[go: up one dir, main page]

Skip to content

Commit 40e3021

Browse files
committed
add 'modebarButtonsToRemove' config argument:
- adds ability to remove specific modebar buttons by listing their names upon plot configuration - throw error if 'modebarButtonsToRemove' isn't an Array - add filter step to choose button routine, removing buttons that are in 'modebarButtonsToRemove' list.
1 parent 10d591b commit 40e3021

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

src/components/modebar/manage.js

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,20 @@ module.exports = function manageModebar(gd) {
3333
return;
3434
}
3535

36-
var buttons = chooseButtons(fullLayout, context.modebarButtons);
36+
if(!Array.isArray(context.modebarButtonsToRemove)) {
37+
throw new Error([
38+
'*modebarButtonsToRemove* configuration options',
39+
'must be an array.'
40+
].join(' '));
41+
}
42+
43+
var buttons = chooseButtons(fullLayout, context.modebarButtonsToRemove);
3744

3845
if(modebar) modebar.update(gd, buttons);
3946
else fullLayout._modebar = createModebar(gd, buttons);
4047
};
4148

42-
function chooseButtons(fullLayout) {
49+
function chooseButtons(fullLayout, buttonsToRemove) {
4350
var buttons = findButtons('all');
4451

4552
if(fullLayout._hasGL3D) buttons = buttons.concat(findButtons('gl3d'));
@@ -58,6 +65,7 @@ function chooseButtons(fullLayout) {
5865

5966
if(fullLayout._hasPie) buttons = buttons.concat(findButtons('pie'));
6067

68+
buttons = filterButtons(buttons, buttonsToRemove);
6169
buttons = groupButtons(buttons);
6270

6371
return buttons;
@@ -89,6 +97,21 @@ function areAllAxesFixed(fullLayout) {
8997
return allFixed;
9098
}
9199

100+
// Remove buttons according to modebarButtonsToRemove plot config options
101+
function filterButtons(buttons, buttonsToRemove) {
102+
var out = [];
103+
104+
for(var i = 0; i < buttons.length; i++) {
105+
var button = buttons[i];
106+
107+
if(buttonsToRemove.indexOf(button) !== -1) continue;
108+
109+
out.push(button);
110+
}
111+
112+
return out;
113+
}
114+
92115
function groupButtons(buttons) {
93116
var hashObj = {};
94117
var i;

src/plot_api/plot_config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ module.exports = {
5858
// display the modebar (true, false, or 'hover')
5959
displayModeBar: 'hover',
6060

61+
// remove modebar button by name
62+
modebarButtonsToRemove: [],
63+
6164
// add the plotly logo on the end of the modebar
6265
displaylogo: true,
6366

0 commit comments

Comments
 (0)
0