+ 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 8px Courier";
+ ctx.fillText(0, px(tmin) - 8, py(0));
+ for (i = 0; comb[1][i]; i++) {
+ ctx.fillText(comb[1][i], px(tmin) - xzero + 2, py(comb[1][i]));
+ }
+ ctx.fillText("l/h", px(tmin) + 2, py(hmax) + 8);
+ }
+
+ /* @ 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) * 360 ; /* Litres per hour */
+ if (hmax < v) hmax = v;
+ res.push([times[i][0], v]);
+ }
+ }
+ res.push([times[i][0], v]);
+
+ return res;
+ }
+
+ function drawplot(data, color) {
+ var i;
+
+ ctx.beginPath();
+ ctx.moveTo(px(data[0][0]), py(data[0][1]));
+ for (i = 1; i < data.length; i++) {
+ ctx.lineTo(px(data[i][0]), py(data[i - 1][1]));
+ ctx.lineTo(px(data[i][0]), py(data[i][1]));
+ }
+ ctx.strokeStyle = color;
+ ctx.stroke();
+ }
+
+ function showloading() {
+ ctx.fillStyle = "green";
+ ctx.font = "bold 16px Courier";
+ ctx.fillText("loading", (ww / 2) - 40 , (wh / 2) + 8);
+ }
+
+ function clearplot() {
+ ctx.clearRect(0, 0, ww, wh);
+ }
+
+ function redraw() {
+ 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();