Add tickmarks for 10 day intervals

This commit is contained in:
Peter J. Holzer 2022-12-30 20:29:39 +01:00 committed by Peter J. Holzer
parent 2b0a0f6d64
commit 5dec92d736
1 changed files with 40 additions and 1 deletions

View File

@ -171,7 +171,7 @@ class TimeSeries(Widget):
tickmarks.append({"t": t, "t_h": d.strftime("%Y-%m-%d %H:%M:%S"), "x": x}) tickmarks.append({"t": t, "t_h": d.strftime("%Y-%m-%d %H:%M:%S"), "x": x})
min_step = 25 min_step = 25
steps = ("s", "m", "h", "D", "M", "Y") steps = ("s", "m", "h", "D", "10D", "M", "Y")
step_i = 0 step_i = 0
while True: while True:
t0 = tickmarks[-1]["t"] t0 = tickmarks[-1]["t"]
@ -226,6 +226,45 @@ class TimeSeries(Widget):
step_i += 1 step_i += 1
continue continue
if steps[step_i] == "10D":
year = d0.year
month = d0.month
day = d0.day
if day > 21:
day = 21
elif day > 11:
day = 11
elif day > 1:
day = 1
else:
day = 21
month -= 1
if month < 1:
month += 12
year -= 1
d1 = datetime.datetime(year, month, day)
t1 = d1.timestamp()
x1 = t2x(t1)
if x0 - x1 < min_step:
if day > 21:
day = 21
elif day > 11:
day = 11
elif day > 1:
day = 1
else:
day = 21
month -= 1
if month < 1:
month += 12
year -= 1
d1 = datetime.datetime(year, month, day)
t1 = d1.timestamp()
x1 = t2x(t1)
if x0 - x1 < min_step:
step_i += 1
continue
if steps[step_i] == "M": if steps[step_i] == "M":
d1 = datetime.datetime(d0.year, d0.month, 1) d1 = datetime.datetime(d0.year, d0.month, 1)
t1 = d1.timestamp() t1 = d1.timestamp()