From 3940c84de345fe58a1f82844a709f6f8a84e8a01 Mon Sep 17 00:00:00 2001 From: William Van Hevelingen Date: Mon, 30 Jun 2014 19:30:36 -0700 Subject: [PATCH] Improve speed with facts that have many unique values When there are more than 15 unique fact values it groups the least commonly used into an other label. Co-authored-by: Sage Imel Co-authored-by: Ryan Niebur --- puppetboard/templates/_macros.html | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/puppetboard/templates/_macros.html b/puppetboard/templates/_macros.html index ce0ba89..8170ea6 100644 --- a/puppetboard/templates/_macros.html +++ b/puppetboard/templates/_macros.html @@ -53,11 +53,16 @@ value: 0, } ] - var fact_values = data.map(function(item) { return [item.label, item.value]; }).filter(function(item){return item[0];}); + var fact_values = data.map(function(item) { return [item.label, item.value]; }).filter(function(item){return item[0];}).sort(function(a,b){return a[1] - b[1];}); + var realdata = fact_values.slice(0, 15); + var otherdata = fact_values.slice(15); + if (otherdata.length > 0) { + realdata.push(["other", otherdata.reduce(function(a,b){return a + b[1];},0)]); + } var chart = c3.generate({ bindto: '#factChart', data: { - columns: fact_values, + columns: realdata, type : 'pie', } });