]> ToastFreeware Gitweb - chrisu/seepark.git/blobdiff - web/static/seepark_web.js
tooltip: 2 decimal places are enough
[chrisu/seepark.git] / web / static / seepark_web.js
index 5f0facc70d7e6fc2b4b912c7b908a95f7f367c88..f5f2f6a413fe4c0e87f33f2355402518fe5894f1 100644 (file)
@@ -1,10 +1,13 @@
 var chart = c3.generate({
        bindto: '#chart',
+       transition: {
+               duration: null
+       },
        title: {
-               text: 'Temperaturen'
+               text: 'Der See'
        },
        data: {
-               url: '/data',
+               url: '/data/', // redirects to /data/1
                mimeType: 'json',
                xs: {
                        '0316a2193bff': '0316a2193bff_x',
@@ -39,7 +42,19 @@ var chart = c3.generate({
                }
        },
        zoom: {
-               enabled: true
+               enabled: true,
+               onzoomend: function (domain) {
+                       // UNIX epoch
+                       var start = domain[0].getTime()/1000;
+                       var end   = domain[1].getTime()/1000;
+                       var duration = end - start;
+                       // duration is now the diff of the "viewport in seconds"
+                       // FIXME
+                       var days = Math.round(duration / 86400 / 2);
+                       if (days > 0) {
+                               loaddays(days);
+                       }
+               }
        },
        tooltip: {
                format: {
@@ -49,9 +64,26 @@ var chart = c3.generate({
                                return res;
                        },
                        value: function (value, ratio, id, index) {
-                               return value + '°';
+                               return value.toFixed(2) + '°';
                        }
                }
-       }
+       },
+       grid: {
+               y: {
+                       show: true
+               }
+       },
+       regions: [
+               {axis: 'y', start: -999, end:   0, class: 'region-frozen'},
+               {axis: 'y', start:    0, end:  25, class: 'region-ok'},
+               {axis: 'y', start:   25, end: 100, class: 'region-warm'},
+               {axis: 'y', start:  100, end: 999, class: 'region-boiling'}
+       ]
 });
 
+function loaddays(days) {
+       chart.load({
+               url: '/data/' + days,
+               mimeType: 'json'
+       });
+}