Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 313da5c

Browse files
committed
add 'modeBarButtonsToAdd' config arg:
- takes an array of buttons config objects (as the defined for the default buttons in modebar/buttons.js) - these 'buttons to add' get appended an additional group of buttons passed to the ModeBar constructor
1 parent 9972341 commit 313da5c

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

src/components/modebar/manage.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,26 @@ module.exports = function manageModeBar(gd) {
4040
].join(' '));
4141
}
4242

43-
// if(!Array.isArray(context.m))
43+
if(!Array.isArray(context.modeBarButtonsToAdd)) {
44+
throw new Error([
45+
'*modeBarButtonsToAdd* configuration options',
46+
'must be an array.'
47+
].join(' '));
48+
}
49+
4450

45-
var buttonGroups = getButtonGroups(fullLayout, context.modeBarButtonsToRemove);
51+
buttonGroups = getButtonGroups(
52+
fullLayout,
53+
context.modeBarButtonsToRemove,
54+
context.modeBarButtonsToAdd
55+
);
4656

4757
if(modeBar) modeBar.update(gd, buttonGroups);
4858
else fullLayout._modeBar = createModeBar(gd, buttonGroups);
4959
};
5060

5161
// logic behind which buttons are displayed by default
52-
function getButtonGroups(fullLayout, buttonsToRemove) {
62+
function getButtonGroups(fullLayout, buttonsToRemove, buttonsToAdd) {
5363
var groups = [];
5464

5565
function addGroup(newGroup) {
@@ -97,6 +107,8 @@ function getButtonGroups(fullLayout, buttonsToRemove) {
97107
addGroup(['hoverClosestPie']);
98108
}
99109

110+
if(buttonsToAdd.length) groups.push(buttonsToAdd);
111+
100112
return groups;
101113
}
102114

src/plot_api/plot_config.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,14 @@ module.exports = {
5858
// display the mode bar (true, false, or 'hover')
5959
displayModeBar: 'hover',
6060

61-
// remove modebar button by name
61+
// remove mode bar button by name
6262
// (see ./components/modebar/buttons.js for the list of names)
6363
modeBarButtonsToRemove: [],
6464

65+
// add mode bar button using config objects
66+
// (see ./components/modebar/buttons.js for list of arguments)
67+
modeBarButtonsToAdd: [],
68+
6569
// add the plotly logo on the end of the mode bar
6670
displaylogo: true,
6771

0 commit comments

Comments
 (0)