Skip to content

Commit 26936aa

Browse files
committed
add ability to multiple mode bar button groups via 'modeBarButtonToAdd'
1 parent 71033b9 commit 26936aa

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/components/modebar/manage.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,15 @@ function getButtonGroups(fullLayout, buttonsToRemove, buttonsToAdd) {
114114
addGroup(['hoverClosestPie']);
115115
}
116116

117-
if(buttonsToAdd.length) groups.push(buttonsToAdd);
117+
// append buttonsToAdd to the groups
118+
if(buttonsToAdd.length) {
119+
if(Array.isArray(buttonsToAdd[0])) {
120+
for(var i = 0; i < buttonsToAdd.length; i++) {
121+
groups.push(buttonsToAdd[i]);
122+
}
123+
}
124+
else groups.push(buttonsToAdd);
125+
}
118126

119127
return groups;
120128
}

test/jasmine/tests/modebar_test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,26 @@ describe('ModeBar', function() {
369369
expect(countButtons(modeBar)).toEqual(10);
370370
});
371371

372+
it('sets up buttons with modeBarButtonsToAdd and modeBarButtonToRemove (2)', function() {
373+
var gd = setupGraphInfo();
374+
gd._context.modeBarButtonsToRemove = [
375+
'toImage', 'pan2d', 'hoverCompareCartesian'
376+
];
377+
gd._context.modeBarButtonsToAdd = [[
378+
{ name: 'some button', click: noop },
379+
{ name: 'some other button', click: noop }
380+
], [
381+
{ name: 'some button 2', click: noop },
382+
{ name: 'some other button 2', click: noop }
383+
]];
384+
385+
manageModeBar(gd);
386+
387+
var modeBar = gd._fullLayout._modeBar;
388+
expect(countGroups(modeBar)).toEqual(7);
389+
expect(countButtons(modeBar)).toEqual(12);
390+
});
391+
372392
it('sets up buttons with fully custom modeBarButtons', function() {
373393
var gd = setupGraphInfo();
374394
gd._context.modeBarButtons = [[

0 commit comments

Comments
 (0)