ha-frontend/src/components/state-history-charts.html

105 lines
2.5 KiB
HTML
Raw Normal View History

2015-07-13 01:57:15 +02:00
<link rel="import" href="../../bower_components/polymer/polymer.html">
2016-07-31 23:43:07 +02:00
<link rel="import" href="../../bower_components/paper-spinner/paper-spinner.html">
2015-07-13 01:57:15 +02:00
<link rel="import" href="../../bower_components/google-apis/google-legacy-loader.html">
<link rel="import" href="./state-history-chart-timeline.html">
<link rel="import" href="./state-history-chart-line.html">
<dom-module id="state-history-charts">
2016-07-19 10:19:44 +02:00
<template>
<style>
:host {
display: block;
}
2015-07-13 01:57:15 +02:00
2016-07-19 10:19:44 +02:00
.loading-container {
text-align: center;
padding: 8px;
}
.loading {
height: 0px;
overflow: hidden;
}
</style>
2015-07-13 01:57:15 +02:00
<google-legacy-loader on-api-load="_googleApiLoaded"></google-legacy-loader>
2015-07-13 01:57:15 +02:00
<template is='dom-if' if='[[_isLoading]]'>
<div class='loading-container'>
<paper-spinner active alt='Updating history data'></paper-spinner>
</div>
</template>
2015-07-13 01:57:15 +02:00
<template is='dom-if' if='[[!_isLoading]]'>
<template is='dom-if' if='[[_computeIsEmpty(historyData)]]'>
2015-07-13 01:57:15 +02:00
No state history found.
</template>
<state-history-chart-timeline
data='[[historyData.timeline]]'>
2015-07-13 01:57:15 +02:00
</state-history-chart-timeline>
<template is='dom-repeat' items='[[historyData.line]]'>
2016-07-19 06:28:42 +02:00
<state-history-chart-line
unit='[[item.unit]]'
data='[[item.data]]'
is-single-device='[[_computeIsSingleLineChart(historyData)]]'>
2015-07-13 01:57:15 +02:00
</state-history-chart-line>
</template>
</template>
2015-07-13 01:57:15 +02:00
</template>
</dom-module>
2016-07-19 06:28:42 +02:00
<script>
Polymer({
is: 'state-history-charts',
properties: {
historyData: {
2016-07-19 06:28:42 +02:00
type: Object,
value: null,
2016-07-19 06:28:42 +02:00
},
isLoadingData: {
type: Boolean,
value: true,
2016-07-19 06:28:42 +02:00
},
_apiLoaded: {
2016-07-19 06:28:42 +02:00
type: Boolean,
value: false,
},
_isLoading: {
2016-07-19 06:28:42 +02:00
type: Boolean,
computed: '_computeIsLoading(isLoadingData, _apiLoaded)',
2016-07-19 06:28:42 +02:00
},
},
_computeIsSingleLineChart: function (historyData) {
return historyData && historyData.line.length === 1;
2016-07-19 06:28:42 +02:00
},
_googleApiLoaded: function () {
2016-07-19 06:28:42 +02:00
window.google.load('visualization', '1', {
packages: ['timeline', 'corechart'],
callback: function () {
this._apiLoaded = true;
2016-07-19 06:28:42 +02:00
}.bind(this),
});
},
_computeIsLoading: function (_isLoadingData, _apiLoaded) {
return _isLoadingData || !_apiLoaded;
2016-07-19 06:28:42 +02:00
},
_computeIsEmpty: function (historyData) {
return (historyData &&
historyData.timeline.length === 0 &&
historyData.line.length === 0);
2016-07-19 06:28:42 +02:00
},
});
</script>