From 7488d7bf239f034fd8f88838512dd397cd832c4f Mon Sep 17 00:00:00 2001 From: CaCO3 Date: Fri, 14 Apr 2023 12:26:25 +0200 Subject: [PATCH] fix leading NaN (#2310) --- sd-card/html/graph.html | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/sd-card/html/graph.html b/sd-card/html/graph.html index 8dcad980..74843d55 100644 --- a/sd-card/html/graph.html +++ b/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 tracePreValue.x = traceValue.x;