Increase spacing between horizontal ticks a bit

This commit is contained in:
Peter J. Holzer 2022-12-30 20:19:41 +01:00 committed by Peter J. Holzer
parent 8d02bf2c6b
commit 2b0a0f6d64
1 changed files with 15 additions and 14 deletions

View File

@ -170,6 +170,7 @@ class TimeSeries(Widget):
d = datetime.datetime.fromtimestamp(t)
tickmarks.append({"t": t, "t_h": d.strftime("%Y-%m-%d %H:%M:%S"), "x": x})
min_step = 25
steps = ("s", "m", "h", "D", "M", "Y")
step_i = 0
while True:
@ -181,11 +182,11 @@ class TimeSeries(Widget):
d1 = datetime.datetime(d0.year, d0.month, d0.day, d0.hour, d0.minute, d0.second)
t1 = d1.timestamp()
x1 = t2x(t1)
if x0 - x1 < 20:
if x0 - x1 < min_step:
d1 -= datetime.timedelta(seconds=1)
t1 = d1.timestamp()
x1 = t2x(t1)
if x0 - x1 < 20:
if x0 - x1 < min_step:
step_i += 1
continue
@ -193,11 +194,11 @@ class TimeSeries(Widget):
d1 = datetime.datetime(d0.year, d0.month, d0.day, d0.hour, d0.minute)
t1 = d1.timestamp()
x1 = t2x(t1)
if x0 - x1 < 20:
if x0 - x1 < min_step:
d1 -= datetime.timedelta(minutes=1)
t1 = d1.timestamp()
x1 = t2x(t1)
if x0 - x1 < 20:
if x0 - x1 < min_step:
step_i += 1
continue
@ -205,11 +206,11 @@ class TimeSeries(Widget):
d1 = datetime.datetime(d0.year, d0.month, d0.day, d0.hour)
t1 = d1.timestamp()
x1 = t2x(t1)
if x0 - x1 < 20:
if x0 - x1 < min_step:
d1 -= datetime.timedelta(hours=1)
t1 = d1.timestamp()
x1 = t2x(t1)
if x0 - x1 < 20:
if x0 - x1 < min_step:
step_i += 1
continue
@ -217,11 +218,11 @@ class TimeSeries(Widget):
d1 = datetime.datetime(d0.year, d0.month, d0.day)
t1 = d1.timestamp()
x1 = t2x(t1)
if x0 - x1 < 20:
if x0 - x1 < min_step:
d1 -= datetime.timedelta(days=1)
t1 = d1.timestamp()
x1 = t2x(t1)
if x0 - x1 < 20:
if x0 - x1 < min_step:
step_i += 1
continue
@ -229,14 +230,14 @@ class TimeSeries(Widget):
d1 = datetime.datetime(d0.year, d0.month, 1)
t1 = d1.timestamp()
x1 = t2x(t1)
if x0 - x1 < 20:
if x0 - x1 < min_step:
if d1.month > 1:
d1 = datetime.datetime(d1.year, d1.month-1, 1)
else:
d1 = datetime.datetime(d1.year-1, 12, 1)
t1 = d1.timestamp()
x1 = t2x(t1)
if x0 - x1 < 20:
if x0 - x1 < min_step:
step_i += 1
continue
@ -244,17 +245,17 @@ class TimeSeries(Widget):
d1 = datetime.datetime(d0.year, 1, 1)
t1 = d1.timestamp()
x1 = t2x(t1)
if x0 - x1 < 20:
if x0 - x1 < min_step:
d1 = datetime.datetime(d1.year-1, 1, 1)
t1 = d1.timestamp()
x1 = t2x(t1)
if x0 - x1 < 20:
if x0 - x1 < min_step:
step_i += 1
continue
if x1 < 0:
break
tickmarks.append({"t": t1, "t_h": d1.strftime("%Y-%m-%d %H:%M:%S"), "x": x1})
if tickmarks[-1]["x"] > 20:
if tickmarks[-1]["x"] > min_step:
t = v_data[0]["t"]
x = v_data[0]["x"]
d = datetime.datetime.fromtimestamp(t)
@ -269,7 +270,7 @@ class TimeSeries(Widget):
v += step
html = ""
html += "<svg width=1200 height=300>"
html += "<svg width=1150 height=300>"
for tm in self.x_tickmarks:
html += f"<line x1={tm['x']} y1=0 x2={tm['x']} y2=200 stroke='#CCC' />"
html += f"<text transform='translate({tm['x']}, 210) rotate(30)' fill='#888'>{tm['t_h']}</text>"