- document.getElementById("cold").innerHTML = data.current.cold / 100;
- document.getElementById("hot").innerHTML = data.current.hot / 100;
- drawplot(data.cold, "blue");
- drawplot(data.hot, "red");
+ tfact = (ww - xzero) / (tmax - tmin);
+ /* differetiate() updates hmax */
+ hmax = 0;
+ cold_d = differentiate(data.cold);
+ hot_d = differentiate(data.hot);
+ hfact = (wh - yzero) / hmax;
+ //document.getElementById("debug").innerHTML = cold_d + "<br>" + hot_d;
+ redraw();
+ }
+
+ function sendquery(lo, hi) {
+ var url = "query.cgi";
+
+ if (lo && hi) url += "?lo=" + lo + "&" + hi;
+ else url = "query.cgi?lo=2015-12-19+00:00:00&hi=2015-12-20+00:00:00"; //FIX
+ xmlhttp.onreadystatechange = function() {
+ if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
+ // dbg.innerHTML = xmlhttp.responseText;
+ var myData = JSON.parse(xmlhttp.responseText);
+ gotdata(myData);
+ }
+ }
+ xmlhttp.open("GET", url, true);
+ xmlhttp.send();
+ }
+
+ function resize() {
+ ww = window.innerWidth;
+ if (ww > window.innerHeight) ww = window.innerHeight;
+ wh = ww / 2;
+ canvas.width = ww;
+ canvas.height = wh;
+ canvas.style.width = ww + "px";
+ canvas.style.height = wh + "px";
+ redraw();
+ }
+
+ function initialize() {
+ dbg = document.getElementById("debug");
+ canvas = document.getElementById("plot");
+ ctx = canvas.getContext("2d");
+ xmlhttp = new XMLHttpRequest();
+ resize();
+ sendquery();
+ }
+
+ /* Set up */
+ if(window.attachEvent) {
+ window.attachEvent('onload', initialize);
+ window.attachEvent('onresize', resize);
+ } else {
+ window.onload = initialize;
+ window.onresize = resize;