fix total calculation for empty dataset
authorEugene Crosser <crosser@average.org>
Fri, 25 Dec 2015 21:16:24 +0000 (00:16 +0300)
committerEugene Crosser <crosser@average.org>
Fri, 25 Dec 2015 21:16:24 +0000 (00:16 +0300)
web/index.html

index 0c6c1777b3a1870ac20e2ce6fc4f9843fb2e3785..a1745afe9684bb469b686fb7c6dad6832a852c42 100644 (file)
     document.getElementById("curhot").innerHTML =
       (data.current.hot / 100).toFixed(2);
 
     document.getElementById("curhot").innerHTML =
       (data.current.hot / 100).toFixed(2);
 
-    document.getElementById("totcold").innerHTML =
-      ((data.cold[data.cold.length - 1][1] - data.cold[0][1]) * 10);
-    document.getElementById("tothot").innerHTML =
-      ((data.hot[data.hot.length - 1][1] - data.hot[0][1]) * 10);
+    if (data.cold.length)
+      document.getElementById("totcold").innerHTML =
+        ((data.cold[data.cold.length - 1][1] - data.cold[0][1]) * 10);
+    else document.getElementById("totcold").innerHTML = "0";
+    if (data.hot.length)
+      document.getElementById("tothot").innerHTML =
+        ((data.hot[data.hot.length - 1][1] - data.hot[0][1]) * 10);
+    else document.getElementById("tothot").innerHTML = "0";
 
     tmin = data.range.lo;
     tmax = data.range.hi;
 
     tmin = data.range.lo;
     tmax = data.range.hi;