diff --git a/tsplot b/tsplot index f56b2b6..07f679f 100755 --- a/tsplot +++ b/tsplot @@ -60,25 +60,32 @@ plot_page = html.Div([ id='interval-component', interval=4*1000, # in milliseconds n_intervals=0), - dcc.Dropdown( - id='timerange', - options=[ - {'label': 'Last hour', 'value': 'h'}, - {'label': 'Last day', 'value': 'd'}, - {'label': 'Last week', 'value': 'w'}, - {'label': 'All', 'value': 'all'} - ], - value='d' - ), + html.Div([ + dcc.Input(id="range_count", + type="number", + value=1, + debounce=True, + min=1), + dcc.Dropdown( + id='timerange', + 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.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 {