1 <?xml version="1.0" encoding="utf-8"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
3 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
4 <html xml:lang="en" lang="en" xmlns="http://www.w3.org/1999/xhtml">
12 var tmin, tmax, tfact;
13 var xzero = 20, yzero = 20;
14 var cold_d = [], hot_d = [];
17 return xzero + ((x - tmin) * tfact);
20 return wh - yzero - (y * hfact);
24 ctx.moveTo(px(tmin), py(0));
25 ctx.lineTo(px(tmax), py(0));
26 ctx.strokeStyle = "black";
31 ctx.moveTo(px(tmin), py(0));
32 ctx.lineTo(px(tmin), py(hmax));
33 ctx.strokeStyle = "black";
36 /* @ updates global var `hmax` */
37 function differentiate(times) {
41 for (i = 0; i < times.length - 1; i++) {
42 dv = times[i+1][1] - times[i][1];
43 dt = times[i+1][0] - times[i][0];
44 if (dt != 0 && dv != 0) {
46 if (hmax < v) hmax = v;
47 res.push([times[i][0], v]);
50 res.push([times[i][0], v]);
54 function drawplot(data, color) {
58 ctx.moveTo(px(data[0][0]), py(data[0][1]));
59 for (i = 1; i < data.length; i++) {
60 ctx.lineTo(px(data[i][0]), py(data[i - 1][1]));
61 ctx.lineTo(px(data[i][0]), py(data[i][1]));
63 ctx.strokeStyle = color;
67 if (cold_d.length && hot_d.length) {
68 drawplot(cold_d, "blue");
69 drawplot(hot_d, "red");
73 /* load animation here */ ;
77 function gotdata(data) {
78 document.getElementById("cold").innerHTML =
79 (data.current.cold / 100).toFixed(2);
80 document.getElementById("hot").innerHTML =
81 (data.current.hot / 100).toFixed(2);
84 tfact = (ww - xzero) / (tmax - tmin);
85 /* differetiate() updates hmax */
87 cold_d = differentiate(data.cold);
88 hot_d = differentiate(data.hot);
89 hfact = (wh - yzero) / hmax;
90 //document.getElementById("debug").innerHTML = cold_d + "<br>" + hot_d;
94 function sendquery(lo, hi) {
95 var url = "query.cgi";
97 if (lo && hi) url += "?lo=" + lo + "&" + hi;
98 else url = "query.cgi?lo=2015-12-19+00:00:00&hi=2015-12-20+00:00:00"; //FIX
99 xmlhttp.onreadystatechange = function() {
100 if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
101 // dbg.innerHTML = xmlhttp.responseText;
102 var myData = JSON.parse(xmlhttp.responseText);
106 xmlhttp.open("GET", url, true);
111 ww = window.innerWidth;
112 if (ww > window.innerHeight) ww = window.innerHeight;
116 canvas.style.width = ww + "px";
117 canvas.style.height = wh + "px";
121 function initialize() {
122 dbg = document.getElementById("debug");
123 canvas = document.getElementById("plot");
124 ctx = canvas.getContext("2d");
125 xmlhttp = new XMLHttpRequest();
131 if(window.attachEvent) {
132 window.attachEvent('onload', initialize);
133 window.attachEvent('onresize', resize);
135 window.onload = initialize;
136 window.onresize = resize;
157 border: solid 1px black;
162 background-color: #d0e0ff;
166 background-color: #ffd0e0;
174 border: solid 1px black;
180 <title>Water Meters</title>
182 <h1>Water Meters</h1>
183 <div id="currentvals">
185 <div class="current" id="cold">cold</div>
186 <div class="current" id="hot">hot</div>
189 <canvas id="plot" width="640" height = "320"></canvas>