Skip to content

Commit

Permalink
with sliders
Browse files Browse the repository at this point in the history
  • Loading branch information
ikaryss committed Feb 14, 2023
1 parent 71d11b3 commit 25fb708
Showing 1 changed file with 70 additions and 9 deletions.
79 changes: 70 additions & 9 deletions pyquac/fmn_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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),
Expand All @@ -55,21 +59,22 @@ 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),
]
),
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(
Expand All @@ -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"},
# ),
]
),
]
Expand All @@ -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
Expand Down

0 comments on commit 25fb708

Please sign in to comment.