From ba1a53a9a3a09835baed0f1aaba556bbff7ef1cd Mon Sep 17 00:00:00 2001 From: Dan Howe Date: Mon, 12 Aug 2019 07:37:27 +1000 Subject: [PATCH] Only plot selected rows --- daqviewer/tables.py | 67 ++++++++++++--------------------------------- 1 file changed, 18 insertions(+), 49 deletions(-) diff --git a/daqviewer/tables.py b/daqviewer/tables.py index 00c6574..2898dbc 100644 --- a/daqviewer/tables.py +++ b/daqviewer/tables.py @@ -4,6 +4,7 @@ from dash.dependencies import Input, Output import dash_table import dash_core_components as dcc import dash_html_components as html +import plotly.graph_objs as go import pandas as pd import numpy as np @@ -80,56 +81,24 @@ def update_graphs(row_ids, selected_row_ids, active_cell): # the component. selected_id_set = set(selected_row_ids or []) - if row_ids is None: - dff = df - # pandas Series works enough like a list for this to be OK - row_ids = df['id'] + if selected_id_set: + dff = df.loc[selected_id_set] else: - dff = df.loc[row_ids] - - active_row_id = active_cell['row_id'] if active_cell else None - - colors = [ - '#FF69B4' if i == active_row_id else - '#7FDBFF' if i in selected_id_set else '#0074D9' for i in row_ids - ] - - return [ - dcc.Graph( - id=column + '--row-ids', - figure={ - 'data': [{ - 'x': dff['id'], - 'y': dff[column], - 'type': 'bar', - 'marker': { - 'color': colors - }, - }], - 'layout': { - 'xaxis': { - 'automargin': True - }, - 'yaxis': { - 'automargin': True, - 'title': { - 'text': column - } - }, - 'height': 250, - 'margin': { - 't': 10, - 'l': 10, - 'r': 10 - }, - }, - }, - ) - # check if column exists - user may have deleted it - # If `column.deletable=False`, then you don't - # need to do this check. - for column in ['H_sig', 'H_1%', 'H_max'] if column in dff - ] + dff = df + + spec = [] + for i, row in dff.iterrows(): + x = np.arange(10) + y = x * row['H_sig'] + + trace = go.Scatter(x=x, y=y, name=i) + spec.append(trace) + + energy = dict(data=spec) + + graph = dcc.Graph(id='time-series', figure=energy) + + return graph if __name__ == '__main__':