Skip to content

Commit

Permalink
hide on right 2d plot
Browse files Browse the repository at this point in the history
  • Loading branch information
rookiepeng committed Jul 14, 2024
1 parent eca6ea9 commit 99d765e
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 1 deletion.
1 change: 1 addition & 0 deletions app_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"task_id": "TASK_ID",
"filter_kwargs": "FILTGER_KWARGS",
"selected_data_left": "SELECTED_DATA_LEFT",
"selected_data_right": "SELECTED_DATA_RIGHT",
}
KEY_TYPES = {"CAT": "categorical", "NUM": "numerical"}

Expand Down
1 change: 1 addition & 0 deletions app_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -1306,6 +1306,7 @@ def get_app_layout():
dcc.Store(id="left-regenerate-trigger", data=0),
dcc.Store(id="right-regenerate-trigger", data=0),
dcc.Store(id="left-hide-trigger", data=0),
dcc.Store(id="right-hide-trigger", data=0),
dcc.Store(id="file-loaded-trigger", data=0),
dcc.Store(id="background-trigger", data=0),
dcc.Store(id="dummy-background"),
Expand Down
2 changes: 2 additions & 0 deletions view_callbacks/heatmap_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def get_heatmap_view_callbacks(app):
inputs={
"unused_filter_trigger": Input("filter-trigger", "data"),
"unused_left_hide_trigger": Input("left-hide-trigger", "data"),
"unused_right_hide_trigger": Input("right-hide-trigger", "data"),
"heat_sw": Input("heat-switch", "value"),
"x_heat": Input("x-picker-heatmap", "value"),
"y_heat": Input("y-picker-heatmap", "value"),
Expand All @@ -80,6 +81,7 @@ def get_heatmap_view_callbacks(app):
def regenerate_heatmap_callback(
unused_filter_trigger,
unused_left_hide_trigger,
unused_right_hide_trigger,
heat_sw,
x_heat,
y_heat,
Expand Down
2 changes: 2 additions & 0 deletions view_callbacks/histogram_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def get_histogram_view_callbacks(app):
inputs={
"unused_filter_trigger": Input("filter-trigger", "data"),
"unused_left_hide_trigger": Input("left-hide-trigger", "data"),
"unused_right_hide_trigger": Input("right-hide-trigger", "data"),
"histogram_sw": Input("histogram-switch", "value"),
"x_histogram": Input("x-picker-histogram", "value"),
"y_histogram": Input("y-histogram", "value"),
Expand All @@ -83,6 +84,7 @@ def get_histogram_view_callbacks(app):
def regenerate_histogram_callback(
unused_filter_trigger,
unused_left_hide_trigger,
unused_right_hide_trigger,
histogram_sw,
x_histogram,
y_histogram,
Expand Down
2 changes: 2 additions & 0 deletions view_callbacks/parcats_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def get_parcats_view_callbacks(app):
inputs={
"unused_filter_trigger": Input("filter-trigger", "data"),
"unused_left_hide_trigger": Input("left-hide-trigger", "data"),
"unused_right_hide_trigger": Input("right-hide-trigger", "data"),
"parallel_sw": Input("parallel-switch", "value"),
"dim_parallel": Input("dim-picker-parallel", "value"),
"c_key": Input("c-picker-parallel", "value"),
Expand All @@ -81,6 +82,7 @@ def get_parcats_view_callbacks(app):
def regenerate_parallel_callback(
unused_filter_trigger,
unused_left_hide_trigger,
unused_right_hide_trigger,
parallel_sw,
dim_parallel,
c_key,
Expand Down
2 changes: 2 additions & 0 deletions view_callbacks/scatter_2d_left_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ def invoke_scatter2d_left_frame_trigger(
inputs={
"unused_filter_trigger": Input("filter-trigger", "data"),
"unused_left_hide_trigger": Input("left-hide-trigger", "data"),
"unused_right_hide_trigger": Input("right-hide-trigger", "data"),
"unused_regenerate_trigger": Input("left-regenerate-trigger", "data"),
"left_sw": Input("left-switch", "value"),
"all_frame_sw": Input("scatter2dl-allframe-switch", "value"),
Expand All @@ -143,6 +144,7 @@ def invoke_scatter2d_left_frame_trigger(
def regenerate_scatter2d_left_callback(
unused_filter_trigger,
unused_left_hide_trigger,
unused_right_hide_trigger,
unused_regenerate_trigger,
left_sw,
x_left,
Expand Down
75 changes: 74 additions & 1 deletion view_callbacks/scatter_2d_right_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@

import datetime

import pandas as pd

import plotly.graph_objs as go

import dash
Expand All @@ -44,7 +46,7 @@
from app_config import CACHE_KEYS, KEY_TYPES

from utils import filter_all
from utils import cache_get
from utils import cache_get, cache_set
from utils import load_data


Expand Down Expand Up @@ -120,6 +122,7 @@ def invoke_scatter2d_right_frame_trigger(
inputs={
"unused_filter_trigger": Input("filter-trigger", "data"),
"unused_left_hide_trigger": Input("left-hide-trigger", "data"),
"unused_right_hide_trigger": Input("right-hide-trigger", "data"),
"unused_regenerate_trigger": Input("right-regenerate-trigger", "data"),
"right_sw": Input("right-switch", "value"),
"all_frame_sw": Input("scatter2dr-allframe-switch", "value"),
Expand All @@ -141,6 +144,7 @@ def invoke_scatter2d_right_frame_trigger(
def regenerate_scatter2d_right_callback(
unused_filter_trigger,
unused_left_hide_trigger,
unused_right_hide_trigger,
unused_regenerate_trigger,
right_sw,
x_right,
Expand Down Expand Up @@ -354,3 +358,72 @@ def export_right_2d_scatter(btn, fig):
temp_fig.write_image(file_name, scale=2)

return {"download": dcc.send_file(file_name)}

@app.callback(
output={"dummy": Output("selected-data-right", "data")},
inputs={"selected_data": Input("scatter2d-right", "selectedData")},
state={"session_id": State("session-id", "data")},
)
def select_right_figure(selected_data, session_id):
"""
Callback function to store the selected data from the right 2D scatter plot.
Parameters:
- selectedData (dict): The selected data from the right 2D scatter plot.
- session_id (str): The ID of the current session.
Returns:
- dict: A dictionary containing a dummy value for the output property.
Output Properties:
- dummy (int): A dummy value to trigger the update.
"""
cache_set(selected_data, session_id, CACHE_KEYS["selected_data_right"])
return {"dummy": 0}

@app.callback(
output={"output_trigger": Output("right-hide-trigger", "data")},
inputs={"btn": Input("hide-right", "n_clicks")},
state={
"trigger_idx": State("right-hide-trigger", "data"),
"session_id": State("session-id", "data"),
},
)
def right_hide_button(btn, trigger_idx, session_id):
"""
Callback function to handle the hide right button click event.
Parameters:
- btn (int): The number of times the hide right button has been clicked.
- trigger_idx (int): The current value of the right hide trigger.
- session_id (str): The ID of the current session.
Returns:
- dict: A dictionary containing the updated value for the output trigger.
Output Properties:
- output_trigger (int): The updated value for the right hide trigger.
"""
if btn == 0:
raise PreventUpdate

selected_data = cache_get(session_id, CACHE_KEYS["selected_data_right"])

if selected_data is None:
raise PreventUpdate

visible_table = cache_get(session_id, CACHE_KEYS["visible_table"])

s_data = pd.DataFrame(selected_data["points"])
idx = s_data["id"]
idx.index = idx

vis_idx = idx[visible_table["_VIS_"][idx] == "visible"]
hid_idx = idx[visible_table["_VIS_"][idx] == "hidden"]

visible_table.loc[vis_idx, "_VIS_"] = "hidden"
visible_table.loc[hid_idx, "_VIS_"] = "visible"

cache_set(visible_table, session_id, CACHE_KEYS["visible_table"])

return {"output_trigger": trigger_idx + 1}
2 changes: 2 additions & 0 deletions view_callbacks/scatter_3d_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,7 @@ def visible_table_change_callback(
"unused_vistable_trigger": Input("visible-table-change-trigger", "data"),
"c_key": Input("c-picker-3d", "value"),
"unused_left_hide_trigger": Input("left-hide-trigger", "data"),
"unused_right_hide_trigger": Input("right-hide-trigger", "data"),
"unused_file_loaded": Input("file-loaded-trigger", "data"),
},
state={
Expand All @@ -635,6 +636,7 @@ def regenerate_figure_callback(
c_key,
overlay_enable,
unused_left_hide_trigger,
unused_right_hide_trigger,
unused_file_loaded,
decay,
colormap,
Expand Down
2 changes: 2 additions & 0 deletions view_callbacks/violin_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def get_violin_view_callbacks(app):
inputs={
"unused_filter_trigger": Input("filter-trigger", "data"),
"unused_left_hide_trigger": Input("left-hide-trigger", "data"),
"unused_right_hide_trigger": Input("right-hide-trigger", "data"),
"violin_sw": Input("violin-switch", "value"),
"x_violin": Input("x-picker-violin", "value"),
"y_violin": Input("y-picker-violin", "value"),
Expand All @@ -81,6 +82,7 @@ def get_violin_view_callbacks(app):
def regenerate_violin_callback(
unused_filter_trigger,
unused_left_hide_trigger,
unused_right_hide_trigger,
violin_sw,
x_violin,
y_violin,
Expand Down

0 comments on commit 99d765e

Please sign in to comment.