Add number input to select timerange more precisely

master
0xee 2020-12-21 21:30:17 +01:00
parent 6215406e34
commit 8d33fe713c
1 changed files with 24 additions and 16 deletions

40
tsplot
View File

@ -60,25 +60,32 @@ plot_page = html.Div([
id='interval-component', id='interval-component',
interval=4*1000, # in milliseconds interval=4*1000, # in milliseconds
n_intervals=0), n_intervals=0),
dcc.Dropdown( html.Div([
id='timerange', dcc.Input(id="range_count",
options=[ type="number",
{'label': 'Last hour', 'value': 'h'}, value=1,
{'label': 'Last day', 'value': 'd'}, debounce=True,
{'label': 'Last week', 'value': 'w'}, min=1),
{'label': 'All', 'value': 'all'} dcc.Dropdown(
], id='timerange',
value='d' options=[
), {'label': 'hours', 'value': 'h'},
{'label': 'days', 'value': 'd'},
{'label': 'weeks', 'value': 'w'},
{'label': 'all', 'value': 'all'}
],
value='d'
),
]),
dcc.Graph(id='graph', animate=False), dcc.Graph(id='graph', animate=False),
dcc.Link('Back', href='/') dcc.Link('Back', href='/')
]) ])
def get_timedelta(range_str): def get_timedelta(range_str, count):
range_to_delta = { range_to_delta = {
'h': datetime.timedelta(hours=1), 'h': datetime.timedelta(hours=count),
'd': datetime.timedelta(days=1), 'd': datetime.timedelta(days=count),
'w': datetime.timedelta(weeks=1), 'w': datetime.timedelta(weeks=count),
'all': datetime.timedelta(weeks=10000), 'all': datetime.timedelta(weeks=10000),
} }
return range_to_delta[range_str] return range_to_delta[range_str]
@ -87,11 +94,12 @@ def get_timedelta(range_str):
@app.callback(Output('graph', 'figure'), @app.callback(Output('graph', 'figure'),
[Input('interval-component', 'n_intervals'), [Input('interval-component', 'n_intervals'),
Input('timerange', 'value'), Input('timerange', 'value'),
Input('range_count', 'value'),
Input('url', 'pathname')]) Input('url', 'pathname')])
def update_graph(interval, timerange, pathname): def update_graph(interval, timerange, range_count, pathname):
topics = pathname.strip('/').split('+') topics = pathname.strip('/').split('+')
if len(topics): if len(topics):
delta = get_timedelta(timerange) delta = get_timedelta(timerange, range_count)
now = int(time.time()) // update_interval_s now = int(time.time()) // update_interval_s
def make_data(df, name): def make_data(df, name):
return { return {