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 <sage@cat.pdx.edu>
Co-authored-by: Ryan Niebur <ryan@cat.pdx.edu>
This commit is contained in:
William Van Hevelingen
2014-06-30 19:30:36 -07:00
committed by William Van Hevelingen
parent 8e063e7f15
commit 3940c84de3

View File

@@ -53,11 +53,16 @@
value: 0, 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({ var chart = c3.generate({
bindto: '#factChart', bindto: '#factChart',
data: { data: {
columns: fact_values, columns: realdata,
type : 'pie', type : 'pie',
} }
}); });