]> ToastFreeware Gitweb - chrisu/seepark.git/blobdiff - web/static/seepark_web.js
show current/most recent air/water temperature on top of page
[chrisu/seepark.git] / web / static / seepark_web.js
index 87e897a33c828485881944e241aa171b5c52eb3f..63bca132533275b3cd42f35048aa4503c22f4ab1 100644 (file)
@@ -1,8 +1,11 @@
 var api_base_url = '/api/1/sensor/type/Wassertemperatur?mode=consolidated&format=c3';
 
-function dayschart(element, interval, days) {
+function dayschart(element, interval, days, xtickformat) {
        var chart = c3.generate({
-               bindto: element,
+               bindto: '#' + element,
+               size: {
+                       width: document.getElementById(element).parentElement.clientWidth * 80 / 100
+               },
                transition: {
                        duration: null
                },
@@ -30,7 +33,7 @@ function dayschart(element, interval, days) {
                        x: {
                                type: 'timeseries',
                                tick: {
-                                       format: '%Y-%m-%d %H:%M',
+                                       format: xtickformat,
                                        fit: false,
                                        multiline: true, // broken? so →
                                        rotate: -90
@@ -72,6 +75,10 @@ function dayschart(element, interval, days) {
                                },
                                value: function (value, ratio, id, index) {
                                        return value.toFixed(2) + '°';
+                               },
+                               title: function (x) {
+                                       // TODO: format datetime into something readable
+                                       return x;
                                }
                        }
                },
@@ -103,7 +110,7 @@ function beginend(days) {
        return '&begin=' + begin + '&end=' + end;
 }
 
-dayschart('#chart1',   'Tag',     1);
-dayschart('#chart7',   'Woche',   7);
-dayschart('#chart31',  'Monat',  31);
-dayschart('#chart365', 'Jahr',  365);
+dayschart('chart1',   'Tag',     1, '%H:%M');
+dayschart('chart7',   'Woche',   7, '%a %d');
+dayschart('chart31',  'Monat',  31, 'Woche %V');
+dayschart('chart365', 'Jahr',  365, '%b %d');