From 4b6e6c6eed1281dfd1cae68e632511a12ab0e6fb Mon Sep 17 00:00:00 2001 From: "Peter J. Holzer" Date: Sat, 31 Dec 2022 17:51:38 +0100 Subject: [PATCH] Use special log scale for time values Seconds are a bit unintuitive for everything above 1 hour. --- dashboard.py | 41 ++++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/dashboard.py b/dashboard.py index 6a225c8..e3f30c5 100644 --- a/dashboard.py +++ b/dashboard.py @@ -314,19 +314,34 @@ class TimeSeries(Widget): v += step log.debug("") elif self.yscale == "log": - log.debug("") - v = 10 ** math.ceil(math.log10(min_value)) - log.debug("v = %s", v) - if v > max_value: - # Implement that when it happens - log.warning("No tickmark between %s and %s", min_value, max_value) - return - 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 *= 10 - log.debug("") + unit = self.lts.description["unit"] + if unit == "s" and max_value > 3600: + steps = ( + (3600, "1 h"), + (86400, "1 d"), + (7*86400, "1 w"), + (28*86400, "4 w"), + (365*86400, "1 y"), + (3652.5 * 86400, "10 y"), + ) + for s in steps: + if min_value <= s[0] <= max_value: + self.y_tickmarks.append({"y": v2y(s[0]), "v_h": s[1]}) + + else: + log.debug("") + v = 10 ** math.ceil(math.log10(min_value)) + log.debug("v = %s", v) + if v > max_value: + # Implement that when it happens + log.warning("No tickmark between %s and %s", min_value, max_value) + return + 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 *= 10 + log.debug("") else: log.debug("") raise ValueError(f"Unknown yscale {self.yscale}")