This is an automated email from the ASF dual-hosted git repository.

maximebeauchemin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-superset.git


The following commit(s) were added to refs/heads/master by this push:
     new f8cc05b  Added label+percent and label+value display options to pie 
chart (#3565)
f8cc05b is described below

commit f8cc05b54edbd119bccc26837ac99f6c3d6078d1
Author: Jeff Niu <jeffni...@gmail.com>
AuthorDate: Mon Oct 2 15:53:11 2017 -0700

    Added label+percent and label+value display options to pie chart (#3565)
---
 superset/assets/javascripts/explore/stores/controls.jsx |  2 ++
 superset/assets/visualizations/nvd3_vis.js              | 13 ++++++++++---
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/superset/assets/javascripts/explore/stores/controls.jsx 
b/superset/assets/javascripts/explore/stores/controls.jsx
index c5ad432..92faad1 100644
--- a/superset/assets/javascripts/explore/stores/controls.jsx
+++ b/superset/assets/javascripts/explore/stores/controls.jsx
@@ -943,6 +943,8 @@ export const controls = {
       ['key', 'Category Name'],
       ['value', 'Value'],
       ['percent', 'Percentage'],
+      ['key_value', 'Category and Value'],
+      ['key_percent', 'Category and Percentage'],
     ],
     description: t('What should be shown on the label?'),
   },
diff --git a/superset/assets/visualizations/nvd3_vis.js 
b/superset/assets/visualizations/nvd3_vis.js
index fd147ee..1353968 100644
--- a/superset/assets/visualizations/nvd3_vis.js
+++ b/superset/assets/visualizations/nvd3_vis.js
@@ -230,14 +230,21 @@ function nvd3Vis(slice, payload) {
           chart.donut(true);
         }
         chart.labelsOutside(fd.labels_outside);
-        chart.labelThreshold(0.05)  // Configure the minimum slice size for 
labels to show up
-          .labelType(fd.pie_label_type);
+        chart.labelThreshold(0.05);  // Configure the minimum slice size for 
labels to show up
+        if (fd.pie_label_type !== 'key_percent' && fd.pie_label_type !== 
'key_value') {
+          chart.labelType(fd.pie_label_type);
+        } else if (fd.pie_label_type === 'key_value') {
+          chart.labelType(d => `${d.data.x}: ${d3.format('.3s')(d.data.y)}`);
+        }
         chart.cornerRadius(true);
 
-        if (fd.pie_label_type === 'percent') {
+        if (fd.pie_label_type === 'percent' || fd.pie_label_type === 
'key_percent') {
           let total = 0;
           data.forEach((d) => { total += d.y; });
           chart.tooltip.valueFormatter(d => `${((d / total) * 
100).toFixed()}%`);
+          if (fd.pie_label_type === 'key_percent') {
+            chart.labelType(d => `${d.data.x}: ${((d.data.y / total) * 
100).toFixed()}%`);
+          }
         }
 
         break;

-- 
To stop receiving notification emails like this one, please contact
['"comm...@superset.apache.org" <comm...@superset.apache.org>'].

Reply via email to