Permalink
Browse files

Avoid combining a single pie slice into 'other'.

Resolves #638.
  • Loading branch information...
dnschnur committed Feb 27, 2013
1 parent ab6e4a9 commit 64b28faf0d2e4345c7cd6da6f943009a94dde7d7
Showing with 11 additions and 5 deletions.
  1. +11 −5 jquery.flot.pie.js
View
@@ -195,23 +195,29 @@ More detail and specific examples can be found in the included HTML file.
data[i].data = [value];
}
- // Calculate the total of all slices, so we can show percentages
+ // Sum up all the slices, so we can calculate percentages for each
for (var i = 0; i < data.length; ++i) {
total += data[i].data[0][1];
}
- for (var i = 0; i < data.length; ++i) {
+ // Count the number of slices with percentages below the combine
+ // threshold; if it turns out to be just one, we won't combine.
+ for (var i = 0; i < data.length; ++i) {
var value = data[i].data[0][1];
-
if (value / total <= options.series.pie.combine.threshold) {
combined += value;
numCombined++;
if (!color) {
color = data[i].color;
}
- } else {
+ }
+ }
+
+ for (var i = 0; i < data.length; ++i) {
+ var value = data[i].data[0][1];
+ if (numCombined < 2 || value / total > options.series.pie.combine.threshold) {
newdata.push({
data: [[1, value]],
color: data[i].color,
@@ -222,7 +228,7 @@ More detail and specific examples can be found in the included HTML file.
}
}
- if (numCombined > 0) {
+ if (numCombined > 1) {
newdata.push({
data: [[1, combined]],
color: color,

0 comments on commit 64b28fa

Please sign in to comment.