Skip to content

Commit ca26892

Browse files
committed
DRY up button remove routine
1 parent 06e8140 commit ca26892

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

src/components/updatemenus/draw.js

+16-10
Original file line numberDiff line numberDiff line change
@@ -82,21 +82,23 @@ module.exports = function draw(gd) {
8282
.classed(constants.buttonGroupClassName, true)
8383
.style('pointer-events', 'all');
8484

85-
// whenever we add new menu,
85+
// whenever we add new menu, attach 'state' variable to node
86+
// to keep track of the active menu ('-1' means no menu is active)
87+
// and remove all dropped buttons (if any)
8688
if(headerGroups.enter().size()) {
87-
88-
// attach 'state' variable to node to keep track of the active menu
89-
// '-1' means no menu is active
90-
gButton.attr(constants.menuIndexAttrName, '-1');
91-
92-
// remove all dropped buttons (if any)
93-
gButton.selectAll('g.' + constants.buttonClassName).remove();
89+
gButton
90+
.call(removeAllButtons)
91+
.attr(constants.menuIndexAttrName, '-1');
9492
}
9593

9694
// remove exiting header, remove dropped buttons and reset margins
9795
headerGroups.exit().each(function(menuOpts) {
9896
d3.select(this).remove();
99-
gButton.selectAll('g.' + constants.buttonClassName).remove();
97+
98+
gButton
99+
.call(removeAllButtons)
100+
.attr(constants.menuIndexAttrName, '-1');
101+
100102
Plots.autoMargin(gd, constants.autoMarginIdRoot + menuOpts._index);
101103
});
102104

@@ -177,7 +179,7 @@ function drawHeader(gd, gHeader, gButton, menuOpts) {
177179
});
178180

179181
header.on('click', function() {
180-
gButton.selectAll('g.' + constants.buttonClassName).remove();
182+
gButton.call(removeAllButtons);
181183

182184
// if clicked index is same as dropped index => fold
183185
// otherwise => drop buttons associated with header
@@ -429,3 +431,7 @@ function setItemPosition(item, menuOpts, posOpts) {
429431

430432
posOpts.y += menuOpts.height1 + posOpts.yPad;
431433
}
434+
435+
function removeAllButtons(gButton) {
436+
gButton.selectAll('g.' + constants.buttonClassName).remove();
437+
}

0 commit comments

Comments
 (0)