From 55c549d86f6c6ba6a207cee17a5595783945c1b9 Mon Sep 17 00:00:00 2001 From: Maxime Beauchemin Date: Fri, 17 Jun 2016 12:31:20 -0700 Subject: [PATCH] Adding option for reduceXTicks (#640) --- caravel/assets/visualizations/nvd3_vis.js | 11 ++++++++--- caravel/forms.py | 12 +++++++++++- caravel/viz.py | 2 ++ 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/caravel/assets/visualizations/nvd3_vis.js b/caravel/assets/visualizations/nvd3_vis.js index 201537425e..ba205ab3a1 100644 --- a/caravel/assets/visualizations/nvd3_vis.js +++ b/caravel/assets/visualizations/nvd3_vis.js @@ -36,6 +36,7 @@ function nvd3Vis(slice) { var fd = payload.form_data; var viz_type = fd.viz_type; var f = d3.format('.3s'); + var reduceXTicks = fd.reduce_x_ticks || false; nv.addGraph(function () { switch (viz_type) { @@ -63,7 +64,9 @@ function nvd3Vis(slice) { .showControls(true) .groupSpacing(0.1); - width = barchartWidth(); + if (!reduceXTicks) { + width = barchartWidth(); + } chart.width(width); chart.xAxis .showMaxMin(false) @@ -75,7 +78,7 @@ function nvd3Vis(slice) { case 'dist_bar': chart = nv.models.multiBarChart() .showControls(true) //Allow user to switch between 'Grouped' and 'Stacked' mode. - .reduceXTicks(false) + .reduceXTicks(reduceXTicks) .rotateLabels(45) .groupSpacing(0.1); //Distance between each group of bars. @@ -83,7 +86,9 @@ function nvd3Vis(slice) { .showMaxMin(false); chart.stacked(fd.bar_stacked); - width = barchartWidth(); + if (!reduceXTicks) { + width = barchartWidth(); + } chart.width(width); break; diff --git a/caravel/forms.py b/caravel/forms.py index 220d2129aa..97a833e9f7 100644 --- a/caravel/forms.py +++ b/caravel/forms.py @@ -225,6 +225,16 @@ class FormFactory(object): "default": False, "description": "" }), + 'reduce_x_ticks': (BetterBooleanField, { + "label": _("Reduce X ticks"), + "default": False, + "description": ( + "Reduces the number of X axis ticks to be rendered. " + "If true, the x axis wont overflow and labels may be " + "missing. If false, a minimum width will be applied " + "to columns and the width may overflow into an " + "horizontal scroll."), + }), 'include_series': (BetterBooleanField, { "label": _("Include Series"), "default": False, @@ -562,7 +572,7 @@ class FormFactory(object): "default": '', }), 'y_axis_label': (TextField, { - "label": _("X Axis Label"), + "label": _("Y Axis Label"), "default": '', }), 'where': (TextField, { diff --git a/caravel/viz.py b/caravel/viz.py index ebeea92f78..c8e4d3b429 100644 --- a/caravel/viz.py +++ b/caravel/viz.py @@ -1075,6 +1075,7 @@ class NVD3TimeSeriesBarViz(NVD3TimeSeriesViz): ('line_interpolation', 'bar_stacked'), ('x_axis_showminmax', 'bottom_margin'), ('x_axis_label', 'y_axis_label'), + ('reduce_x_ticks', None), ), }] + [NVD3TimeSeriesViz.fieldsets[2]] @@ -1158,6 +1159,7 @@ class DistributionBarViz(DistributionPieViz): ('show_legend', 'bar_stacked'), ('y_axis_format', 'bottom_margin'), ('x_axis_label', 'y_axis_label'), + ('reduce_x_ticks', None), ) },) form_overrides = {