]> ToastFreeware Gitweb - chrisu/seepark.git/blobdiff - web/static/seepark_web.js
next attempt with the reload-on-zoom function. not yet working, esp. one doesn't...
[chrisu/seepark.git] / web / static / seepark_web.js
index ce4226e6af4f1cd6d628d674a9998d16280ee100..0bda80064e8391adc56a63a268d61ae0c9e991cb 100644 (file)
@@ -7,7 +7,7 @@ var chart = c3.generate({
                text: 'Der See'
        },
        data: {
                text: 'Der See'
        },
        data: {
-               url: '/data',
+               url: '/data/', // redirects to /data/1
                mimeType: 'json',
                xs: {
                        '0316a2193bff': '0316a2193bff_x',
                mimeType: 'json',
                xs: {
                        '0316a2193bff': '0316a2193bff_x',
@@ -42,7 +42,19 @@ var chart = c3.generate({
                }
        },
        zoom: {
                }
        },
        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: {
        },
        tooltip: {
                format: {
@@ -69,3 +81,9 @@ var chart = c3.generate({
        ]
 });
 
        ]
 });
 
+function loaddays(days) {
+       chart.load({
+               url: '/data/' + days,
+               mimeType: 'json'
+       });
+}