Skip to content

Commit 74350d6

Browse files
committed
make Modebar constructor not rely on button config in scope:
- each button's config is passed to the constructor on init.
1 parent b3fdb5d commit 74350d6

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

src/components/modebar/index.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ var Icons = require('../../../build/ploticon');
1919
* UI controller for interactive plots
2020
* @Class
2121
* @Param {object} opts
22-
* @Param {object} opts.buttons nested arrays of grouped buttons to initialize
22+
* @Param {object} opts.buttons nested arrays of grouped buttons config objects
2323
* @Param {object} opts.container container div to append modebar
2424
* @Param {object} opts.graphInfo primary plot object containing data and layout
2525
*/
@@ -52,6 +52,7 @@ proto.update = function(graphInfo, buttons) {
5252
}
5353
else this.element.className = 'modebar';
5454

55+
// if buttons or logo have changed, redraw modebar interior
5556
var needsNewButtons = !this.hasButtons(buttons),
5657
needsNewLogo = (this.hasLogo !== context.displaylogo);
5758

@@ -78,15 +79,10 @@ proto.updateButtons = function(buttons) {
7879
this.buttons.forEach(function(buttonGroup) {
7980
var group = _this.createGroup();
8081

81-
buttonGroup.forEach(function(buttonName) {
82-
var buttonConfig = buttonsConfig[buttonName];
83-
84-
if (!buttonConfig) {
85-
throw new Error(buttonName + 'not specfied in modebar configuration');
82+
buttonGroup.forEach(function(buttonConfig) {
8683
}
8784

8885
var button = _this.createButton(buttonConfig);
89-
9086
_this.buttonElements.push(button);
9187
group.appendChild(button);
9288
});
@@ -108,7 +104,7 @@ proto.createGroup = function () {
108104

109105
/**
110106
* Create a new button div and set constant and configurable attributes
111-
* @Param {object} config (see ./modebar_config,js for more info)
107+
* @Param {object} config (see ./buttons.js for more info)
112108
* @Return {HTMLelement}
113109
*/
114110
proto.createButton = function (config) {

0 commit comments

Comments
 (0)