From 25381714a19e65010d76d74731e68076de5d3ee3 Mon Sep 17 00:00:00 2001 From: "Peter J. Holzer" Date: Sun, 1 Jan 2023 01:06:24 +0100 Subject: [PATCH] Use special linear scale for time values --- dashboard.py | 47 ++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 40 insertions(+), 7 deletions(-) diff --git a/dashboard.py b/dashboard.py index 0294f45..ef4b4b1 100644 --- a/dashboard.py +++ b/dashboard.py @@ -310,17 +310,50 @@ class TimeSeries(Widget): def set_y_tickmarks(): log.debug("") + unit = self.lts.description["unit"] self.y_tickmarks = [] if self.yscale == "linear": log.debug("") - step = 10 ** math.floor(math.log10(max_value)) - v = 0 - while v < max_value: - self.y_tickmarks.append({"y": v2y(v), "v_h": str(v)}) - v += step - log.debug("") + if unit == "s" and max_value > 3600: + if max_value >= 4 * 7 * 86400: + step = 7 * 86400 + step_d = 1 + unit = "w" + elif max_value >= 10 * 86400: + step = 3 * 86400 + step_d = 3 + unit = "d" + elif max_value >= 4 * 86400: + step = 86400 + step_d = 1 + unit = "d" + elif max_value >= 4 * 3600: + step = 3600 + step_d = 1 + unit = "h" + else: + step = 10 * 60 + step_d = 10 + unit = "m" + v = 0 + v_d = 0 + while v < max_value: + y = v2y(v) + log.debug("v = %s, y = %s", v, y) + self.y_tickmarks.append({"y": y, "v_h": f"{v_d} {unit}"}) + v += step + v_d += step_d + + else: + step = 10 ** math.floor(math.log10(max_value)) + v = 0 + while v < max_value: + y = v2y(v) + log.debug("v = %s, y = %s", v, y) + self.y_tickmarks.append({"y": y, "v_h": str(v)}) + v += step + log.debug("") elif self.yscale == "log": - unit = self.lts.description["unit"] if unit == "s" and max_value > 3600: steps = ( (3600, "1 h"),