Jelajahi Sumber

Tweaked build and update to allow for other chart types

Henry Whitaker 6 tahun lalu
induk
melakukan
ad332df8de
2 mengubah file dengan 18 tambahan dan 9 penghapusan
  1. 1 0
      api/functions/homepage-connect-functions.php
  2. 17 9
      js/functions.js

+ 1 - 0
api/functions/homepage-connect-functions.php

@@ -2754,6 +2754,7 @@ function getNetdata()
 
 				$data['title'] = $GLOBALS['netdata'.$i.'Title'];
 				$data['colour'] = $GLOBALS['netdata'.$i.'Colour'];
+				$data['chart'] = $GLOBALS['netdata'.$i.'Chart'];
 
 				array_push($api['data'], $data);
 			}

+ 17 - 9
js/functions.js

@@ -7402,8 +7402,8 @@ function buildNetdataItem(array){
     </style>
     `;
 
-    array.forEach((e, i) => {
-        html += `
+    var buildEasyPieChart = function(e,i) {
+        return `
         <div class="col-lg-2 col-md-3 col-sm-4 col-xs-12 my-3 text-center">
             <div class="d-flex justify-content-center">
                 <div class="chart" id="easyPieChart`+(i+1)+`" data-percent="`+e.percent+`">
@@ -7425,7 +7425,13 @@ function buildNetdataItem(array){
             });
         });
         </script>
-            `;
+        `;
+    }
+
+    array.forEach((e, i) => {
+        if(e.chart == 'easypiechart') {
+            html += buildEasyPieChart(e,i);
+        }
     });
     
     return html;
@@ -7609,12 +7615,14 @@ function tryUpdateNetdata(array){
     var existing = false;
     array.forEach((e,i) => {
         var id = i + 1;
-        if($('#easyPieChart' + id).length) {
-            $('#easyPieChart' + id).data('easyPieChart').update(e.percent);
-            $('#easyPieChart' + id + 'Value').html(parseFloat(e.value).toFixed(1));
-            existing = true;
-        } else {
-            existing = false;
+        if(e.chart == 'easypiechart') {
+            if($('#easyPieChart' + id).length) {
+                $('#easyPieChart' + id).data('easyPieChart').update(e.percent);
+                $('#easyPieChart' + id + 'Value').html(parseFloat(e.value).toFixed(1));
+                existing = true;
+            } else {
+                existing = false;
+            }
         }
     });
     return existing;