]> source.dussan.org Git - rspamd.git/commitdiff
[WebUI] Turn d3pie's stuff into a reusable function, 1298/head
authorAlexander Moisseev <moiseev@mezonplus.ru>
Tue, 3 Jan 2017 15:52:46 +0000 (18:52 +0300)
committerAlexander Moisseev <moiseev@mezonplus.ru>
Tue, 3 Jan 2017 15:52:46 +0000 (18:52 +0300)
do not destroy pie on data update

interface/js/rspamd.js

index 6c0af1dc647cf16d1c6fc8c8376daee376f4dbba..2199d13d21f08c131fedf92ac420b317a65a5b2d 100644 (file)
                     xhr.setRequestHeader('Password', getPassword());
                 },
                 success: function (data) {
-                    if (pie) {
-                        pie.destroy();
-                    }
-                    pie = new d3pie("chart", {
+                    pie = drawPie(pie, "chart", data);
+                }
+            });
+        }
+
+        function drawPie(obj, id, data, conf) {
+            if (obj) {
+                obj.updateProp("data.content",
+                    data.filter(function (elt) {
+                        return elt.value > 0;
+                    })
+                );
+            } else {
+                obj = new d3pie(id,
+                    $.extend({}, {
                         "header": {
                             "title": {
                                 "text": "Rspamd filter stats",
                                 "percentage": 100
                             }
                         }
-                    });
-                }
-            });
+                    }, conf));
+            }
+            return obj;
         }
 
         function initGraph() {