File tree 3 files changed +32
-9
lines changed
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) {
26
26
menuOut = { } ;
27
27
28
28
menuDefaults ( menuIn , menuOut , layoutOut ) ;
29
+
30
+ // used on button click to update the 'active' field
29
31
menuOut . _input = menuIn ;
32
+
33
+ // used to determine object constancy
34
+ menuOut . _index = i ;
35
+
30
36
contOut . push ( menuOut ) ;
31
37
}
32
38
} ;
Original file line number Diff line number Diff line change @@ -125,28 +125,24 @@ module.exports = function draw(gd) {
125
125
126
126
function makeMenuData ( fullLayout ) {
127
127
var contOpts = fullLayout [ constants . name ] ,
128
- menuData = [ ] ,
129
- cnt = 0 ;
128
+ menuData = [ ] ;
130
129
131
130
// Filter visible dropdowns and attach '_index' to each
132
131
// fullLayout options object to be used for 'object constancy'
133
132
// in the data join key function.
134
- //
135
- // Note that '_index' is relinked from update to update via
136
- // Plots.supplyDefaults.
137
133
138
134
for ( var i = 0 ; i < contOpts . length ; i ++ ) {
139
135
var item = contOpts [ i ] ;
140
136
141
- if ( item . visible ) {
142
- if ( ! item . _index ) item . _index = cnt ++ ;
143
- menuData . push ( item ) ;
144
- }
137
+ if ( item . visible ) menuData . push ( item ) ;
145
138
}
146
139
147
140
return menuData ;
148
141
}
149
142
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.
150
146
function keyFunction ( opts ) {
151
147
return opts . _index ;
152
148
}
Original file line number Diff line number Diff line change @@ -194,6 +194,27 @@ describe('update menus interactions', function() {
194
194
expect ( gd . _fullLayout . _pushmargin [ 'updatemenu-0' ] ) . toBeUndefined ( ) ;
195
195
expect ( gd . _fullLayout . _pushmargin [ 'updatemenu-1' ] ) . toBeUndefined ( ) ;
196
196
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
+
197
218
done ( ) ;
198
219
} ) ;
199
220
} ) ;
You can’t perform that action at this time.
0 commit comments