From 25fb708fe90fa6c86a7b2fc411d6cc28b6b12a40 Mon Sep 17 00:00:00 2001 From: Nikolay Date: Tue, 14 Feb 2023 18:26:16 +0300 Subject: [PATCH] with sliders --- pyquac/fmn_app.py | 79 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 70 insertions(+), 9 deletions(-) diff --git a/pyquac/fmn_app.py b/pyquac/fmn_app.py index d3630f1..7180d8b 100644 --- a/pyquac/fmn_app.py +++ b/pyquac/fmn_app.py @@ -4,7 +4,7 @@ This is where we define the various css items to fetch as well as the layout of our application. """ -from dash import dcc, callback +from dash import dcc, callback, ctx from dash.dependencies import Input, Output from dash import html import dash_bootstrap_components as dbc @@ -17,6 +17,8 @@ from pyquac.components.property_nav import property_nav from pyquac.components.heatmap import figure_layout +import numpy as np + # App Instance THEME = dbc.themes.ZEPHYR CSS = settings.css_url @@ -44,6 +46,8 @@ def serve_layout(): dcc.Store(id="z_store", data=data.njit_result), dcc.Store(id="x_store", data=data.x_1d), dcc.Store(id="y_store", data=data.y_1d), + dcc.Store(id="y_scatter", data=None), + dcc.Store(id="z_scatter", data=None), # dcc.Store(id="update_interval", data=settings.init_interval), # dcc.Store(id="max_interval_value", data=settings.init_max_interval), dcc.Store(id="x_label", data=settings.init_x_label), @@ -55,6 +59,7 @@ def serve_layout(): n_intervals=0, max_intervals=settings.init_max_interval, ), + dcc.Interval(id="clientside-interval", n_intervals=0, interval=250), dbc.Row( [ dbc.Col(navbar), @@ -62,14 +67,14 @@ def serve_layout(): ), dbc.Row( [ - dbc.Col(children=[sidebar, content], width=3), + dbc.Col(children=[sidebar(data), content], width=3), dbc.Col( [ - dbc.Row( - children=[ - property_nav, - ] - ), + # dbc.Row( + # children=[ + # property_nav, + # ] + # ), dbc.Row( children=[ figure_layout( @@ -78,6 +83,13 @@ def serve_layout(): settings.init_y_label, settings.init_cmap, ), + # dcc.Graph( + # id="empty", + # figure=go.Scatter( + # x=[1, 2, 3], y=[1, 2, 3], mode="lines" + # ), + # style={"display": "none"}, + # ), ] ), ] @@ -87,9 +99,58 @@ def serve_layout(): ] ) - @callback(Output("z_store", "data"), Input("interval-graph-update", "n_intervals")) + @callback( + Output("x_store", "data"), + Output("y_store", "data"), + Output("z_store", "data"), + Input("interval-graph-update", "n_intervals"), + ) def update_fig_data(i): - return data.njit_result + return ( + data.x_1d, + data.y_1d, + data.njit_result, + ) + + @callback( + Output("y_scatter", "data"), + Output("z_scatter", "data"), + Input("heatmap", "clickData"), + Input("x-slider", "value"), + ) + def update_click_data(click, x_slider): + triggered_id = ctx.triggered_id + if (click == None) and (x_slider == None): + y_scatter, z_scatter = None, None + + if triggered_id == "heatmap": + if click is None: + y_scatter, z_scatter = None, None + else: + x_click = click["points"][0]["x"] + print(x_click) + mask = np.equal(data.x_raw, np.array(x_click)) + y_scatter = np.array(data.y_raw)[mask] + z_scatter = np.array(data.z_raw)[mask] + + if triggered_id == "x-slider": + print("check") + mask = np.equal(data.x_raw, np.array(x_slider)) + y_scatter = np.array(data.y_raw)[mask] + z_scatter = np.array(data.z_raw)[mask] + return y_scatter, z_scatter + + # @callback( + # Output("y_scatter", "data"), + # Output("z_scatter", "data"), + # Input("x-slider", "value"), + # ) + # def update_slide_data_x(x_val): + + # mask = np.equal(data.x_raw, np.array(x_val)) + # y_scatter = np.array(data.y_raw)[mask] + # z_scatter = np.array(data.z_raw)[mask] + # return y_scatter, z_scatter app.layout = serve_layout return app