Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix modeBarButtons issue #6177

Merged
merged 4 commits into from
May 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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