From 8d02bf2c6b8277936796f59b64e5499190031e5e Mon Sep 17 00:00:00 2001 From: "Peter J. Holzer" Date: Fri, 30 Dec 2022 20:14:00 +0100 Subject: [PATCH] Add description to timeseries --- dashboard.py | 26 +++++++++++++++----------- templates/dashboard.html | 8 ++++++++ templates/timeseries.html | 4 ++++ 3 files changed, 27 insertions(+), 11 deletions(-) create mode 100644 templates/timeseries.html diff --git a/dashboard.py b/dashboard.py index a9d136f..e2aa199 100644 --- a/dashboard.py +++ b/dashboard.py @@ -126,13 +126,24 @@ class Widget: log.debug("definitely fail") return f"hsl(0, 100%, {brightness}%)" + @property + def description_formatted(self): + s = "" + for d, v in self.lts.description.items(): + if v: + s += render_template_string( + "", + d=d, v=v) + s += "
{{d}}:{{v}}
" + return Markup(s) class TimeSeries(Widget): def __init__(self, d): super().__init__(d) pass - def as_html(self): + @property + def graph(self): def t2x(t): x = n - math.log((t_last - t) / (n*dt) + 1) * n / k return x @@ -270,6 +281,9 @@ class TimeSeries(Widget): html += "" return Markup(html) + def as_html(self): + return Markup(render_template("timeseries.html", widget=self)) + class Gauge(Widget): def __init__(self, d): super().__init__(d) @@ -311,13 +325,3 @@ class Gauge(Widget): self.lastvalue_formatted = Markup(f"{value:.2f}{unit}") return Markup(render_template("gauge.html", widget=self)) - @property - def description_formatted(self): - s = "" - for d, v in self.lts.description.items(): - if v: - s += render_template_string( - "", - d=d, v=v) - s += "
{{d}}:{{v}}
" - return Markup(s) diff --git a/templates/dashboard.html b/templates/dashboard.html index 7d7782c..ebc3bc5 100644 --- a/templates/dashboard.html +++ b/templates/dashboard.html @@ -15,6 +15,7 @@ display: flex; flex-wrap: wrap; gap: 2rem; + align-items: end; } .widget { border: 1px solid #CCC; @@ -45,6 +46,13 @@ position: absolute; bottom: 0; } + .timeseries { + display: flex; + gap: 1rem; + align-items: end; + border: 1px solid #CCC; + padding: 0.5rem; + } diff --git a/templates/timeseries.html b/templates/timeseries.html new file mode 100644 index 0000000..ffe44bf --- /dev/null +++ b/templates/timeseries.html @@ -0,0 +1,4 @@ +
+ {{ widget.graph }} + {{ widget.description_formatted }} +