Browse Source

Load graph selectors asynchronously and correct empty-data detection

SybexXx 1 day ago
parent
commit
3fc84716b1
1 changed files with 18 additions and 18 deletions
  1. 18 18
      sd-card/html/graph.html

+ 18 - 18
sd-card/html/graph.html

@@ -98,16 +98,12 @@
                 }
                 }
 
 
                 /* If the value trace starts with NaN, replace all those Nans with the first valid value */
                 /* 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;
-                    }
-                }
+                var firstNonNaNIndex = traceValue.y.findIndex(function (value) {
+                    return !isNaN(value);
+                });
 
 
-                if (firstNonNaNIndex == (traceValue.y.length - 1)) {
-                    console.log("No data available for 'value'!");
+                if (firstNonNaNIndex === -1) {
+                    console.log("No valid value data available for number sequence '" + numbername + "'.");
                 }
                 }
                 else if (firstNonNaNIndex > 0) { // Replace all leading NaN with the first valid 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",
                     console.log("The first leading values have all just NaN, replacing them with the value of",
@@ -197,9 +193,9 @@
     <button class="button" onClick="window.location.href = getDomainname() + '/fileserver/log/data/'">Show Data Files</button>
     <button class="button" onClick="window.location.href = getDomainname() + '/fileserver/log/data/'">Show Data Files</button>
 
 
 <script>
 <script>
-    function WriteModelFiles()
+    async function WriteModelFiles()
     {
     {
-        list_data = getDATAList();
+        list_data = await getDATAList();
 
 
         var _indexDig = document.getElementById("datafiles");
         var _indexDig = document.getElementById("datafiles");
         while (_indexDig.length)
         while (_indexDig.length)
@@ -216,9 +212,9 @@
         }
         }
     }
     }
 
 
-    function WriteNumbers()
+    async function WriteNumbers()
     {
     {
-        list_data = getNUMBERSList();
+        list_data = await getNUMBERSList();
 
 
         var _indexDig = document.getElementById("numbers");
         var _indexDig = document.getElementById("numbers");
         while (_indexDig.length)
         while (_indexDig.length)
@@ -235,9 +231,6 @@
         }
         }
     }
     }
 
 
-    WriteModelFiles();
-    WriteNumbers();
-
     function Refresh() {
     function Refresh() {
         setTimeout (function() {
         setTimeout (function() {
             run();
             run();
@@ -245,8 +238,15 @@
         }, 300000);
         }, 300000);
     }
     }
 
 
-    run();
-    Refresh();
+    async function initializeGraph() {
+        await Promise.all([WriteModelFiles(), WriteNumbers()]);
+        run();
+        Refresh();
+    }
+
+    initializeGraph().catch(function (error) {
+        console.error("Could not initialize graph selectors:", error);
+    });
 </script>
 </script>
 </body>
 </body>
 </html>
 </html>