Skip to content

Commit

Permalink
Better marks for the slider. Partially fixes #22.
Browse files Browse the repository at this point in the history
  • Loading branch information
Akronix committed Aug 30, 2018
1 parent d66e3dd commit 78936bf
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,13 +465,32 @@ def update_slider(data_json, selected_timeaxis):
min_time = 0
max_time = len (time_axis)

number_of_marks = int(len(time_axis) / 9);
subset_times = time_axis[0::number_of_marks]
#~ max_number_of_marks = 11
if max_time < 12:
step_for_marks = 1
elif max_time < 33:
step_for_marks = 3
elif max_time < 66:
step_for_marks = 6
elif max_time < 121:
step_for_marks = 12
elif max_time < 264:
step_for_marks = 24
else:
step_for_marks = 36

# Take dates starting from month 0 in steps defined by step_for_marks
# (which makes sure that you don't have more than 11 points in the slider)
# and skip (don't take) the last mark since we want to put there the last
# month of the wiki.
subset_times = time_axis[0:max_time-step_for_marks:step_for_marks]

if relative_time:
range_slider_marks = {x: str(x) for x in subset_times}
range_slider_marks[max_time-1] = max_time-1
else:
range_slider_marks = {i*number_of_marks: x.strftime('%b %Y') for i, x in enumerate(subset_times)}
range_slider_marks = {i*step_for_marks: x.strftime('%b %Y') for i, x in enumerate(subset_times)}
range_slider_marks[max_time-1] = time_axis[max_time-1].strftime('%b %Y')

return (
dcc.RangeSlider(
Expand Down

0 comments on commit 78936bf

Please sign in to comment.