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

28
tsplot
View File

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