Skip to content

Commit

Permalink
Merge pull request #6177 from nickmelnikov82/fix-modebarbuttons-issue
Browse files Browse the repository at this point in the history
Fix modeBarButtons issue
  • Loading branch information
archmoj authored May 9, 2022
2 parents 57dee2e + 77383de commit 6c1c119
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions draftlogs/6177_fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Fix custom modebar buttons mutate the input [[#6177](https://github.com/plotly/plotly.js/pull/6177)]
5 changes: 4 additions & 1 deletion src/components/modebar/manage.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ var isUnifiedHover = require('../fx/helpers').isUnifiedHover;
var createModeBar = require('./modebar');
var modeBarButtons = require('./buttons');
var DRAW_MODES = require('./constants').DRAW_MODES;
var extendDeep = require('../../lib').extendDeep;

/**
* ModeBar wrapper around 'create' and 'update',
Expand Down Expand Up @@ -330,7 +331,9 @@ function appendButtonsToGroups(groups, buttons) {
}

// fill in custom buttons referring to default mode bar buttons
function fillCustomButton(customButtons) {
function fillCustomButton(originalModeBarButtons) {
var customButtons = extendDeep([], originalModeBarButtons);

for(var i = 0; i < customButtons.length; i++) {
var buttonGroup = customButtons[i];

Expand Down
9 changes: 9 additions & 0 deletions test/jasmine/tests/modebar_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -996,6 +996,15 @@ describe('ModeBar', function() {
expect(countButtons(gd._fullLayout._modeBar))
.toEqual(initialButtonCount + 6);
});

it('sets up buttons without changing the input', function() {
var config = [['toImage']];
var gd = setupGraphInfo();
gd._context.modeBarButtons = config;
manageModeBar(gd);
expect(config).toEqual([['toImage']]);
expect(countButtons(gd._fullLayout._modeBar)).toEqual(2);
});
});

describe('modebar on clicks', function() {
Expand Down

0 comments on commit 6c1c119

Please sign in to comment.