Add number input to select timerange more precisely
parent
6215406e34
commit
8d33fe713c
28
tsplot
28
tsplot
|
@ -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),
|
||||||
|
html.Div([
|
||||||
|
dcc.Input(id="range_count",
|
||||||
|
type="number",
|
||||||
|
value=1,
|
||||||
|
debounce=True,
|
||||||
|
min=1),
|
||||||
dcc.Dropdown(
|
dcc.Dropdown(
|
||||||
id='timerange',
|
id='timerange',
|
||||||
options=[
|
options=[
|
||||||
{'label': 'Last hour', 'value': 'h'},
|
{'label': 'hours', 'value': 'h'},
|
||||||
{'label': 'Last day', 'value': 'd'},
|
{'label': 'days', 'value': 'd'},
|
||||||
{'label': 'Last week', 'value': 'w'},
|
{'label': 'weeks', 'value': 'w'},
|
||||||
{'label': 'All', 'value': 'all'}
|
{'label': 'all', 'value': 'all'}
|
||||||
],
|
],
|
||||||
value='d'
|
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 {
|
||||||
|
|
Loading…
Reference in New Issue