replace 1 chart+buttons with 4 charts
authorgregor herrmann <gregor@toastfreeware.priv.at>
Thu, 14 Jun 2018 21:03:41 +0000 (23:03 +0200)
committergregor herrmann <gregor@toastfreeware.priv.at>
Thu, 14 Jun 2018 21:03:41 +0000 (23:03 +0200)
web/static/seepark_web.css
web/static/seepark_web.js
web/templates/seepark_web.html

index 6ddd30ab5198fb3eace372412793cb7a78632921..70d7692e4482235e95f9cb66b51cddd054f10106 100644 (file)
     fill: red;
 }
 
-button {
-    color: inherit;
-    font: inherit;
-    margin: 0;
-    border: 1px solid;
-}
-
-#buttonbar, #openweathermap-widget-15 {
+#openweathermap-widget-15 {
     margin: 0 auto;
     text-align: center;
     padding-top: 1em;
-}
-
-#openweathermap-widget-15 {
     width: 300px;
 }
index 1af2da3c0d4668e163ffd0184bf37786752d892a..87e897a33c828485881944e241aa171b5c52eb3f 100644 (file)
@@ -1,96 +1,96 @@
 var api_base_url = '/api/1/sensor/type/Wassertemperatur?mode=consolidated&format=c3';
 
-var chart = c3.generate({
-       bindto: '#chart',
-       transition: {
-               duration: null
-       },
-       title: {
-               text: 'Der See'
-       },
-       data: {
-//             url: '/data/', // redirects to /data/1
-               url: api_base_url + beginend(1),
-               mimeType: 'json',
-               xs: {
-                       '0316a2193bff': '0316a2193bff_x',
-                       '0316a21383ff': '0316a21383ff_x'
+function dayschart(element, interval, days) {
+       var chart = c3.generate({
+               bindto: element,
+               transition: {
+                       duration: null
                },
-               names: {
-                       '0316a2193bff': 'Wassertemperatur in 4 m Tiefe',
-                       '0316a21383ff': 'Wassertemperatur in 5 m Tiefe'
+               title: {
+                       text: 'Der See (' + interval + ')'
                },
-               xFormat: '%Y-%m-%d %H:%M:%S',
-               colors: {
-                       '0316a2193bff': 'lightblue',
-                       '0316a21383ff': 'darkblue'
-               }
-       },
-       axis: {
-               x: {
-                       type: 'timeseries',
-                       tick: {
-                               format: '%Y-%m-%d %H:%M',
-                               fit: false,
-                               multiline: true, // broken? so →
-                               rotate: -90
+               data: {
+                       url: api_base_url + beginend(days),
+                       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',
+                       colors: {
+                               '0316a2193bff': 'lightblue',
+                               '0316a21383ff': 'darkblue'
                        }
                },
-               y: {
-                       label: {
-                               text: 'Temperatur in °C',
-                               position: 'outer-middle'
+               axis: {
+                       x: {
+                               type: 'timeseries',
+                               tick: {
+                                       format: '%Y-%m-%d %H:%M',
+                                       fit: false,
+                                       multiline: true, // broken? so →
+                                       rotate: -90
+                               }
                        },
-                       tick: {
-                               format: function (d) {
-                                       return d.toFixed(1) + '°';
+                       y: {
+                               label: {
+                                       text: 'Temperatur in °C',
+                                       position: 'outer-middle'
+                               },
+                               tick: {
+                                       format: function (d) {
+                                               return d.toFixed(1) + '°';
+                                       }
                                }
                        }
-               }
-       },
-       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);
+               },
+               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) + '°';
+               },
+               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
                        }
-               }
-       },
-       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'}
-       ]
-});
+               },
+               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,
                url: api_base_url + beginend(days),
                mimeType: 'json'
        });
@@ -102,3 +102,8 @@ function beginend(days) {
        var begin = new Date(now - days * 60*60*24 * 1000).toISOString().substr(0, 19);
        return '&begin=' + begin + '&end=' + end;
 }
+
+dayschart('#chart1',   'Tag',     1);
+dayschart('#chart7',   'Woche',   7);
+dayschart('#chart31',  'Monat',  31);
+dayschart('#chart365', 'Jahr',  365);
index 4d136e3e6dc2bcf538c61ead8c59f8454b7ea328..6997f7a50450b35b7e231614250a4738120ea90f 100644 (file)
        </head>
        <body>
                <h1>Daten zum Seepark Obsteig</h1>
-               <div id="chart"></div>
-               <div id="buttonbar">
-                       <button onclick="loaddays(1)">Tag</button>
-                       <button onclick="loaddays(7)">Woche</button>
-                       <button onclick="loaddays(30)">Monat</button>
-                       <button onclick="loaddays(365)">Jahr</button>
-               </div>
+               <div id="chart1"></div>
+               <div id="chart7"></div>
+               <div id="chart31"></div>
+               <div id="chart365"></div>
 
                <!-- openweathermap widget -->
                <div id="openweathermap-widget-15"></div>