CaCO3 před 2 roky
rodič
revize
7488d7bf23
1 změnil soubory, kde provedl 21 přidání a 1 odebrání
  1. 21 1
      sd-card/html/graph.html

+ 21 - 1
sd-card/html/graph.html

@@ -72,7 +72,27 @@
                         }
                         }
                     }
                     }
                 }
                 }
-                //console.log(trace);
+
+                /* If the value trace starts with NaN, replace all those Nans with the first valid value */
+                var firstNonNaNIndex = 0;
+                for(var i = 0; i < traceValue.y.length; i++) {
+                    firstNonNaNIndex = i;
+                    if (! isNaN(traceValue.y[i])) {
+                        break;
+                    }
+                }
+
+                if (firstNonNaNIndex == (traceValue.y.length - 1)) {
+                    console.log("No data available for 'value'!");
+                }
+                else if (firstNonNaNIndex > 0) { // Replace all leading NaN with the first valid value 
+                    console.log("The first leading values have all just NaN, replacing them with the value of",
+                            traceValue.y[firstNonNaNIndex], "at", traceValue.x[firstNonNaNIndex], "(Index:", firstNonNaNIndex, ")");
+                    for(var i = 0; i < firstNonNaNIndex; i++) {
+                        traceValue.y[i] = traceValue.y[firstNonNaNIndex];
+                    }
+                }
+
 
 
                 // Copy time to all traces
                 // Copy time to all traces
                 tracePreValue.x = traceValue.x;
                 tracePreValue.x = traceValue.x;