]> ToastFreeware Gitweb - chrisu/seepark.git/blobdiff - web/static/seepark_web.js
experiment again with re-loading chart data
[chrisu/seepark.git] / web / static / seepark_web.js
index ff430ff9337969d9775bd8da1022c8305aca1fef..5cdeca5b9b65ea1065e8148ccd8e4788cd076187 100644 (file)
@@ -149,6 +149,9 @@ function dayschart(element, title, days, xtickformat) {
                grid: {
                        y: {
                                show: true
+                       },
+                       x: {
+                               show: true
                        }
                },
                regions: [
@@ -159,25 +162,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 +179,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
                });
-       }
+       };
+       chart.flush();
 }
 
 function beginend(days) {
@@ -235,19 +229,19 @@ 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);
                        });
        },
        refresh_interval