Skip to content
Snippets Groups Projects
Commit bb80226b authored by Robert Goldmann's avatar Robert Goldmann
Browse files

#36 - SensorLineChartTile now supports showing axes and longterm data

parent bc94d2bd
No related branches found
No related tags found
No related merge requests found
...@@ -22,7 +22,9 @@ ...@@ -22,7 +22,9 @@
flex-direction: row; flex-direction: row;
justify-content: space-between; justify-content: space-between;
align-items: center; align-items: center;
{% if not showAxes %}
padding-bottom: 5%; padding-bottom: 5%;
{% endif %}
} }
.sensorLineChartTile .title { .sensorLineChartTile .title {
...@@ -52,7 +54,9 @@ ...@@ -52,7 +54,9 @@
<div class="header"> <div class="header">
<div class="header-left"> <div class="header-left">
<div class="title">{{ title }}</div> <div class="title">{{ title }}</div>
{% if not showAxes %}
<div class="value">{{ latest }}{{ unit }}</div> <div class="value">{{ latest }}{{ unit }}</div>
{% endif %}
</div> </div>
<i class="wi {{ icon }}"></i> <i class="wi {{ icon }}"></i>
</div> </div>
...@@ -91,29 +95,45 @@ ...@@ -91,29 +95,45 @@
let layout = { let layout = {
xaxis: { xaxis: {
showgrid: false, showgrid: false,
zeroline: false, zeroline: {{ showAxes | lower }},
visible: false, visible: {{ showAxes | lower }},
showspikes: {{ showAxes | lower }},
spikedash: 'solid',
spikecolor: 'white',
spikethickness: 2,
tickcolor: 'white',
zerolinecolor: 'white',
linecolor: 'white',
tickfont: {
color: 'white'
}
}, },
yaxis: { yaxis: {
showgrid: false, showgrid: false,
zeroline: false, zeroline: {{ showAxes | lower }},
visible: false, visible: {{ showAxes | lower }},
range: [{{ min }}, {{ max }}] range: [{{ min }}, {{ max }}],
tickcolor: 'white',
zerolinecolor: 'white',
linecolor: 'white',
tickfont: {
color: 'white'
}
}, },
paper_bgcolor: 'rgba(0,0,0,0)', paper_bgcolor: 'rgba(0,0,0,0)',
plot_bgcolor: 'rgba(0,0,0,0)', plot_bgcolor: 'rgba(0,0,0,0)',
showlegend: false, showlegend: false,
margin: { margin: {
b: 0, b: {% if showAxes %}50{% else %}0{% endif %},
l: 0, l: {% if showAxes %}50{% else %}0{% endif %},
r: 0, r: {% if showAxes %}50{% else %}0{% endif %},
t: 0 t: 0
}, },
dragmode: !isMobileDevice() dragmode: !isMobileDevice()
}; };
let config = { let config = {
displayModeBar: false, displayModeBar: {{ showAxes | lower }},
displaylogo: false, displaylogo: false,
responsive: true, responsive: true,
locale: 'de' locale: 'de'
......
...@@ -29,7 +29,8 @@ class SensorLineChartTile(Tile): ...@@ -29,7 +29,8 @@ class SensorLineChartTile(Tile):
"numberOfHoursToShow": 4, "numberOfHoursToShow": 4,
"decimals": 1, "decimals": 1,
"lineColor": "rgba(254, 151, 0, 1)", "lineColor": "rgba(254, 151, 0, 1)",
"fillColor": "rgba(254, 151, 0, 0.2)" "fillColor": "rgba(254, 151, 0, 0.2)",
"showAxes": True
} }
UNIT_BY_SENSOR_TYPE = { UNIT_BY_SENSOR_TYPE = {
...@@ -137,6 +138,11 @@ class SensorLineChartTile(Tile): ...@@ -137,6 +138,11 @@ class SensorLineChartTile(Tile):
textLabels = [f'{self.__format_date(xItem)} - {yItem}{unescapedUnit}' for xItem, yItem in zip(data['x'], textLabels = [f'{self.__format_date(xItem)} - {yItem}{unescapedUnit}' for xItem, yItem in zip(data['x'],
data['y'])] data['y'])]
title = self._settings['title']
if self._settings['showAxes']:
days = int(self._settings['numberOfHoursToShow'] / 24)
title = f'{title} - {days} days'
return Tile.render_template(os.path.dirname(__file__), __class__.__name__, return Tile.render_template(os.path.dirname(__file__), __class__.__name__,
x=data['x'], x=data['x'],
y=data['y'], y=data['y'],
...@@ -146,12 +152,13 @@ class SensorLineChartTile(Tile): ...@@ -146,12 +152,13 @@ class SensorLineChartTile(Tile):
latest=data['latest'], latest=data['latest'],
unit=unit, unit=unit,
icon=icon, icon=icon,
title=self._settings['title'], title=title,
lineColor=self._settings['lineColor'], lineColor=self._settings['lineColor'],
fillColor=self._settings['fillColor'], fillColor=self._settings['fillColor'],
chartId=str(uuid.uuid4()), chartId=str(uuid.uuid4()),
ghostTraceX=data['ghostTraceX'], ghostTraceX=data['ghostTraceX'],
ghostTraceY=data['ghostTraceY']) ghostTraceY=data['ghostTraceY'],
showAxes=self._settings['showAxes'])
def __format_date(self, dateTime: str): def __format_date(self, dateTime: str):
parsedDateTime = datetime.strptime(dateTime, self.DATE_FORMAT) parsedDateTime = datetime.strptime(dateTime, self.DATE_FORMAT)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment