X-Git-Url: https://git.toastfreeware.priv.at/chrisu/seepark.git/blobdiff_plain/a0668e798825ed7294cd0f0e5beb6e4bd0884e41..c41b39636626c0fd80c06cec0508458c25b23873:/web/static/seepark_web.js diff --git a/web/static/seepark_web.js b/web/static/seepark_web.js index ff430ff..5aaf55a 100644 --- a/web/static/seepark_web.js +++ b/web/static/seepark_web.js @@ -67,7 +67,6 @@ function dayschart(element, title, days, xtickformat) { chart.resize({ width: getwidth(element) }); - // chart.flush(); }, transition: { duration: null @@ -149,6 +148,9 @@ function dayschart(element, title, days, xtickformat) { grid: { y: { show: true + }, + x: { + show: true } }, regions: [ @@ -159,25 +161,13 @@ function dayschart(element, title, days, xtickformat) { ] }); + // workaround for unrendered dots + setTimeout(function () { chart.flush(); }, 5000); + // reload data in charts - // TODO: this is basically the same as the unused loaddays function below setInterval( function() { - if (element.substr(0, 7) == 'chart_w') { - console.log("water"); - chart.load({ - url: api_base_url_sensors + beginend(days), - mimeType: 'json' - }); - chart.flush(); - } else { - console.log("air"); - chart.load({ - url: api_base_url_weather + beginend(days), - mimeType: 'json' - }); - chart.flush(); - } + loaddays(chart, element, days); }, refresh_interval ); @@ -188,14 +178,17 @@ function loaddays(chart, element, days) { if (element.substr(0, 7) == 'chart_w') { chart.load({ url: api_base_url_sensors + beginend(days), - mimeType: 'json' + mimeType: 'json', + unload: true }); } else { chart.load({ url: api_base_url_weather + beginend(days), - mimeType: 'json' + mimeType: 'json', + unload: true }); - } + }; + setTimeout(function () { chart.flush(); }, 5000); } function beginend(days) { @@ -224,7 +217,7 @@ dayschart('chart_air_7', 'Die Luft (Woche)', 7, '%a %d'); dayschart('chart_air_31', 'Die Luft (Monat)', 31, '%Y-%m-%d'); dayschart('chart_air_365', 'Die Luft (Jahr)', 365, '%b %Y'); -// reload current values +// reload current values + owm script setInterval( function() { var airvalue = document.getElementById('currentairvalue'); @@ -235,20 +228,28 @@ setInterval( .then((resp) => resp.json()) .then(function(data) { airvalue.innerText = data['value'].toFixed(1); - airtime.innerText = strftime('%Y-%m-%d H:%M', data['timestamp']); + airtime.innerText = strftime('%Y-%m-%d %H:%M', new Date(data['timestamp'])); }) .catch(function(error) { - // handle error + console.log(error); }); fetch(api_url_currentwater) .then((resp) => resp.json()) .then(function(data) { watervalue.innerText = data['value'].toFixed(1); - watertime.innerText = strftime('%Y-%m-%d H:%M', data['timestamp']); + watertime.innerText = strftime('%Y-%m-%d %H:%M', new Date(data['timestamp'])); }) .catch(function(error) { - // handle error + console.log(error); }); + + var owmwidget = document.getElementById('openweathermap-widget-15'); + owmwidget.removeChild(owmwidget.childNodes[0]); + var owmscript = document.head.lastElementChild; + document.head.removeChild(owmscript); + var newowmscript = document.createElement('script'); + newowmscript.src = '//openweathermap.org/themes/openweathermap/assets/vendor/owm/js/weather-widget-generator.js'; + document.head.appendChild(newowmscript); }, refresh_interval );