Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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