1- from typing import Dict , List , Optional , Tuple , Union
1+ import datetime
2+ from typing import Any , Dict , List , Optional , Tuple , Union
23
34import plotly .graph_objects as go
45from dash import ALL , Input , Output , State , callback , ctx
@@ -284,6 +285,18 @@ def _update_vector_store(vector: list) -> str:
284285 ),
285286 "value" ,
286287 ),
288+ Output (
289+ self .settings_group_unique_id (
290+ self .Ids .SELECTIONS , Selections .Ids .DATE_SLIDER
291+ ),
292+ "max" ,
293+ ),
294+ Output (
295+ self .settings_group_unique_id (
296+ self .Ids .SELECTIONS , Selections .Ids .DATE_SLIDER
297+ ),
298+ "marks" ,
299+ ),
287300 Input (
288301 self .settings_group_unique_id (
289302 self .Ids .SELECTIONS , Selections .Ids .ENSEMBLE
@@ -307,7 +320,7 @@ def _update_date(
307320 ensemble : str ,
308321 timeseries_clickdata : Union [None , dict ],
309322 dateidx : int ,
310- ) -> Tuple [str , str , int ]:
323+ ) -> Tuple [str , str , int , int , Dict [ int , Dict [ str , Any ]] ]:
311324 """Store selected date and tornado input. Write statistics
312325 to table"""
313326
@@ -332,6 +345,9 @@ def _update_date(
332345 date_selected = date_from_str (
333346 timeseries_clickdata .get ("points" , [{}])[0 ]["x" ]
334347 )
348+ if date_selected not in dates :
349+ date_selected = get_closest_date (dates , date_selected )
350+
335351 elif dateslider_drag :
336352 date_selected = dates [dateidx ]
337353 else :
@@ -341,6 +357,14 @@ def _update_date(
341357 date_to_str (date_selected ),
342358 date_to_str (date_selected ),
343359 dates .index (date_selected ),
360+ len (dates ) - 1 ,
361+ {
362+ idx : {
363+ "label" : date_to_str (dates [idx ]),
364+ "style" : {"white-space" : "nowrap" },
365+ }
366+ for idx in [0 , len (dates ) - 1 ]
367+ },
344368 )
345369
346370 @callback (
@@ -399,7 +423,7 @@ def _update_timeseries_figure(
399423 ensemble
400424 ),
401425 )
402- if linetype == LineType .MEAN :
426+ if linetype == LineType .STATISTICS :
403427 data = self ._data_model .create_vectors_statistics_df (data )
404428
405429 return self ._data_model .create_timeseries_figure (
@@ -577,3 +601,10 @@ def _display_table_or_realplot(selected_vizualisation: str) -> tuple:
577601 return {
578602 "display" : "none" if selected_vizualisation == "table" else "block"
579603 }, {"display" : "block" if selected_vizualisation == "table" else "none" }
604+
605+
606+ def get_closest_date (
607+ dates : List [datetime .datetime ], date : datetime .datetime
608+ ) -> datetime .datetime :
609+ # Returns the closest date to the input date in the dates list.
610+ return min (dates , key = lambda dte : abs (dte - date ))
0 commit comments