From: John Walker Date: Fri, 22 Apr 2016 13:59:28 +0000 (+0100) Subject: Scaled bar width fix X-Git-Tag: 2.1.0~57^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F2326%2Fhead;p=thirdparty%2FChart.js.git Scaled bar width fix Add logic for calculating bar width when ticks are less than the data labels --- diff --git a/src/controllers/controller.bar.js b/src/controllers/controller.bar.js index 9574ed2e3..d0761f5b4 100644 --- a/src/controllers/controller.bar.js +++ b/src/controllers/controller.bar.js @@ -184,6 +184,12 @@ module.exports = function(Chart) { var categoryWidth = tickWidth * xScale.options.categoryPercentage; var categorySpacing = (tickWidth - (tickWidth * xScale.options.categoryPercentage)) / 2; var fullBarWidth = categoryWidth / datasetCount; + + if (xScale.ticks.length !== this.chart.data.labels.length) { + var perc = xScale.ticks.length / this.chart.data.labels.length; + fullBarWidth = fullBarWidth * perc; + } + var barWidth = fullBarWidth * xScale.options.barPercentage; var barSpacing = fullBarWidth - (fullBarWidth * xScale.options.barPercentage);