Skip to content

Commit

Permalink
Added checkbox in dist_bar viz to enable sorting of bars based on x a…
Browse files Browse the repository at this point in the history
…xis labels (#1379)

* Added order bars option for dist_bar viz

* Make order_bar checkbox to cover half the colum and translate the description
  • Loading branch information
vera-liu authored Oct 28, 2016
1 parent 6ab769f commit d2826ab
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
12 changes: 11 additions & 1 deletion caravel/assets/visualizations/nvd3_vis.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,17 @@ function nvd3Vis(slice) {

stacked = fd.bar_stacked;
chart.stacked(stacked);

if (fd.order_bars) {
payload.data.forEach((d) => {
d.values.sort(
function compare(a, b) {
if (a.x < b.x) return -1;
if (a.x > b.x) return 1;
return 0;
}
);
});
}
if (fd.show_bar_value) {
setTimeout(function () {
addTotalBarValues(chart, payload.data, stacked);
Expand Down
5 changes: 5 additions & 0 deletions caravel/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,11 @@ def __init__(self, viz):
"default": False,
"description": "Show the value on top of the bars or not"
}),
'order_bars': (BetterBooleanField, {
"label": _("Sort Bars"),
"default": False,
"description": _("Sort bars by x labels."),
}),
'show_controls': (BetterBooleanField, {
"label": _("Extra Controls"),
"default": False,
Expand Down
2 changes: 1 addition & 1 deletion caravel/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -1320,7 +1320,7 @@ class DistributionBarViz(DistributionPieViz):
('y_axis_format', 'bottom_margin'),
('x_axis_label', 'y_axis_label'),
('reduce_x_ticks', 'contribution'),
('show_controls', None),
('show_controls', 'order_bars'),
)
},)
form_overrides = {
Expand Down

0 comments on commit d2826ab

Please sign in to comment.