X-Git-Url: http://average.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=web%2Findex.html;h=f63467190945b58bd4d7aae8eb7c81639a1603ce;hb=9dcf18f64ca3a0df27551f392d2ad0263479af52;hp=72bd9f9d5f5edb5fd425f9d823044af77d6f3ea6;hpb=fcca95634eda4df11fc367c294e34203ad3bc934;p=pulsecounter.git
diff --git a/web/index.html b/web/index.html
index 72bd9f9..f634671 100644
--- a/web/index.html
+++ b/web/index.html
@@ -10,9 +10,14 @@
var ww, wh;
var hmax, hfact;
var tmin, tmax, tfact;
- var xzero = 20, yzero = 20;
+ var xzero = 36, yzero = 24;
var cold_d = [], hot_d = [];
+ function showdate(utime) {
+ var dt = new Date(utime*1000);
+ return dt.toLocaleDateString() + " " + dt.toLocaleTimeString();
+ }
+
function getcomb(lo, hi) {
var comb = [], lb = [];
var d = hi - lo;
@@ -20,16 +25,16 @@
var scl = Math.floor(d / ord);
var inc, inc2, first, x, lb;
- if (scl < 2) { inc = 0.1; inc2 = 0.5; }
- else if (scl < 5) { inc = 0.2; inc2 = 1; }
- else { inc = 0.5; inc2 = 2; }
+ if (scl < 2) { inc = 0.1; inc2 = 0.2; }
+ else if (scl < 5) { inc = 0.1; inc2 = 0.2; }
+ else { inc = 0.5; inc2 = 1; }
inc *= ord;
inc2 *= ord;
first = (Math.floor(lo / inc) + 1) * inc;
- for (x = 0; x < (d / inc) - 1.5; x++)
+ for (x = 0; x < (d / inc) - 1.2; x++)
comb.push(first + inc * x);
first = (Math.floor(lo / inc2) + 1) * inc2;
- for (x = 0; x < (d / inc2) - 1.5; x++)
+ for (x = 0; x < (d / inc2) - 1.2; x++)
lb.push(first + inc2 * x);
//dbg.innerHTML = "ord=" + ord + "
inc=" + inc + "
"
// + comb + "
" + lb;
@@ -50,6 +55,13 @@
ctx.lineTo(px(tmax), py(0));
ctx.strokeStyle = "black";
ctx.stroke();
+
+ ctx.fillStyle = "black";
+ ctx.font = "bold 12px Courier";
+ ctx.textAlign = "left";
+ ctx.fillText(showdate(tmin), px(tmin), py(0) + 20);
+ ctx.textAlign = "right";
+ ctx.fillText(showdate(tmax), px(tmax), py(0) + 20);
}
function yaxis() {
@@ -71,12 +83,14 @@
ctx.stroke();
ctx.fillStyle = "black";
- ctx.font = "bold 8px Courier";
- ctx.fillText(0, px(tmin) - 8, py(0));
+ ctx.font = "bold 12px Courier";
+ ctx.textAlign = "right";
+ ctx.fillText(0, px(tmin) - 6, py(0));
for (i = 0; comb[1][i]; i++) {
- ctx.fillText(comb[1][i], px(tmin) - xzero + 2, py(comb[1][i]));
+ ctx.fillText(comb[1][i].toFixed(1), px(tmin) - 6, py(comb[1][i]));
}
- ctx.fillText("l/h", px(tmin) + 2, py(hmax) + 8);
+ ctx.textAlign = "left";
+ ctx.fillText("l/h", px(tmin) + 4, py(hmax) + 8);
}
/* @ updates global var `hmax` */
@@ -93,7 +107,7 @@
res.push([times[i][0], v]);
}
}
- res.push([times[i][0], v]);
+ if (i) res.push([times[i][0], v]);
return res;
}
@@ -114,7 +128,16 @@
function showloading() {
ctx.fillStyle = "green";
ctx.font = "bold 16px Courier";
- ctx.fillText("loading", (ww / 2) - 40 , (wh / 2) + 8);
+ ctx.textAlign="center";
+ ctx.fillText("...loading...", (ww / 2) , (wh / 2) + 8);
+ }
+
+ function showempty() {
+ ctx.fillStyle = "red";
+ ctx.font = "bold 24px Courier";
+ ctx.textAlign="center";
+ ctx.fillText("No data for the requested time interval",
+ (ww / 2) , (wh / 2) + 8);
}
function clearplot() {
@@ -122,16 +145,16 @@
}
function redraw() {
- if (cold_d.length && hot_d.length) {
+ clearplot();
+ if (cold_d.length || hot_d.length) {
tfact = (ww - xzero) / (tmax - tmin);
hfact = (wh - yzero) / hmax;
- clearplot();
xaxis();
yaxis();
drawplot(cold_d, "blue");
drawplot(hot_d, "red");
} else {
- showloading();
+ showempty();
}
}
@@ -142,6 +165,8 @@
(data.current.hot / 100).toFixed(2);
tmin = data.range.lo;
tmax = data.range.hi;
+ //dbg.innerHTML = "from " + tmin + " to " + tmax
+ // + "
from " + showdate(tmin) + " to " + showdate(tmax);
/* differetiate() updates hmax */
hmax = 0;
cold_d = differentiate(data.cold);
@@ -151,11 +176,14 @@
redraw();
}
+ function iso2qu(idate) {
+ return idate.replace("T", "+").replace("0Z", "");
+ }
+
function sendquery(lo, hi) {
- var url = "query.cgi";
+ var url = "query.cgi" + "?lo=" + iso2qu(lo) + "&hi=" + iso2qu(hi);
- 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
+ //dbg.innerHTML = url;
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
// dbg.innerHTML = xmlhttp.responseText;
@@ -164,6 +192,8 @@
}
}
xmlhttp.open("GET", url, true);
+ clearplot();
+ showloading();
xmlhttp.send();
}
@@ -178,13 +208,70 @@
redraw();
}
+ function daystart(date) {
+ date.setMilliseconds(0);
+ date.setSeconds(0);
+ date.setMinutes(0);
+ date.setHours(0);
+ return date;
+ }
+
+ function prevweek() {
+ var tdy = daystart(new Date());
+ var dow = tdy.getDay();
+ var wstart, wend;
+
+ wstart = new Date(1*tdy - 86400000 * (dow + 7));
+ wend = new Date(1*wstart + 86400000 * 7);
+ xmlhttp = new XMLHttpRequest();
+ sendquery(wstart.toISOString(), wend.toISOString());
+ }
+
+ function thisweek() {
+ var tdy = daystart(new Date());
+ var dow = tdy.getDay();
+ var wstart, wend;
+
+ wstart = new Date(1*tdy - 86400000 * dow);
+ wend = new Date(1*wstart + 86400000 * 7);
+ xmlhttp = new XMLHttpRequest();
+ sendquery(wstart.toISOString(), wend.toISOString());
+ }
+
+ function beforeyesterday() {
+ 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() {
dbg = document.getElementById("debug");
canvas = document.getElementById("plot");
ctx = canvas.getContext("2d");
- xmlhttp = new XMLHttpRequest();
resize();
- sendquery();
+ today();
+
+ document.getElementById("today").onclick = today;
+ document.getElementById("yesterday").onclick = yesterday;
+ document.getElementById("beforeyesterday").onclick = beforeyesterday;
+ document.getElementById("thisweek").onclick = thisweek;
+ document.getElementById("prevweek").onclick = prevweek;
}
/* Set up */
@@ -197,8 +284,18 @@
}