@@ -82,21 +82,23 @@ module.exports = function draw(gd) {
82
82
. classed ( constants . buttonGroupClassName , true )
83
83
. style ( 'pointer-events' , 'all' ) ;
84
84
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)
86
88
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' ) ;
94
92
}
95
93
96
94
// remove exiting header, remove dropped buttons and reset margins
97
95
headerGroups . exit ( ) . each ( function ( menuOpts ) {
98
96
d3 . select ( this ) . remove ( ) ;
99
- gButton . selectAll ( 'g.' + constants . buttonClassName ) . remove ( ) ;
97
+
98
+ gButton
99
+ . call ( removeAllButtons )
100
+ . attr ( constants . menuIndexAttrName , '-1' ) ;
101
+
100
102
Plots . autoMargin ( gd , constants . autoMarginIdRoot + menuOpts . _index ) ;
101
103
} ) ;
102
104
@@ -177,7 +179,7 @@ function drawHeader(gd, gHeader, gButton, menuOpts) {
177
179
} ) ;
178
180
179
181
header . on ( 'click' , function ( ) {
180
- gButton . selectAll ( 'g.' + constants . buttonClassName ) . remove ( ) ;
182
+ gButton . call ( removeAllButtons ) ;
181
183
182
184
// if clicked index is same as dropped index => fold
183
185
// otherwise => drop buttons associated with header
@@ -429,3 +431,7 @@ function setItemPosition(item, menuOpts, posOpts) {
429
431
430
432
posOpts . y += menuOpts . height1 + posOpts . yPad ;
431
433
}
434
+
435
+ function removeAllButtons ( gButton ) {
436
+ gButton . selectAll ( 'g.' + constants . buttonClassName ) . remove ( ) ;
437
+ }
0 commit comments