@@ -306,17 +306,20 @@ def download_state(self):
306306 "tools" : self .state .active_tools ,
307307 "help" : not self .state .compact_drawer ,
308308 }
309- state_content [ "data-selection" ] = {
309+ data_selection = {
310310 k : self .state [k ]
311311 for k in [
312- "time_idx" ,
313- "midpoint_idx" ,
314- "interface_idx" ,
315312 "crop_longitude" ,
316313 "crop_latitude" ,
317314 "projection" ,
318315 ]
319316 }
317+ # Save all dynamic dimension indices
318+ for dim_name in getattr (self .state , "available_animation_tracks" , None ) or []:
319+ idx_key = f"{ dim_name } _idx"
320+ data_selection [idx_key ] = getattr (self .state , idx_key , 0 )
321+ data_selection ["animation_track" ] = self .state .animation_track
322+ state_content ["data-selection" ] = data_selection
320323 views_to_export = state_content ["views" ] = []
321324 for view_type , var_names in active_variables .items ():
322325 for var_name in var_names :
@@ -329,7 +332,10 @@ def download_state(self):
329332 # lut
330333 "preset" : config .preset ,
331334 "invert" : config .invert ,
335+ "color_blind" : config .color_blind ,
332336 "use_log_scale" : config .use_log_scale ,
337+ "discrete_log" : config .discrete_log ,
338+ "n_discrete_colors" : config .n_discrete_colors ,
333339 # layout
334340 "order" : config .order ,
335341 "size" : config .size ,
@@ -370,16 +376,34 @@ async def _import_state(self, state_content):
370376
371377 # Load variables
372378 self .state .variables_selected = state_content ["variables-selection" ]
373- self .state .update (state_content ["data-selection" ])
379+ # Apply non-index data-selection fields (crop, projection) before load
380+ data_sel = state_content ["data-selection" ]
381+ non_idx = {
382+ k : v
383+ for k , v in data_sel .items ()
384+ if not k .endswith ("_idx" ) and k != "animation_track"
385+ }
386+ self .state .update (non_idx )
374387 await self ._data_load_variables ()
375388 self .state .variables_loaded = True
376389
390+ # Restore dimension indices after data is loaded
391+ with self .state :
392+ for k , v in data_sel .items ():
393+ if k .endswith ("_idx" ):
394+ self .state [k ] = v
395+ if "animation_track" in data_sel :
396+ self .state .animation_track = data_sel ["animation_track" ]
397+
377398 # Update view states
378399 for view_state in state_content ["views" ]:
379400 view_type = view_state ["type" ]
380401 var_name = view_state ["name" ]
402+ cfg = view_state ["config" ]
403+ if "color_range" in cfg and isinstance (cfg ["color_range" ], list ):
404+ cfg ["color_range" ] = tuple (cfg ["color_range" ])
381405 config = self .view_manager .get_view (var_name , view_type ).config
382- config .update (** view_state [ "config" ] )
406+ config .update (** cfg )
383407
384408 # Update layout
385409 self .state .aspect_ratio = state_content ["layout" ]["aspect-ratio" ]
0 commit comments