From 6d5e17822dd6d094f7eb8c96c8ae6517b4a97846 Mon Sep 17 00:00:00 2001 From: hh_itx_win10 Date: Thu, 11 Apr 2024 12:59:54 -0700 Subject: [PATCH 1/3] feat: add form to draw session --- code/Home.py | 92 ++++++++++++++++++++++++++++------------------------ 1 file changed, 49 insertions(+), 43 deletions(-) diff --git a/code/Home.py b/code/Home.py index 9d1e1f0..266041a 100644 --- a/code/Home.py +++ b/code/Home.py @@ -186,49 +186,55 @@ def draw_session_plots(df_to_draw_session): def session_plot_settings(need_click=True): - st.markdown('##### Show plots for individual sessions ') - cols = st.columns([2, 1, 6]) - - session_plot_modes = [f'sessions selected from table or plot', f'all sessions filtered from sidebar'] - st.session_state.selected_draw_sessions = cols[0].selectbox(f'Which session(s) to draw?', - session_plot_modes, - index=session_plot_modes.index(st.session_state['session_plot_mode']) - if 'session_plot_mode' in st.session_state else - session_plot_modes.index(st.query_params['session_plot_mode']) - if 'session_plot_mode' in st.query_params - else 0, - key='session_plot_mode', - ) - - n_session_to_draw = len(st.session_state.df_selected_from_plotly) \ - if 'selected from table or plot' in st.session_state.selected_draw_sessions \ - else len(st.session_state.df_session_filtered) - cols[0].markdown(f'{n_session_to_draw} sessions to draw') - - st.session_state.num_cols = cols[1].number_input('number of columns', 1, 10, - 3 if 'num_cols' not in st.session_state else st.session_state.num_cols) - - st.markdown( - """ - """, - unsafe_allow_html=True, - ) - st.session_state.selected_draw_types = cols[2].multiselect('Which plot(s) to draw?', - st.session_state.draw_type_mapper_session_level.keys(), - default=st.session_state.draw_type_mapper_session_level.keys() - if 'selected_draw_types' not in st.session_state else - st.session_state.selected_draw_types) - if need_click: - draw_it = st.button(f'Show me all {n_session_to_draw} sessions!', use_container_width=True, type="primary") - draw_it_now_override = cols[1].checkbox('Auto draw') - else: - draw_it = True - draw_it_now_override = True - return draw_it | draw_it_now_override + with st.form(key='session_plot_settings'): + st.markdown('##### Show plots for individual sessions ') + cols = st.columns([2, 6, 1]) + + session_plot_modes = [f'sessions selected from table or plot', f'all sessions filtered from sidebar'] + st.session_state.selected_draw_sessions = cols[0].selectbox(f'Which session(s) to draw?', + session_plot_modes, + index=session_plot_modes.index(st.session_state['session_plot_mode']) + if 'session_plot_mode' in st.session_state else + session_plot_modes.index(st.query_params['session_plot_mode']) + if 'session_plot_mode' in st.query_params + else 0, + key='session_plot_mode', + ) + + n_session_to_draw = len(st.session_state.df_selected_from_plotly) \ + if 'selected from table or plot' in st.session_state.selected_draw_sessions \ + else len(st.session_state.df_session_filtered) + + st.session_state.num_cols = cols[2].number_input('number of columns', 1, 10, + 3 if 'num_cols' not in st.session_state else st.session_state.num_cols) + + st.markdown( + """ + """, + unsafe_allow_html=True, + ) + st.session_state.selected_draw_types = cols[1].multiselect('Which plot(s) to draw?', + st.session_state.draw_type_mapper_session_level.keys(), + default=st.session_state.draw_type_mapper_session_level.keys() + if 'selected_draw_types' not in st.session_state else + st.session_state.selected_draw_types) + cols[0].markdown(f'{n_session_to_draw} sessions to draw') + draw_it_now_override = cols[2].checkbox('Auto show', value=not need_click, disabled=not need_click) + submitted = cols[0].form_submit_button("Update settings", type='primary') + + + if not need_click: + return True + + if draw_it_now_override: + return True + + draw_it = st.button(f'Show {n_session_to_draw} sessions!', use_container_width=False, type="primary") + return draw_it def plot_x_y_session(): From de23a07d3635b702bc34800a205e59ed930fdd79 Mon Sep 17 00:00:00 2001 From: hh_itx_win10 Date: Thu, 11 Apr 2024 13:04:33 -0700 Subject: [PATCH 2/3] feat: add form to x-y settings --- code/Home.py | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/code/Home.py b/code/Home.py index 266041a..91babf7 100644 --- a/code/Home.py +++ b/code/Home.py @@ -238,24 +238,27 @@ def session_plot_settings(need_click=True): def plot_x_y_session(): + with st.expander("X-Y plot settings", expanded=True): + with st.form(key='x_y_plot_settings', border=False): + cols = st.columns([1, 1, 1]) - cols = st.columns([1, 1, 1]) - - with cols[0]: - x_name, y_name, group_by = add_xy_selector(if_bonsai=True) + with cols[0]: + x_name, y_name, group_by = add_xy_selector(if_bonsai=True) - with cols[1]: - (if_show_dots, if_aggr_each_group, aggr_method_group, if_use_x_quantile_group, q_quantiles_group, - if_aggr_all, aggr_method_all, if_use_x_quantile_all, q_quantiles_all, smooth_factor, if_show_diagonal, - dot_size, dot_opacity, line_width, x_y_plot_figure_width, x_y_plot_figure_height, - font_size_scale, color_map) = add_xy_setting() - - if st.session_state.x_y_plot_if_show_dots: - with cols[2]: - size_mapper, size_mapper_range, size_mapper_gamma = add_dot_property_mapper() - else: - size_mapper = 'None' - size_mapper_range, size_mapper_gamma = None, None + with cols[1]: + (if_show_dots, if_aggr_each_group, aggr_method_group, if_use_x_quantile_group, q_quantiles_group, + if_aggr_all, aggr_method_all, if_use_x_quantile_all, q_quantiles_all, smooth_factor, if_show_diagonal, + dot_size, dot_opacity, line_width, x_y_plot_figure_width, x_y_plot_figure_height, + font_size_scale, color_map) = add_xy_setting() + + if st.session_state.x_y_plot_if_show_dots: + with cols[2]: + size_mapper, size_mapper_range, size_mapper_gamma = add_dot_property_mapper() + else: + size_mapper = 'None' + size_mapper_range, size_mapper_gamma = None, None + + submitted = st.form_submit_button("👉 Update X-Y settings 👈", type='primary') # If no sessions are selected, use all filtered entries # df_x_y_session = st.session_state.df_selected_from_dataframe if if_plot_only_selected_from_dataframe else st.session_state.df_session_filtered From c9b63b3dd4e7fc053e6705a48ef3cc3ac109dff6 Mon Sep 17 00:00:00 2001 From: hh_itx_win10 Date: Thu, 11 Apr 2024 13:09:40 -0700 Subject: [PATCH 3/3] minor: change default size --- code/util/streamlit.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/code/util/streamlit.py b/code/util/streamlit.py index 8f51946..01d4afb 100644 --- a/code/util/streamlit.py +++ b/code/util/streamlit.py @@ -623,9 +623,9 @@ def add_dot_property_mapper(): size_mapper_range = slider_wrapper_for_url_query(cols[1], label="size range", min_value=0, - max_value=100, + max_value=50, key='x_y_plot_size_mapper_range', - default=(0, 50), + default=(0, 10), ) size_mapper_gamma = slider_wrapper_for_url_query(cols[2],