@@ -30,7 +30,14 @@ def toggle_tables(switch_value):
3030 return get_n_switch_values (not switch_value , 3 )
3131
3232 @staticmethod
33- def handle_model_change (i , sidebar_data ):
33+ def change_btn_color (n_clicks ):
34+ try :
35+ return [False ] if n_clicks % 2 == 0 else [True ]
36+ except :
37+ return [False ]
38+
39+ @staticmethod
40+ def handle_model_change (i , sidebar_data , lock_zoom_clicks , graphs_relayout_data ):
3441 model = {}
3542 pars = None
3643 result = []
@@ -44,7 +51,6 @@ def handle_model_change(i, sidebar_data):
4451 viz_kwargs = dict (
4552 labels = pars .labels ,
4653 table_mod = 7 ,
47- max_y_axis = pars .max_y_axis ,
4854 content = vis_content
4955 )
5056 result .extend (i .components ["intro" ].build (model , pars ))
@@ -53,11 +59,42 @@ def handle_model_change(i, sidebar_data):
5359 if model :
5460 df = model .__dict__ .get (df_key , None )
5561 result .extend (prepare_visualization_group (df , ** viz_kwargs ))
62+
63+ figures = [result [1 ], result [4 ], result [7 ]]
64+
65+ for n_clicks , relayout_data , figure in zip (lock_zoom_clicks , graphs_relayout_data , figures ):
66+ if relayout_data :
67+ if n_clicks == None or n_clicks % 2 == 0 :
68+ # Set plot_data figure coordinates
69+ if "xaxis.range[0]" in relayout_data :
70+ figure ["layout" ]["xaxis" ]["range" ] = [
71+ relayout_data ["xaxis.range[0]" ],
72+ relayout_data ["xaxis.range[1]" ]
73+ ]
74+ if "yaxis.range[0]" in relayout_data :
75+ figure ["layout" ]["yaxis" ]["range" ] = [
76+ relayout_data ["yaxis.range[0]" ],
77+ relayout_data ["yaxis.range[1]" ]
78+ ]
79+
5680 return result
5781
5882 def __init__ (self , component_instance ):
59- def handle_model_change_helper (sidebar_mod , sidebar_data ):
60- return IndexCallbacks .handle_model_change (component_instance , sidebar_data )
83+ def handle_model_change_helper (
84+ sidebar_mod ,
85+ new_admissions_lock_zoom ,
86+ admitted_patients_lock_zoom ,
87+ SIR_lock_zoom ,
88+ sidebar_data ,
89+ new_admissions_relayout_data ,
90+ admitted_patients_relayout_data ,
91+ SIR_relayout_data
92+ ):
93+ # parameter order: Inputs (sidebar_mod and all lock_zooms) followed by States (sidebar_data and all relayout_datas)
94+ # Order matters; callback_wrapper passes in Inputs before States
95+ lock_zoom_clicks = [new_admissions_lock_zoom , admitted_patients_lock_zoom , SIR_lock_zoom ]
96+ graphs_relayout_data = [new_admissions_relayout_data , admitted_patients_relayout_data , SIR_relayout_data ]
97+ return IndexCallbacks .handle_model_change (component_instance , sidebar_data , lock_zoom_clicks , graphs_relayout_data )
6198
6299 super ().__init__ (
63100 component_instance = component_instance ,
@@ -72,7 +109,12 @@ def handle_model_change_helper(sidebar_mod, sidebar_data):
72109 callback_fn = IndexCallbacks .toggle_tables
73110 ),
74111 ChimeCallback ( # If the parameters or model change, update the text
75- changed_elements = {"sidebar-store" : "modified_timestamp" },
112+ changed_elements = {
113+ "sidebar-store" : "modified_timestamp" ,
114+ "new_admissions_lock_zoom" : "n_clicks" ,
115+ "admitted_patients_lock_zoom" : "n_clicks" ,
116+ "SIR_lock_zoom" : "n_clicks"
117+ },
76118 dom_updates = {
77119 "intro" : "children" ,
78120 "new_admissions_graph" : "figure" ,
@@ -85,8 +127,28 @@ def handle_model_change_helper(sidebar_mod, sidebar_data):
85127 "SIR_table" : "children" ,
86128 "SIR_download" : "href" ,
87129 },
88- callback_fn = handle_model_change_helper ,
130+ states = {
131+ "new_admissions_graph" : "relayoutData" ,
132+ "admitted_patients_graph" : "relayoutData" ,
133+ "SIR_graph" : "relayoutData"
134+ },
89135 stores = ["sidebar-store" ],
136+ callback_fn = handle_model_change_helper
137+ ),
138+ ChimeCallback ( # If user presses the Lock Zoom Button, update outline / solid color
139+ changed_elements = {"new_admissions_lock_zoom" : "n_clicks" },
140+ dom_updates = {"new_admissions_lock_zoom" : "outline" },
141+ callback_fn = IndexCallbacks .change_btn_color
142+ ),
143+ ChimeCallback (
144+ changed_elements = {"admitted_patients_lock_zoom" : "n_clicks" },
145+ dom_updates = {"admitted_patients_lock_zoom" : "outline" },
146+ callback_fn = IndexCallbacks .change_btn_color
147+ ),
148+ ChimeCallback (
149+ changed_elements = {"SIR_lock_zoom" : "n_clicks" },
150+ dom_updates = {"SIR_lock_zoom" : "outline" },
151+ callback_fn = IndexCallbacks .change_btn_color
90152 )
91153 ]
92154 )
@@ -136,8 +198,7 @@ def update_parameters(i, *input_values) -> List[dict]:
136198 ventilated = Disposition .create (
137199 days = inputs_dict ["ventilated_los" ],
138200 rate = inputs_dict ["ventilated_rate" ] / 100 ,
139- ),
140- max_y_axis = inputs_dict .get ("max_y_axis_value" , None ),
201+ )
141202 )
142203 return [{"inputs_dict" : inputs_dict , "parameters" : parameters_serializer (pars )}]
143204
0 commit comments