f5f2f6a413fe4c0e87f33f2355402518fe5894f1
[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         },
22         axis: {
23                 x: {
24                         type: 'timeseries',
25                         tick: {
26                                 format: '%Y-%m-%d %H:%M',
27                                 fit: false,
28                                 multiline: true, // broken? so →
29                                 rotate: -90
30                         }
31                 },
32                 y: {
33                         label: {
34                                 text: 'Temperatur in °C',
35                                 position: 'outer-middle'
36                         },
37                         tick: {
38                                 format: function (d) {
39                                         return d + '°';
40                                 }
41                         }
42                 }
43         },
44         zoom: {
45                 enabled: true,
46                 onzoomend: function (domain) {
47                         // UNIX epoch
48                         var start = domain[0].getTime()/1000;
49                         var end   = domain[1].getTime()/1000;
50                         var duration = end - start;
51                         // duration is now the diff of the "viewport in seconds"
52                         // FIXME
53                         var days = Math.round(duration / 86400 / 2);
54                         if (days > 0) {
55                                 loaddays(days);
56                         }
57                 }
58         },
59         tooltip: {
60                 format: {
61                         name: function (name, ratio, id, index) {
62                                 var re = /\d m/;
63                                 var res = re.exec(name);
64                                 return res;
65                         },
66                         value: function (value, ratio, id, index) {
67                                 return value.toFixed(2) + '°';
68                         }
69                 }
70         },
71         grid: {
72                 y: {
73                         show: true
74                 }
75         },
76         regions: [
77                 {axis: 'y', start: -999, end:   0, class: 'region-frozen'},
78                 {axis: 'y', start:    0, end:  25, class: 'region-ok'},
79                 {axis: 'y', start:   25, end: 100, class: 'region-warm'},
80                 {axis: 'y', start:  100, end: 999, class: 'region-boiling'}
81         ]
82 });
83
84 function loaddays(days) {
85         chart.load({
86                 url: '/data/' + days,
87                 mimeType: 'json'
88         });
89 }