From a966487a3f3a3cc53ddc721146d61a12ad33d018 Mon Sep 17 00:00:00 2001 From: Vera Liu Date: Wed, 19 Oct 2016 15:00:17 -0700 Subject: [PATCH 1/2] Added order bars option for dist_bar viz --- caravel/assets/visualizations/nvd3_vis.js | 12 +++++++++++- caravel/forms.py | 5 +++++ caravel/viz.py | 1 + 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/caravel/assets/visualizations/nvd3_vis.js b/caravel/assets/visualizations/nvd3_vis.js index 7d8dbfa25a548..09ceac6e08618 100644 --- a/caravel/assets/visualizations/nvd3_vis.js +++ b/caravel/assets/visualizations/nvd3_vis.js @@ -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); diff --git a/caravel/forms.py b/caravel/forms.py index 638d9f5344176..c0e934ee4ac28 100755 --- a/caravel/forms.py +++ b/caravel/forms.py @@ -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" + }), 'show_controls': (BetterBooleanField, { "label": _("Extra Controls"), "default": False, diff --git a/caravel/viz.py b/caravel/viz.py index e384ec4d90956..fa153397b0623 100755 --- a/caravel/viz.py +++ b/caravel/viz.py @@ -1316,6 +1316,7 @@ class DistributionBarViz(DistributionPieViz): ('y_axis_format', 'bottom_margin'), ('x_axis_label', 'y_axis_label'), ('reduce_x_ticks', 'contribution'), + ('order_bars'), ('show_controls', None), ) },) From fa53dcb9ef0592890ee295caba5b637ece554ffe Mon Sep 17 00:00:00 2001 From: Vera Liu Date: Thu, 20 Oct 2016 13:43:24 -0700 Subject: [PATCH 2/2] Make order_bar checkbox to cover half the colum and translate the description --- caravel/forms.py | 2 +- caravel/viz.py | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/caravel/forms.py b/caravel/forms.py index c0e934ee4ac28..e3415d353b84d 100755 --- a/caravel/forms.py +++ b/caravel/forms.py @@ -250,7 +250,7 @@ def __init__(self, viz): 'order_bars': (BetterBooleanField, { "label": _("Sort Bars"), "default": False, - "description": "Sort bars by x labels" + "description": _("Sort bars by x labels."), }), 'show_controls': (BetterBooleanField, { "label": _("Extra Controls"), diff --git a/caravel/viz.py b/caravel/viz.py index fa153397b0623..dbdd9af9c51b7 100755 --- a/caravel/viz.py +++ b/caravel/viz.py @@ -1316,8 +1316,7 @@ class DistributionBarViz(DistributionPieViz): ('y_axis_format', 'bottom_margin'), ('x_axis_label', 'y_axis_label'), ('reduce_x_ticks', 'contribution'), - ('order_bars'), - ('show_controls', None), + ('show_controls', 'order_bars'), ) },) form_overrides = {