]> 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 b58ad45d1b616545c2dd852b1e65a8041a268ad9..f5f2f6a413fe4c0e87f33f2355402518fe5894f1 100644 (file)
@@ -1,22 +1,89 @@
 var chart = c3.generate({
-    bindto: '#chart',
-    data: {
-        x: 'x',
-//        xFormat: '%Y%m%d', // 'xFormat' can be used as custom format of 'x'
-        columns: [
-            ['x', '2013-01-01', '2013-01-02', '2013-01-03', '2013-01-04', '2013-01-05', '2013-01-06'],
-//            ['x', '20130101', '20130102', '20130103', '20130104', '20130105', '20130106'],
-            ['data1', 30, 200, 100, 400, 150, 250],
-            ['data2', 130, 340, 200, 500, 250, 350]
-        ]
-    },
-    axis: {
-        x: {
-            type: 'timeseries',
-            tick: {
-                format: '%Y-%m-%d'
-            }
-        }
-    }
+       bindto: '#chart',
+       transition: {
+               duration: null
+       },
+       title: {
+               text: 'Der See'
+       },
+       data: {
+               url: '/data/', // redirects to /data/1
+               mimeType: 'json',
+               xs: {
+                       '0316a2193bff': '0316a2193bff_x',
+                       '0316a21383ff': '0316a21383ff_x'
+               },
+               names: {
+                       '0316a2193bff': 'Wassertemperatur in 4 m Tiefe',
+                       '0316a21383ff': 'Wassertemperatur in 5 m Tiefe'
+               },
+               xFormat: '%Y-%m-%d %H:%M:%S'
+       },
+       axis: {
+               x: {
+                       type: 'timeseries',
+                       tick: {
+                               format: '%Y-%m-%d %H:%M',
+                               fit: false,
+                               multiline: true, // broken? so →
+                               rotate: -90
+                       }
+               },
+               y: {
+                       label: {
+                               text: 'Temperatur in °C',
+                               position: 'outer-middle'
+                       },
+                       tick: {
+                               format: function (d) {
+                                       return d + '°';
+                               }
+                       }
+               }
+       },
+       zoom: {
+               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: {
+                       name: function (name, ratio, id, index) {
+                               var re = /\d m/;
+                               var res = re.exec(name);
+                               return res;
+                       },
+                       value: function (value, ratio, id, index) {
+                               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'
+       });
+}