Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added checkbox in dist_bar viz to enable sorting of bars based on x axis labels #1379

Merged
merged 3 commits into from
Oct 28, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -247,6 +247,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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_("Sort bars by x labels"), for translation, and don't forget the trailing comma

}),
'show_controls': (BetterBooleanField, {
"label": _("Extra Controls"),
"default": False,
Expand Down
1 change: 1 addition & 0 deletions caravel/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -1316,6 +1316,7 @@ class DistributionBarViz(DistributionPieViz):
('y_axis_format', 'bottom_margin'),
('x_axis_label', 'y_axis_label'),
('reduce_x_ticks', 'contribution'),
('order_bars'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

('order_bars', None) will render using half the column so that the checkbox is not too far away from the label.

('show_controls', None),
)
},)
Expand Down