From 29e3dd404d8ff0d4332a34d159df8246786702e0 Mon Sep 17 00:00:00 2001 From: x4base Date: Thu, 28 Jul 2016 13:39:29 -0500 Subject: [PATCH] Let the user decide the label type of pie charts (#819) --- caravel/assets/visualizations/nvd3_vis.js | 5 +++-- caravel/forms.py | 15 +++++++++++++++ caravel/viz.py | 2 ++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/caravel/assets/visualizations/nvd3_vis.js b/caravel/assets/visualizations/nvd3_vis.js index 7a60740346..b7512e7349 100644 --- a/caravel/assets/visualizations/nvd3_vis.js +++ b/caravel/assets/visualizations/nvd3_vis.js @@ -117,9 +117,10 @@ function nvd3Vis(slice) { chart.valueFormat(f); if (fd.donut) { chart.donut(true); - chart.labelsOutside(true); } - chart.labelsOutside(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.cornerRadius(true); break; diff --git a/caravel/forms.py b/caravel/forms.py index cb45d21df8..6499747b7c 100755 --- a/caravel/forms.py +++ b/caravel/forms.py @@ -695,6 +695,16 @@ class FormFactory(object): "default": 'linear', "description": _("Line interpolation as defined by d3.js") }), + 'pie_label_type': (SelectField, { + "label": _("Label Type"), + "default": 'key', + "choices": ( + ('key', _("Category Name")), + ('value', _("Value")), + ('percent', _("Percentage")), + ), + "description": _("What should be shown on the label?") + }), 'code': (TextAreaField, { "label": _("Code"), "description": _("Put your code here"), @@ -789,6 +799,11 @@ class FormFactory(object): "default": False, "description": _("Do you want a donut or a pie?") }), + 'labels_outside': (BetterBooleanField, { + "label": _("Put labels outside"), + "default": True, + "description": _("Put the labels outside the pie?") + }), 'contribution': (BetterBooleanField, { "label": _("Contribution"), "default": False, diff --git a/caravel/viz.py b/caravel/viz.py index 3259280adb..6abd85bd2b 100755 --- a/caravel/viz.py +++ b/caravel/viz.py @@ -1175,7 +1175,9 @@ class DistributionPieViz(NVD3Viz): 'fields': ( 'metrics', 'groupby', 'limit', + 'pie_label_type', ('donut', 'show_legend'), + 'labels_outside', ) },)