Use special log scale for time values

Seconds are a bit unintuitive for everything above 1 hour.
This commit is contained in:
Peter J. Holzer 2022-12-31 17:51:38 +01:00 committed by Peter J. Holzer
parent fedc4c66ac
commit 4b6e6c6eed
1 changed files with 28 additions and 13 deletions

View File

@ -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}")