File tree Expand file tree Collapse file tree 2 files changed +17
-9
lines changed Expand file tree Collapse file tree 2 files changed +17
-9
lines changed Original file line number Diff line number Diff line change @@ -108,9 +108,6 @@ module.exports = function draw(gd) {
108108 // find dimensions before plotting anything (this mutates menuOpts)
109109 for ( var i = 0 ; i < menuData . length ; i ++ ) {
110110 var menuOpts = menuData [ i ] ;
111-
112- // often more convenient than playing with two arguments
113- menuOpts . _index = i ;
114111 findDimenstions ( gd , menuOpts ) ;
115112 }
116113
@@ -128,19 +125,30 @@ module.exports = function draw(gd) {
128125
129126function makeMenuData ( fullLayout ) {
130127 var contOpts = fullLayout [ constants . name ] ,
131- menuData = [ ] ;
128+ menuData = [ ] ,
129+ cnt = 0 ;
130+
131+ // Filter visible dropdowns and attach '_index' to each
132+ // fullLayout options object to be used for 'object constancy'
133+ // in the data join key function.
134+ //
135+ // Note that '_index' is relinked from update to update via
136+ // Plots.supplyDefaults.
132137
133138 for ( var i = 0 ; i < contOpts . length ; i ++ ) {
134139 var item = contOpts [ i ] ;
135140
136- if ( item . visible ) menuData . push ( item ) ;
141+ if ( item . visible ) {
142+ if ( ! item . _index ) item . _index = cnt ++ ;
143+ menuData . push ( item ) ;
144+ }
137145 }
138146
139147 return menuData ;
140148}
141149
142- function keyFunction ( opts , i ) {
143- return opts . visible + i ;
150+ function keyFunction ( opts ) {
151+ return opts . _index ;
144152}
145153
146154function areMenuButtonsDropped ( gButton , menuOpts ) {
Original file line number Diff line number Diff line change @@ -167,8 +167,8 @@ describe('update menus interactions', function() {
167167
168168 Plotly . relayout ( gd , 'updatemenus[0].visible' , false ) . then ( function ( ) {
169169 assertMenus ( [ 0 ] ) ;
170- expect ( gd . _fullLayout . _pushmargin [ 'updatemenu-0' ] ) . toBeDefined ( ) ;
171- expect ( gd . _fullLayout . _pushmargin [ 'updatemenu-1' ] ) . toBeUndefined ( ) ;
170+ expect ( gd . _fullLayout . _pushmargin [ 'updatemenu-0' ] ) . toBeUndefined ( ) ;
171+ expect ( gd . _fullLayout . _pushmargin [ 'updatemenu-1' ] ) . toBeDefined ( ) ;
172172
173173 return Plotly . relayout ( gd , 'updatemenus[1]' , null ) ;
174174 } ) . then ( function ( ) {
You can’t perform that action at this time.
0 commit comments