From 2bb9efd00b055931aab92a81a7dbde48ffb1ad94 Mon Sep 17 00:00:00 2001
From: Paul Rosenzweig <paulrosenzweig@users.noreply.github.com>
Date: Wed, 5 Jun 2019 14:37:04 -0400
Subject: [PATCH] fix bug with one zero value row (#10082)

---
 .../visualizations/PieChart.jsx               | 35 +++++++++----------
 1 file changed, 16 insertions(+), 19 deletions(-)

diff --git a/frontend/src/metabase/visualizations/visualizations/PieChart.jsx b/frontend/src/metabase/visualizations/visualizations/PieChart.jsx
index e13e92df616..e0fab8883d5 100644
--- a/frontend/src/metabase/visualizations/visualizations/PieChart.jsx
+++ b/frontend/src/metabase/visualizations/visualizations/PieChart.jsx
@@ -247,26 +247,23 @@ export default class PieChart extends Component {
       .partition(d => d.percentage > sliceThreshold)
       .value();
 
-    let otherSlice;
-    if (others.length > 1) {
-      let otherTotal = others.reduce((acc, o) => acc + o.value, 0);
-      if (otherTotal > 0) {
-        otherSlice = {
-          key: "Other",
-          value: otherTotal,
-          percentage: otherTotal / total,
-          color: colors["text-light"],
-        };
-        slices.push(otherSlice);
+    const otherTotal = others.reduce((acc, o) => acc + o.value, 0);
+    // Multiple others get squashed together under the key "Other"
+    let otherSlice =
+      others.length === 1
+        ? others[0]
+        : {
+            key: "Other",
+            value: otherTotal,
+            percentage: otherTotal / total,
+            color: colors["text-light"],
+          };
+    if (otherSlice.value > 0) {
+      // increase "other" slice so it's barely visible
+      if (otherSlice.percentage < OTHER_SLICE_MIN_PERCENTAGE) {
+        otherSlice.value = total * OTHER_SLICE_MIN_PERCENTAGE;
       }
-    } else {
-      slices.push(...others);
-    }
-
-    // increase "other" slice so it's barely visible
-    // $FlowFixMe
-    if (otherSlice && otherSlice.percentage < OTHER_SLICE_MIN_PERCENTAGE) {
-      otherSlice.value = total * OTHER_SLICE_MIN_PERCENTAGE;
+      slices.push(otherSlice);
     }
 
     let legendTitles = slices.map(slice => [
-- 
GitLab