]> ToastFreeware Gitweb - chrisu/seepark.git/blob - web/static/seepark_web.js
maybe we want different shades of blue for the water termperatures
[chrisu/seepark.git] / web / static / seepark_web.js
1 var chart = c3.generate({
2         bindto: '#chart',
3         transition: {
4                 duration: null
5         },
6         title: {
7                 text: 'Der See'
8         },
9         data: {
10                 url: '/data/', // redirects to /data/1
11                 mimeType: 'json',
12                 xs: {
13                         '0316a2193bff': '0316a2193bff_x',
14                         '0316a21383ff': '0316a21383ff_x'
15                 },
16                 names: {
17                         '0316a2193bff': 'Wassertemperatur in 4 m Tiefe',
18                         '0316a21383ff': 'Wassertemperatur in 5 m Tiefe'
19                 },
20                 xFormat: '%Y-%m-%d %H:%M:%S',
21                 colors: {
22                         '0316a2193bff': 'lightblue',
23                         '0316a21383ff': 'darkblue'
24                 }
25         },
26         axis: {
27                 x: {
28                         type: 'timeseries',
29                         tick: {
30                                 format: '%Y-%m-%d %H:%M',
31                                 fit: false,
32                                 multiline: true, // broken? so →
33                                 rotate: -90
34                         }
35                 },
36                 y: {
37                         label: {
38                                 text: 'Temperatur in °C',
39                                 position: 'outer-middle'
40                         },
41                         tick: {
42                                 format: function (d) {
43                                         return d + '°';
44                                 }
45                         }
46                 }
47         },
48         zoom: {
49                 enabled: true,
50                 onzoomend: function (domain) {
51                         // UNIX epoch
52                         var start = domain[0].getTime()/1000;
53                         var end   = domain[1].getTime()/1000;
54                         var duration = end - start;
55                         // duration is now the diff of the "viewport in seconds"
56                         // FIXME
57                         var days = Math.round(duration / 86400 / 2);
58                         if (days > 0) {
59                                 loaddays(days);
60                         }
61                 }
62         },
63         tooltip: {
64                 format: {
65                         name: function (name, ratio, id, index) {
66                                 var re = /\d m/;
67                                 var res = re.exec(name);
68                                 return res;
69                         },
70                         value: function (value, ratio, id, index) {
71                                 return value.toFixed(2) + '°';
72                         }
73                 }
74         },
75         grid: {
76                 y: {
77                         show: true
78                 }
79         },
80         regions: [
81                 {axis: 'y', start: -999, end:   0, class: 'region-frozen'},
82                 {axis: 'y', start:    0, end:  25, class: 'region-ok'},
83                 {axis: 'y', start:   25, end: 100, class: 'region-warm'},
84                 {axis: 'y', start:  100, end: 999, class: 'region-boiling'}
85         ]
86 });
87
88 function loaddays(days) {
89         chart.load({
90                 url: '/data/' + days,
91                 mimeType: 'json'
92         });
93 }