Skip to content

Commit

Permalink
Fix bug: on click to plot data, it goes to infinite loop if the same …
Browse files Browse the repository at this point in the history
…dot is clicked
  • Loading branch information
gurayerus committed Dec 18, 2024
1 parent fe26bcf commit 6f42c8f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
Binary file added src/viewer/utils/.utils_plot.py.kate-swp
Binary file not shown.
42 changes: 21 additions & 21 deletions src/viewer/utils/utils_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,27 @@ def callback_plot_clicked() -> None:
Set the active plot id to plot that was clicked
"""
st.session_state.plot_active = plot_id
# st.rerun()

# Detect MRID from the click info and save to session_state
hind = get_index_in_list(df.columns.tolist(), curr_plot["hvar"])

sel_info = st.session_state[f'bubble_chart_{plot_id}']
if len(sel_info["selection"]["points"]) > 0:
sind = sel_info["selection"]["point_indices"][0]
if hind is None:
sel_mrid = df_filt.iloc[sind]["MRID"]
else:
lgroup = sel_info["selection"]["points"][0]["legendgroup"]
sel_mrid = df_filt[df_filt[curr_plot["hvar"]] == lgroup].iloc[sind][
"MRID"
]
sel_roi = st.session_state.plots.loc[st.session_state.plot_active, "yvar"]
st.session_state.sel_mrid = sel_mrid
st.session_state.sel_roi = sel_roi
st.session_state.sel_roi_img = sel_roi
st.session_state.paths["sel_img"] = ""
st.session_state.paths["sel_seg"] = ""
st.rerun()

# Main container for the plot
with st.container(border=True):
Expand Down Expand Up @@ -550,28 +570,8 @@ def callback_plot_clicked() -> None:
fig, key=f"bubble_chart_{plot_id}", on_select=callback_plot_clicked
)

# Detect MRID from the click info and save to session_state
hind = get_index_in_list(df.columns.tolist(), curr_plot["hvar"])
if len(sel_info["selection"]["points"]) > 0:
sind = sel_info["selection"]["point_indices"][0]
if hind is None:
sel_mrid = df_filt.iloc[sind]["MRID"]
else:
lgroup = sel_info["selection"]["points"][0]["legendgroup"]
sel_mrid = df_filt[df_filt[curr_plot["hvar"]] == lgroup].iloc[sind][
"MRID"
]
sel_roi = st.session_state.plots.loc[st.session_state.plot_active, "yvar"]
st.session_state.sel_mrid = sel_mrid
st.session_state.sel_roi = sel_roi
st.session_state.sel_roi_img = sel_roi
st.session_state.paths["sel_img"] = ""
st.session_state.paths["sel_seg"] = ""
st.rerun()

return fig


def display_dist_plot(
df: pd.DataFrame, plot_id: str, show_settings: bool, sel_mrid: str
) -> Any:
Expand Down

0 comments on commit 6f42c8f

Please sign in to comment.