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
13 changes: 9 additions & 4 deletions caravel/assets/visualizations/nvd3_vis.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,14 @@ function nvd3Vis(slice) {
var render = function () {
d3.json(slice.jsonEndpoint(), function (error, payload) {
var width = slice.width();
var fd = payload.form_data;
var barchartWidth = function () {
var bars = d3.sum(payload.data, function (d) { return d.values.length; });
var bars;
if (fd.bar_stacked) {
bars = d3.max(payload.data, function (d) { return d.values.length; });
} else {
bars = d3.sum(payload.data, function (d) { return d.values.length; });
}
if (bars * minBarWidth > width) {
return bars * minBarWidth;
} else {
Expand All @@ -33,7 +39,6 @@ function nvd3Vis(slice) {
}
return '';
}
var fd = payload.form_data;
var viz_type = fd.viz_type;
var f = d3.format('.3s');
var reduceXTicks = fd.reduce_x_ticks || false;
Expand Down Expand Up @@ -61,7 +66,7 @@ function nvd3Vis(slice) {

case 'bar':
chart = nv.models.multiBarChart()
.showControls(true)
.showControls(false)
.groupSpacing(0.1);

if (!reduceXTicks) {
Expand All @@ -77,7 +82,7 @@ function nvd3Vis(slice) {

case 'dist_bar':
chart = nv.models.multiBarChart()
.showControls(true) //Allow user to switch between 'Grouped' and 'Stacked' mode.
.showControls(false) //Allow user to switch between 'Grouped' and 'Stacked' mode.
.reduceXTicks(reduceXTicks)
.rotateLabels(45)
.groupSpacing(0.1); //Distance between each group of bars.
Expand Down
2 changes: 1 addition & 1 deletion caravel/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def __init__(self, viz):
'reduce_x_ticks': (BetterBooleanField, {
"label": _("Reduce X ticks"),
"default": False,
"description": (
"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 "
Expand Down
6 changes: 5 additions & 1 deletion caravel/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -1159,7 +1159,7 @@ class DistributionBarViz(DistributionPieViz):
('show_legend', 'bar_stacked'),
('y_axis_format', 'bottom_margin'),
('x_axis_label', 'y_axis_label'),
('reduce_x_ticks', None),
('reduce_x_ticks', 'contribution'),
)
},)
form_overrides = {
Expand Down Expand Up @@ -1198,6 +1198,10 @@ def get_df(self, query_obj=None):
index=self.groupby,
columns=columns,
values=self.metrics)
if fd.get("contribution"):
pt = pt.fillna(0)
pt = pt.T
pt = (pt / pt.sum()).T
pt = pt.reindex(row.index)
return pt

Expand Down