Просмотр исходного кода

Load graph selectors asynchronously and correct empty-data detection

SybexXx 1 день назад
Родитель
Сommit
3fc84716b1
1 измененных файлов с 18 добавлено и 18 удалено
  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 */
-                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 
                     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>
 
 <script>
-    function WriteModelFiles()
+    async function WriteModelFiles()
     {
-        list_data = getDATAList();
+        list_data = await getDATAList();
 
         var _indexDig = document.getElementById("datafiles");
         while (_indexDig.length)
@@ -216,9 +212,9 @@
         }
     }
 
-    function WriteNumbers()
+    async function WriteNumbers()
     {
-        list_data = getNUMBERSList();
+        list_data = await getNUMBERSList();
 
         var _indexDig = document.getElementById("numbers");
         while (_indexDig.length)
@@ -235,9 +231,6 @@
         }
     }
 
-    WriteModelFiles();
-    WriteNumbers();
-
     function Refresh() {
         setTimeout (function() {
             run();
@@ -245,8 +238,15 @@
         }, 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>
 </body>
 </html>