From a1c84203bdcfe56078f094163056a36338547719 Mon Sep 17 00:00:00 2001 From: David Schnur Date: Sun, 3 Feb 2013 12:46:45 -0500 Subject: [PATCH] Moved fixData and calcData into combine. They're small and not used anywhere else, so keeping them in separate functions only serves to increase complexity. --- jquery.flot.pie.js | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/jquery.flot.pie.js b/jquery.flot.pie.js index cea9429..dfd51da 100644 --- a/jquery.flot.pie.js +++ b/jquery.flot.pie.js @@ -178,15 +178,6 @@ More detail and specific examples can be found in the included HTML file. alert(msg); } - function calcTotal(data) { - for (var i = 0; i < data.length; ++i) { - var item = parseFloat(data[i].data[0][1]); - if (item) { - total += item; - } - } - } - function processDatapoints(plot, series, data, datapoints) { if (!processed) { processed = true; @@ -224,7 +215,15 @@ More detail and specific examples can be found in the included HTML file. } } - function fixData(data) { + function combine(data) { + + var combined = 0, + numCombined = 0, + color = options.series.pie.combine.color, + newdata = []; + + // Fix up the raw data from Flot, eliminating undefined values + for (var i = 0; i < data.length; ++i) { if (typeof(data[i].data) == "number") { data[i].data = [[1, data[i].data]]; @@ -235,18 +234,15 @@ More detail and specific examples can be found in the included HTML file. data[i].data = [[1, 0]]; } } - return data; - } - function combine(data) { + // Calculate the total of all slices, so we can show percentages - data = fixData(data); - calcTotal(data); - - var combined = 0; - var numCombined = 0; - var color = options.series.pie.combine.color; - var newdata = []; + for (var i = 0; i < data.length; ++i) { + var item = parseFloat(data[i].data[0][1]); + if (item) { + total += item; + } + } for (var i = 0; i < data.length; ++i) {