Display min and max values in timeseries

This commit is contained in:
Peter J. Holzer 2023-01-10 21:33:47 +01:00 committed by Peter J. Holzer
parent e57e333942
commit 7ab45d3e90
1 changed files with 13 additions and 2 deletions

View File

@ -396,7 +396,7 @@ class TimeSeries(Widget):
dt = (t_last - data[-5][0]) / 4 dt = (t_last - data[-5][0]) / 4
k = math.log((t_last - data[0][0]) / dt / n + 1) k = math.log((t_last - data[0][0]) / dt / n + 1)
max_value = max([d[1] for d in self.lts.data]) max_value = max([d[3] if len(d) >= 4 else d[1] for d in self.lts.data])
max_value = max(max_value, 0.001) # ensure positive max_value = max(max_value, 0.001) # ensure positive
if self.yscale == "log": if self.yscale == "log":
try: try:
@ -422,9 +422,17 @@ class TimeSeries(Widget):
for i in range(n): for i in range(n):
t = data[i][0] t = data[i][0]
v = data[i][1] v = data[i][1]
if len(data[i]) >= 4:
v_min = data[i][2]
v_max = data[i][3]
else:
v_min = data[i][1]
v_max = data[i][1]
x = t2x(t) x = t2x(t)
t_h = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(t)) t_h = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(t))
y = v2y(v) y = v2y(v)
y_min = v2y(v_min)
y_max = v2y(v_max)
#print(t, t_h, x) #print(t, t_h, x)
v_data.append( v_data.append(
{ {
@ -432,6 +440,8 @@ class TimeSeries(Widget):
"v": v, "v": v,
"x": x, "x": x,
"y": y, "y": y,
"y_min": y_min,
"y_max": y_max,
"color": self.criticalcolor(v), "color": self.criticalcolor(v),
}) })
@ -450,7 +460,8 @@ class TimeSeries(Widget):
html += f"<line x1=0 y1={tm['y']} x2=1000 y2={tm['y']} stroke='#CCC' />" html += f"<line x1=0 y1={tm['y']} x2=1000 y2={tm['y']} stroke='#CCC' />"
html += f"<text x=1005 y={tm['y']} fill='#888'>{tm['v_h']}</text>" html += f"<text x=1005 y={tm['y']} fill='#888'>{tm['v_h']}</text>"
for v in v_data: for v in v_data:
html += f"<circle cx={v['x']} cy={v['y']} r=3 fill='{v['color']}' />" html += f"<line x1={v['x']-3} x2={v['x']+3} y1={v['y']} y2={v['y']} stroke='{v['color']}' />"
html += f"<line x1={v['x']} x2={v['x']} y1={v['y_min']} y2={v['y_max']} stroke='{v['color']}' />"
html += "</svg>" html += "</svg>"
log.debug("len(html) = %s", len(html)) log.debug("len(html) = %s", len(html))
return Markup(html) return Markup(html)