Commit 424ad4f6 by Dennis Jen

Stacked bars will hide labels if fewer than 3 characters can be displayed.

parent 7a71f0ec
...@@ -44,11 +44,14 @@ define(['d3', 'nvd3', 'underscore', 'utils/utils', 'views/chart-view'], ...@@ -44,11 +44,14 @@ define(['d3', 'nvd3', 'underscore', 'utils/utils', 'views/chart-view'],
var barWidth = d3.select(self.options.barSelector).attr('width'), // jshint ignore:line var barWidth = d3.select(self.options.barSelector).attr('width'), // jshint ignore:line
// this is a rough estimate of how wide a character is // this is a rough estimate of how wide a character is
chartWidth = 5, charWidth = 6,
characterLimit = Math.floor(barWidth / chartWidth), characterLimit = Math.floor(barWidth / charWidth),
formattedLabel = d; formattedLabel = d;
if (_(formattedLabel).size() > characterLimit) { if (characterLimit < 3) {
// no labels will be displayed if label space is limited
formattedLabel = '';
} else if (_(formattedLabel).size() > characterLimit) {
formattedLabel = Utils.truncateText(d, characterLimit); formattedLabel = Utils.truncateText(d, characterLimit);
} }
......
...@@ -19,7 +19,8 @@ define(['nvd3', 'underscore', 'views/discrete-bar-view'], ...@@ -19,7 +19,8 @@ define(['nvd3', 'underscore', 'views/discrete-bar-view'],
chart.stacked(true) chart.stacked(true)
.showControls(false) .showControls(false)
.showLegend(false); .showLegend(false)
.reduceXTicks(false); // shows all ticks
chart.tooltipContent(function(key, x, y, e) { chart.tooltipContent(function(key, x, y, e) {
var tips = []; var tips = [];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment