From: Alexander Moisseev Date: Tue, 3 Jan 2017 15:52:46 +0000 (+0300) Subject: [WebUI] Turn d3pie's stuff into a reusable function, X-Git-Tag: 1.5.0~433^2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=refs%2Fpull%2F1298%2Fhead;p=rspamd.git [WebUI] Turn d3pie's stuff into a reusable function, do not destroy pie on data update --- diff --git a/interface/js/rspamd.js b/interface/js/rspamd.js index 6c0af1dc6..2199d13d2 100644 --- a/interface/js/rspamd.js +++ b/interface/js/rspamd.js @@ -459,10 +459,21 @@ 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", @@ -538,9 +549,9 @@ "percentage": 100 } } - }); - } - }); + }, conf)); + } + return obj; } function initGraph() {