]> www.average.org Git - pulsecounter.git/blobdiff - web/index.html
wrong conversion. l/min, not /hr
[pulsecounter.git] / web / index.html
index f70f51b05686131df6ff06c82a605a3fdcebf1f8..debb7d8b73aa02dcdb50c35a8292e4891625ebe7 100644 (file)
@@ -5,7 +5,6 @@
 <head>
 <script>
   var dbg;
-  var xmlhttp;
   var canvas, ctx;
   var ww, wh;
   var hmax, hfact;
@@ -90,7 +89,7 @@
       ctx.fillText(comb[1][i].toFixed(1), px(tmin) - 6, py(comb[1][i]));
     }
     ctx.textAlign = "left";
-    ctx.fillText("l/h", px(tmin) + 4, py(hmax) + 8);
+    ctx.fillText("l/min", px(tmin) + 4, py(hmax) + 8);
   }
 
   /* @ updates global var `hmax` */
       dv = times[i+1][1] - times[i][1];
       dt = times[i+1][0] - times[i][0];
       if (dt != 0 && dv != 0) {
-        v = (dv / dt) * 360 ; /* Litres per hour */
+        v = (dv / dt) * 600 ; /* Litres per min */
         if (hmax < v) hmax = v;
         res.push([times[i][0], v]);
       }
     redraw();
   }
 
-  function iso2qu(idate) {
-    return idate.replace("T", "+").replace("0Z", "");
-  }
-
-  function sendquery(lo, hi) {
-    var url = "query.cgi" + "?lo=" + iso2qu(lo) + "&hi=" + iso2qu(hi);
+  function sendreq(qstr) {
+    var url = "query.cgi" + qstr;
+    var xmlhttp = new XMLHttpRequest();
 
     //dbg.innerHTML = url;
     xmlhttp.onreadystatechange = function() {
     xmlhttp.send();
   }
 
+  function iso2qu(idate) {
+    return idate.replace("T", "+").replace("0Z", "");
+  }
+
+  function sendquery(lo, hi) {
+    return sendreq("?lo=" + iso2qu(lo) + "&hi=" + iso2qu(hi));
+  }
+
   function resize() {
     ww = window.innerWidth - 4;
     if (ww > window.innerHeight) ww = window.innerHeight;
 
     wstart = new Date(1*tdy - 86400000 * (dow + 7));
     wend = new Date(1*wstart + 86400000 * 7);
-    xmlhttp = new XMLHttpRequest();
     sendquery(wstart.toISOString(), wend.toISOString());
   }
 
 
     wstart = new Date(1*tdy - 86400000 * dow);
     wend = new Date(1*wstart + 86400000 * 7);
-    xmlhttp = new XMLHttpRequest();
     sendquery(wstart.toISOString(), wend.toISOString());
   }
 
     var tdy = daystart(new Date());
     var ytd = new Date(1*tdy - 86400000);
     var byd = new Date(1*ytd - 86400000);
-    xmlhttp = new XMLHttpRequest();
     sendquery(byd.toISOString(), ytd.toISOString());
   }
 
   function yesterday() {
     var tdy = daystart(new Date());
     var ytd = new Date(1*tdy - 86400000);
-    xmlhttp = new XMLHttpRequest();
     sendquery(ytd.toISOString(), tdy.toISOString());
   }
 
   function today() {
     var tdy = daystart(new Date());
     var tmr = new Date(1*tdy + 86400000);
-    xmlhttp = new XMLHttpRequest();
     sendquery(tdy.toISOString(), tmr.toISOString());
   }
 
   function initialize() {
+    var qstr = window.location.search;
+
     dbg = document.getElementById("debug");
     canvas = document.getElementById("plot");
     ctx = canvas.getContext("2d");
     resize();
-    today();
+    if (qstr) sendreq(qstr);
+    else today();
     
     document.getElementById("today").onclick = today;
     document.getElementById("yesterday").onclick = yesterday;
   }
 
   /* Set up */
-  if(window.attachEvent) {
-    window.attachEvent('onload', initialize);
-    window.attachEvent('onresize', resize);
-  } else {
-    window.onload = initialize;
-    window.onresize = resize;
-  }
+  window.onload = initialize;
+  window.onresize = resize;
 </script>
 <style>
 @font-face {
@@ -342,6 +339,7 @@ div.query {
   width: 8em;
   height: 8em;
   border: solid 1px black;
+  border-radius: 1em;
   background-color: lightgray;
   cursor: pointer;
 }