Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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 modeBarButtons mutate the input, issue [[#1157](https://github.com/plotly/dash/issues/1157)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- Fix modeBarButtons mutate the input, issue [[#1157](https://github.com/plotly/dash/issues/1157)]
- Fix custom modebar buttons mutate the input [[#6177](https://github.com/plotly/plotly.js/pull/6177)]

3 changes: 2 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 @@ -44,7 +45,7 @@ module.exports = function manageModeBar(gd) {
].join(' '));
}

var customButtons = context.modeBarButtons;
var customButtons = extendDeep([], context.modeBarButtons);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This deep copy appears to be needed in the first case only.
I suggest you revert the change here and move deep copy inside fillCustomButton function.
For example:

function fillCustomButton(inButtons) {
  var customButtons = extendDeep([], inButtons);
  ...

var buttonGroups;

if(Array.isArray(customButtons) && customButtons.length) {
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