Skip to content

Commit

Permalink
Let the user decide the label type of pie charts (#819)
Browse files Browse the repository at this point in the history
  • Loading branch information
x4base authored and mistercrunch committed Jul 28, 2016
1 parent 1101de5 commit 29e3dd4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
5 changes: 3 additions & 2 deletions caravel/assets/visualizations/nvd3_vis.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
15 changes: 15 additions & 0 deletions caravel/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,16 @@ def __init__(self, viz):
"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"),
Expand Down Expand Up @@ -789,6 +799,11 @@ def __init__(self, viz):
"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,
Expand Down
2 changes: 2 additions & 0 deletions caravel/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -1175,7 +1175,9 @@ class DistributionPieViz(NVD3Viz):
'fields': (
'metrics', 'groupby',
'limit',
'pie_label_type',
('donut', 'show_legend'),
'labels_outside',
)
},)

Expand Down

0 comments on commit 29e3dd4

Please sign in to comment.