File tree Expand file tree Collapse file tree 3 files changed +32
-9
lines changed Expand file tree Collapse file tree 3 files changed +32
-9
lines changed Original file line number Diff line number Diff line change @@ -26,7 +26,13 @@ module.exports = function updateMenusDefaults(layoutIn, layoutOut) {
2626 menuOut = { } ;
2727
2828 menuDefaults ( menuIn , menuOut , layoutOut ) ;
29+
30+ // used on button click to update the 'active' field
2931 menuOut . _input = menuIn ;
32+
33+ // used to determine object constancy
34+ menuOut . _index = i ;
35+
3036 contOut . push ( menuOut ) ;
3137 }
3238} ;
Original file line number Diff line number Diff line change @@ -125,28 +125,24 @@ module.exports = function draw(gd) {
125125
126126function makeMenuData ( fullLayout ) {
127127 var contOpts = fullLayout [ constants . name ] ,
128- menuData = [ ] ,
129- cnt = 0 ;
128+ menuData = [ ] ;
130129
131130 // Filter visible dropdowns and attach '_index' to each
132131 // fullLayout options object to be used for 'object constancy'
133132 // in the data join key function.
134- //
135- // Note that '_index' is relinked from update to update via
136- // Plots.supplyDefaults.
137133
138134 for ( var i = 0 ; i < contOpts . length ; i ++ ) {
139135 var item = contOpts [ i ] ;
140136
141- if ( item . visible ) {
142- if ( ! item . _index ) item . _index = cnt ++ ;
143- menuData . push ( item ) ;
144- }
137+ if ( item . visible ) menuData . push ( item ) ;
145138 }
146139
147140 return menuData ;
148141}
149142
143+ // Note that '_index' is set at the default step,
144+ // it corresponds to the menu index in the user layout update menu container.
145+ // This is a more 'consistent' field than e.g. the index in the menuData.
150146function keyFunction ( opts ) {
151147 return opts . _index ;
152148}
Original file line number Diff line number Diff line change @@ -194,6 +194,27 @@ describe('update menus interactions', function() {
194194 expect ( gd . _fullLayout . _pushmargin [ 'updatemenu-0' ] ) . toBeUndefined ( ) ;
195195 expect ( gd . _fullLayout . _pushmargin [ 'updatemenu-1' ] ) . toBeUndefined ( ) ;
196196
197+ return Plotly . relayout ( gd , {
198+ 'updatemenus[2]' : {
199+ buttons : [ {
200+ method : 'relayout' ,
201+ args : [ 'title' , 'new title' ]
202+ } ]
203+ }
204+ } ) ;
205+ } ) . then ( function ( ) {
206+ assertMenus ( [ 0 ] ) ;
207+ expect ( gd . _fullLayout . _pushmargin [ 'updatemenu-0' ] ) . toBeUndefined ( ) ;
208+ expect ( gd . _fullLayout . _pushmargin [ 'updatemenu-1' ] ) . toBeUndefined ( ) ;
209+ expect ( gd . _fullLayout . _pushmargin [ 'updatemenu-2' ] ) . toBeDefined ( ) ;
210+
211+ return Plotly . relayout ( gd , 'updatemenus[0].visible' , true ) ;
212+ } ) . then ( function ( ) {
213+ assertMenus ( [ 0 , 0 ] ) ;
214+ expect ( gd . _fullLayout . _pushmargin [ 'updatemenu-0' ] ) . toBeDefined ( ) ;
215+ expect ( gd . _fullLayout . _pushmargin [ 'updatemenu-1' ] ) . toBeUndefined ( ) ;
216+ expect ( gd . _fullLayout . _pushmargin [ 'updatemenu-2' ] ) . toBeDefined ( ) ;
217+
197218 done ( ) ;
198219 } ) ;
199220 } ) ;
You can’t perform that action at this time.
0 commit comments