+ ctx.beginPath();
+ for (i = 0; comb[0][i]; i++) {
+ ctx.moveTo(px(comb[0][i]), py(0) + 5);
+ ctx.lineTo(px(comb[0][i]), py(0));
+ }
+ ctx.strokeStyle = "gray";
+ ctx.stroke();
+
+ ctx.beginPath();
+ ctx.moveTo(px(tmin), py(0));
+ ctx.lineTo(px(tmax), py(0));
+ ctx.strokeStyle = "black";
+ ctx.stroke();
+
+ ctx.fillStyle = "black";
+ ctx.font = "bold 16px Courier";
+ ctx.textAlign = "center";
+ ctx.beginPath();
+ for (i = 0; comb[1][i]; i++) {
+ ctx.fillText(comb[1][i][1], px(comb[1][i][0]), py(0) + 20);
+ ctx.moveTo(px(comb[1][i][0]), py(0) + 5);
+ ctx.lineTo(px(comb[1][i][0]), py(0));
+ }
+ ctx.strokeStyle = "black";
+ ctx.stroke();
+
+ ctx.fillStyle = "black";
+ ctx.textAlign = "left";
+ ctx.fillText(showdate(tmin), px(tmin), py(0) + 40);
+ ctx.textAlign = "right";
+ ctx.fillText(showdate(tmax), px(tmax), py(0) + 40);
+ }
+
+ function getcomby(lo, hi) {
+ var comb = [], lb = [];
+ var d = hi - lo;
+ var ord = Math.pow(10, Math.floor(Math.log10(d)));
+ var scl = Math.floor(d / ord);
+ var inc, inc2, first, x, lb;
+
+ if (scl < 2) { inc = 0.1; inc2 = 0.2; }
+ else if (scl < 5) { inc = 0.1; inc2 = 0.5; }
+ else { inc = 0.5; inc2 = 1; }
+ inc *= ord;
+ inc2 *= ord;
+ first = (Math.floor(lo / inc) + 1) * inc;
+ 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.2; x++)
+ lb.push(first + inc2 * x);
+ //dbg.innerHTML = "ord=" + ord + "<br>inc=" + inc + "<br>"
+ // + comb + "<br>" + lb;
+ return [comb, lb];
+ }
+
+ function yaxis() {
+ var comb = getcomby(0, hmax);
+ var i;
+
+ ctx.beginPath();
+ for (i = 0; comb[0][i]; i++) {
+ ctx.moveTo(px(tmin) - 5, py(comb[0][i]));
+ ctx.lineTo(px(tmax), py(comb[0][i]));
+ }
+ ctx.strokeStyle = "lightgray";
+ ctx.stroke();
+
+ ctx.beginPath();
+ ctx.moveTo(px(tmin), py(0));
+ ctx.lineTo(px(tmin), py(hmax));
+ ctx.strokeStyle = "black";
+ ctx.stroke();
+
+ ctx.fillStyle = "black";
+ ctx.font = "bold 16px Courier";
+ ctx.textAlign = "right";
+ ctx.fillText(0, px(tmin) - 6, py(0));
+ ctx.beginPath();
+ for (i = 0; comb[1][i]; i++) {
+ ctx.fillText(comb[1][i].toFixed(1), px(tmin) - 6, py(comb[1][i]));
+ ctx.moveTo(px(tmin) - 5, py(comb[1][i]));
+ ctx.lineTo(px(tmax), py(comb[1][i]));
+ }
+ ctx.strokeStyle = "gray";
+ ctx.stroke();
+
+ ctx.textAlign = "left";
+ ctx.fillText("l/min", px(tmin) + 4, py(hmax) + 12);
+ }
+
+ /* @ updates global var `hmax` */
+ function differentiate(times) {
+ var res = [];
+ var dv, dt, v;
+
+ for (i = 0; i < times.length - 1; i++) {
+ dv = times[i+1][1] - times[i][1];
+ dt = times[i+1][0] - times[i][0];
+ if (dt != 0 && dv != 0) {
+ v = (dv / dt) * 600 ; /* Litres per min */
+ if (hmax < v) hmax = v;
+ res.push([times[i][0], v]);
+ }