From c3ab18e5aa88d991135a86577f93c937fbc2db53 Mon Sep 17 00:00:00 2001 From: Robert Goldmann <deadlocker@gmx.de> Date: Wed, 18 Nov 2020 17:48:54 +0100 Subject: [PATCH] Fixed #35 - handle negative temperatures --- src/logic/tile/tiles/SensorLineChartTile.html | 38 ++++++++++++------- src/logic/tile/tiles/SensorLineChartTile.py | 17 ++++++++- 2 files changed, 39 insertions(+), 16 deletions(-) diff --git a/src/logic/tile/tiles/SensorLineChartTile.html b/src/logic/tile/tiles/SensorLineChartTile.html index 1a5e850..f101b29 100644 --- a/src/logic/tile/tiles/SensorLineChartTile.html +++ b/src/logic/tile/tiles/SensorLineChartTile.html @@ -62,21 +62,31 @@ <script> function createChart_{{ chartId | replace('-', '_') }}() { - let data = [{ - x: {{ x }}, - y: {{ y }}, - text: {{ textLabels }}, - fill: 'tozeroy', - type: 'scatter', - mode: 'lines', - line: { - shape: 'spline', - color: '{{ lineColor }}', - width: 3 + let data = [ + { + x: {{ x }}, + y: {{ y }}, + text: {{ textLabels }}, + fill: 'tozeroy', + type: 'scatter', + mode: 'lines', + line: { + shape: 'spline', + color: '{{ lineColor }}', + width: 3 + }, + hoverinfo: 'text', + fillcolor: '{{ fillColor }}' }, - hoverinfo: 'text', - fillcolor: '{{ fillColor }}' - }]; + { + x: {{ ghostTraceX }}, + y: {{ ghostTraceY }}, + fill: 'tozeroy', + type: 'scatter', + mode: 'none', + fillcolor: '{{ fillColor }}' + } + ]; let layout = { xaxis: { diff --git a/src/logic/tile/tiles/SensorLineChartTile.py b/src/logic/tile/tiles/SensorLineChartTile.py index 7aeb33a..a9d4a2f 100644 --- a/src/logic/tile/tiles/SensorLineChartTile.py +++ b/src/logic/tile/tiles/SensorLineChartTile.py @@ -75,13 +75,24 @@ class SensorLineChartTile(Tile): endDateTime, storageLeafService) + # Check if all values are above zero and the min value for the sensor group is below zero. + # Therefore a ghost trace must be generated that fills the area underneath the x-axis. + ghostTraceX = [] + ghostTraceY = [] + if all(float(i) >= 0 for i in y): + if minValue < 0: + ghostTraceX = [x[0], x[-1]] + ghostTraceY = [minValue, minValue] + return { 'latest': latest, 'x': x, 'y': y, 'sensorInfo': sensorData['sensorInfo'], 'min': minValue, - 'max': maxValue + 'max': maxValue, + 'ghostTraceX': ghostTraceX, + 'ghostTraceY': ghostTraceY } def __get_min_and_max(self, pageName: str, sensorType: Dict, @@ -138,7 +149,9 @@ class SensorLineChartTile(Tile): title=self._settings['title'], lineColor=self._settings['lineColor'], fillColor=self._settings['fillColor'], - chartId=str(uuid.uuid4())) + chartId=str(uuid.uuid4()), + ghostTraceX=data['ghostTraceX'], + ghostTraceY=data['ghostTraceY']) def __format_date(self, dateTime: str): parsedDateTime = datetime.strptime(dateTime, self.DATE_FORMAT) -- GitLab