Skip to content

Commit

Permalink
Adding option for reduceXTicks (#640)
Browse files Browse the repository at this point in the history
  • Loading branch information
mistercrunch committed Jun 17, 2016
1 parent 78eb1e6 commit 55c549d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
11 changes: 8 additions & 3 deletions caravel/assets/visualizations/nvd3_vis.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand All @@ -75,15 +78,17 @@ 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.

chart.xAxis
.showMaxMin(false);

chart.stacked(fd.bar_stacked);
width = barchartWidth();
if (!reduceXTicks) {
width = barchartWidth();
}
chart.width(width);
break;

Expand Down
12 changes: 11 additions & 1 deletion caravel/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,16 @@ def __init__(self, viz):
"default": False,
"description": ""
}),
'reduce_x_ticks': (BetterBooleanField, {
"label": _("Reduce X ticks"),
"default": False,
"description": (

This comment has been minimized.

Copy link
@xrmx

xrmx Jun 18, 2016

Contributor

Missing _ to make this translatable

This comment has been minimized.

Copy link
@mistercrunch

mistercrunch Jun 18, 2016

Author Member

oh right, good catch

"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,
Expand Down Expand Up @@ -562,7 +572,7 @@ def __init__(self, viz):
"default": '',
}),
'y_axis_label': (TextField, {
"label": _("X Axis Label"),
"label": _("Y Axis Label"),
"default": '',
}),
'where': (TextField, {
Expand Down
2 changes: 2 additions & 0 deletions caravel/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]]


Expand Down Expand Up @@ -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 = {
Expand Down

0 comments on commit 55c549d

Please sign in to comment.