Skip to content

Commit da11362

Browse files
authored
Merge pull request #161 from mwang87/map-priority-fix
Map Priority Fix for Synchronization
2 parents 714c4b5 + ad7940c commit da11362

File tree

2 files changed

+72
-60
lines changed

2 files changed

+72
-60
lines changed

app.py

Lines changed: 47 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1240,7 +1240,7 @@
12401240
),
12411241
html.Div("", id="synchronization_type_dependency", style={"display":"none"}), # This is a hack to pass on a retrigger without causing infinite loops in the dependency chain
12421242
html.Div("", id="page_parameters", style={"display":"none"}), # This is an intermediate dependency to hold the parameters so we make it easier to update them
1243-
html.Div("", id="auto_import_parameters", style={"display":"none"}),
1243+
html.Div("", id="auto_import_parameters", style={"display":"none"}), # This is a hidden area to set parameters to be loaded into the interface
12441244

12451245
dbc.Row([
12461246
dbc.Col(
@@ -1979,6 +1979,7 @@ def update_usi(search, url_hash, filecontent_list, sychronization_load_session_b
19791979

19801980
return [usi, usi2, "Using URL USI", dash.no_update]
19811981

1982+
19821983

19831984
# Calculating which xic value to use
19841985
@app.callback(Output('xic_mz', 'value'),
@@ -2715,46 +2716,56 @@ def determine_plot_zoom_bounds(url_search, usi,
27152716
map_plot_rt_min, map_plot_rt_max, map_plot_mz_min, map_plot_mz_max, existing_map_plot_zoom,
27162717
sychronization_session_id, setting_json_area):
27172718

2719+
2720+
print("ALL TRIGGERS", [p['prop_id'] for p in dash.callback_context.triggered], file=sys.stderr, flush=True)
2721+
27182722
triggered_id = [p['prop_id'] for p in dash.callback_context.triggered][0]
27192723

27202724
usi_list = usi.split("\n")
2721-
remote_link, local_filename = _resolve_usi(usi_list[0])
2725+
remote_link, local_filename = _resolve_usi(usi_list[0])
27222726

2723-
# Figuring out the map plot selection
2724-
if "map_plot_update_range_button" in triggered_id:
2725-
# We clicked the button, so we should read the values out of the
2726-
current_map_selection, highlight_box, min_rt, max_rt, min_mz, max_mz = _resolve_map_plot_selection(url_search,
2727-
usi,
2728-
local_filename,
2729-
ui_map_selection=map_selection,
2730-
map_plot_rt_min=map_plot_rt_min,
2731-
map_plot_rt_max=map_plot_rt_max,
2732-
map_plot_mz_min=map_plot_mz_min,
2733-
map_plot_mz_max=map_plot_mz_max)
2734-
else:
2735-
session_dict = {}
2727+
session_dict = {}
27362728

2737-
if "sychronization_load_session_button" in triggered_id or "sychronization_interval" in triggered_id:
2738-
try:
2739-
session_dict = _sychronize_load_state(sychronization_session_id, redis_client)
2740-
except:
2741-
pass
2742-
2743-
# We clicked the button so we are going to load from the text area
2744-
if "advanced_import_update_button" in triggered_id:
2745-
try:
2746-
session_dict = json.loads(setting_json_area)
2747-
except:
2748-
pass
2729+
if "sychronization_load_session_button" in triggered_id or "sychronization_interval" in triggered_id:
2730+
try:
2731+
session_dict = _sychronize_load_state(sychronization_session_id, redis_client)
2732+
except:
2733+
pass
2734+
2735+
# We clicked the button so we are going to load from the text area
2736+
if "advanced_import_update_button" in triggered_id:
2737+
try:
2738+
session_dict = json.loads(setting_json_area)
2739+
except:
2740+
pass
27492741

2750-
if "auto_import_parameters" in triggered_id:
2751-
try:
2752-
session_dict = json.loads(auto_import_parameters)
2753-
except:
2754-
pass
2742+
if "auto_import_parameters" in triggered_id:
2743+
try:
2744+
session_dict = json.loads(auto_import_parameters)
2745+
except:
2746+
pass
2747+
2748+
priority = "url"
27552749

2756-
current_map_selection, highlight_box, min_rt, max_rt, min_mz, max_mz = _resolve_map_plot_selection(url_search, usi, local_filename, ui_map_selection=map_selection, session_dict=session_dict)
2750+
if "map-plot" in triggered_id:
2751+
priority = "ui"
27572752

2753+
if "map_plot_update_range_button" in triggered_id:
2754+
priority = "ui_update_range"
2755+
2756+
if "sychronization_load_session_button" in triggered_id or "sychronization_interval" in triggered_id or "advanced_import_update_button" in triggered_id or "auto_import_parameters" in triggered_id:
2757+
priority = "session"
2758+
2759+
current_map_selection, highlight_box, min_rt, max_rt, min_mz, max_mz = _resolve_map_plot_selection(url_search,
2760+
usi,
2761+
local_filename,
2762+
ui_map_selection=map_selection,
2763+
map_plot_rt_min=map_plot_rt_min,
2764+
map_plot_rt_max=map_plot_rt_max,
2765+
map_plot_mz_min=map_plot_mz_min,
2766+
map_plot_mz_max=map_plot_mz_max,
2767+
session_dict=session_dict,
2768+
priority=priority)
27582769

27592770
current_map_plot_zoom_string = json.dumps(current_map_selection)
27602771

@@ -2767,9 +2778,9 @@ def determine_plot_zoom_bounds(url_search, usi,
27672778
except:
27682779
pass
27692780

2770-
print("MAP SELECTION", map_selection, file=sys.stderr)
2771-
print("NEW SELECTION", current_map_selection, highlight_box, file=sys.stderr)
2772-
print("EXISTING PLOT ZOOM", existing_map_plot_zoom, file=sys.stderr)
2781+
print("MAP SELECTION", map_selection, file=sys.stderr, flush=True)
2782+
print("NEW SELECTION", current_map_selection, highlight_box, file=sys.stderr, flush=True)
2783+
print("EXISTING PLOT ZOOM", existing_map_plot_zoom, file=sys.stderr, flush=True)
27732784

27742785
return [current_map_plot_zoom_string, highlight_box_string, min_rt, max_rt, min_mz, max_mz]
27752786

utils.py

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ def _resolve_map_plot_selection(url_search, usi, local_filename,
119119
map_plot_rt_max="",
120120
map_plot_mz_min="",
121121
map_plot_mz_max="",
122-
session_dict={}):
122+
session_dict={},
123+
priority="url"):
123124
"""
124125
This resolves the map plot selection, given url
125126
@@ -135,12 +136,15 @@ def _resolve_map_plot_selection(url_search, usi, local_filename,
135136
[type]: [description]
136137
"""
137138

138-
current_map_selection = {}
139+
system_map_selection = {}
140+
manual_map_selection = {}
141+
142+
139143
highlight_box = None
140144

141145
# Lets start off with taking the url bounds
142146
try:
143-
current_map_selection = json.loads(_get_param_from_url(url_search, "", "map_plot_zoom", "{}", session_dict=session_dict))
147+
system_map_selection = json.loads(_get_param_from_url(url_search, "", "map_plot_zoom", "{}", session_dict=session_dict))
144148
except:
145149
pass
146150

@@ -168,11 +172,11 @@ def _resolve_map_plot_selection(url_search, usi, local_filename,
168172
max_mz = mz + 3
169173

170174
# If this is already set in the URL, we don't overwrite
171-
if len(current_map_selection) == 0 or "autosize" in current_map_selection:
172-
current_map_selection["xaxis.range[0]"] = min_rt
173-
current_map_selection["xaxis.range[1]"] = max_rt
174-
current_map_selection["yaxis.range[0]"] = min_mz
175-
current_map_selection["yaxis.range[1]"] = max_mz
175+
if len(system_map_selection) == 0 or "autosize" in system_map_selection:
176+
system_map_selection["xaxis.range[0]"] = min_rt
177+
system_map_selection["xaxis.range[1]"] = max_rt
178+
system_map_selection["yaxis.range[0]"] = min_mz
179+
system_map_selection["yaxis.range[1]"] = max_mz
176180

177181
highlight_box = {}
178182
highlight_box["left"] = rt - 0.01
@@ -182,48 +186,45 @@ def _resolve_map_plot_selection(url_search, usi, local_filename,
182186
except:
183187
pass
184188

185-
# We have to do a bit of convoluted object, if {'autosize': True}, that means loading from the URL
186-
try:
187-
# Force an override if user input is detected in map_selection
188-
if "xaxis.autorange" in ui_map_selection:
189-
current_map_selection = ui_map_selection
190-
if "xaxis.range[0]" in ui_map_selection:
191-
current_map_selection = ui_map_selection
192-
if "autosize" in ui_map_selection:
193-
pass
194-
except:
195-
pass
196-
197189
# If the entries are set, then we will override the UI map selection
198190
try:
199191
min_rt = float(map_plot_rt_min)
200192
# Check if the values one by one, are not default
201193
if min_rt > 0:
202-
current_map_selection["xaxis.range[0]"] = min_rt
194+
manual_map_selection["xaxis.range[0]"] = min_rt
203195
except:
204196
pass
205197
try:
206198
max_rt = float(map_plot_rt_max)
207199
# Check if the values one by one, are not default
208200
if max_rt < 1000000:
209-
current_map_selection["xaxis.range[1]"] = max_rt
201+
manual_map_selection["xaxis.range[1]"] = max_rt
210202
except:
211203
pass
212204
try:
213205
min_mz = float(map_plot_mz_min)
214206
# Check if the values one by one, are not default
215207
if min_mz > 0:
216-
current_map_selection["yaxis.range[0]"] = min_mz
208+
manual_map_selection["yaxis.range[0]"] = min_mz
217209
except:
218210
pass
219211
try:
220212
max_mz = float(map_plot_mz_max)
221213
# Check if the values one by one, are not default
222214
if max_mz < 1000000:
223-
current_map_selection["yaxis.range[1]"] = max_mz
215+
manual_map_selection["yaxis.range[1]"] = max_mz
224216
except:
225217
pass
226218

219+
current_map_selection = system_map_selection
220+
221+
if priority == "ui":
222+
current_map_selection = ui_map_selection
223+
if priority == "ui_update_range":
224+
current_map_selection = manual_map_selection
225+
if priority == "session":
226+
current_map_selection = system_map_selection
227+
227228
# Getting values for rt and mz
228229
try:
229230
min_rt = current_map_selection.get("xaxis.range[0]", 0)

0 commit comments

Comments
 (0)