]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Scaled bar width fix 2326/head
authorJohn Walker <mail@john-walker.co.uk>
Fri, 22 Apr 2016 13:59:28 +0000 (14:59 +0100)
committerJohn Walker <mail@john-walker.co.uk>
Fri, 22 Apr 2016 13:59:28 +0000 (14:59 +0100)
Add logic for calculating bar width when ticks are less than the data labels

src/controllers/controller.bar.js

index 9574ed2e37d9643238adc910d9446413b743f64a..d0761f5b4cdc9cb178a73bf2922d0e07edf9fe32 100644 (file)
@@ -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);