From 2b0a0f6d64ca83850f33f8ab69cdfd30f4335cad Mon Sep 17 00:00:00 2001 From: "Peter J. Holzer" Date: Fri, 30 Dec 2022 20:19:41 +0100 Subject: [PATCH] Increase spacing between horizontal ticks a bit --- dashboard.py | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/dashboard.py b/dashboard.py index e2aa199..37fd9bb 100644 --- a/dashboard.py +++ b/dashboard.py @@ -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 += "" + html += "" for tm in self.x_tickmarks: html += f"" html += f"{tm['t_h']}"