Make log scales more robust

This commit is contained in:
Peter J. Holzer 2023-04-15 00:31:00 +02:00 committed by Peter J. Holzer
parent 2e8641ad18
commit 206be6a8fa
1 changed files with 7 additions and 3 deletions

View File

@ -139,9 +139,13 @@ class TimeSeries(Widget):
def v2y(v): def v2y(v):
if self.yscale == "log": if self.yscale == "log":
return (1 - math.log(v / min_value) try:
/ math.log(max_value / min_value) return (1 - math.log(max(v, min_value) / min_value)
) * 200 / math.log(max_value / min_value)
) * 200
except ValueError:
log.error(f"ValueError: v = {v}, min_value = {min_value}, max_value = {max_value}")
return 0
elif self.yscale == "linear": elif self.yscale == "linear":
return (1 - v/max_value) * 200 return (1 - v/max_value) * 200
else: else: