X-Git-Url: https://git.toastfreeware.priv.at/chrisu/seepark.git/blobdiff_plain/12c6d3ce8fac155d829ced736629b5e8399a40e3..399e4efcc12eb206d749d6bc1cafd02d97f6b040:/web/static/seepark_web.js diff --git a/web/static/seepark_web.js b/web/static/seepark_web.js index 93f5d49..904810a 100644 --- a/web/static/seepark_web.js +++ b/web/static/seepark_web.js @@ -7,7 +7,7 @@ var chart = c3.generate({ text: 'Der See' }, data: { - url: '/data', + url: '/data/', // redirects to /data/1 mimeType: 'json', xs: { '0316a2193bff': '0316a2193bff_x', @@ -17,7 +17,11 @@ var chart = c3.generate({ '0316a2193bff': 'Wassertemperatur in 4 m Tiefe', '0316a21383ff': 'Wassertemperatur in 5 m Tiefe' }, - xFormat: '%Y-%m-%d %H:%M:%S' + xFormat: '%Y-%m-%d %H:%M:%S', + colors: { + '0316a2193bff': 'lightblue', + '0316a21383ff': 'darkblue' + } }, axis: { x: { @@ -42,7 +46,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: { @@ -52,7 +68,7 @@ var chart = c3.generate({ return res; }, value: function (value, ratio, id, index) { - return value + '°'; + return value.toFixed(2) + '°'; } } }, @@ -63,9 +79,15 @@ var chart = c3.generate({ }, regions: [ {axis: 'y', start: -999, end: 0, class: 'region-frozen'}, - {axis: 'y', start: 1, end: 25, class: 'region-ok'}, - {axis: 'y', start: 26, end: 99, class: 'region-warm'}, - {axis: 'y', start: 99, end: 999, class: 'region-boiling'} + {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' + }); +}