From: Tanner Linsley Date: Mon, 21 Sep 2015 18:57:04 +0000 (-0600) Subject: Bar spacing is now dynamic at small sizes. X-Git-Tag: 2.0.0-alpha4~18^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=154083b8756e3b94c745def7fec8df709d8b2caa;p=thirdparty%2FChart.js.git Bar spacing is now dynamic at small sizes. Closes #1468 --- diff --git a/samples/bar.html b/samples/bar.html index 7f1d8e7ea..526fd8e5a 100644 --- a/samples/bar.html +++ b/samples/bar.html @@ -25,121 +25,120 @@

Legend

-
diff --git a/src/scales/scale.category.js b/src/scales/scale.category.js index 38a69c92e..1650d523c 100644 --- a/src/scales/scale.category.js +++ b/src/scales/scale.category.js @@ -73,11 +73,18 @@ // Functions needed for bar charts calculateBaseWidth: function() { - return (this.getPixelForValue(null, 1, 0, true) - this.getPixelForValue(null, 0, 0, true)) - (2 * this.options.categorySpacing); + var base = this.getPixelForValue(null, 1, 0, true) - this.getPixelForValue(null, 0, 0, true); + var spacing = 2 * this.options.categorySpacing; + if (base < spacing * 2) { + var mod = Math.min((spacing * 2) / base, 1.5); + base = (base / 2) * mod; + return base; + } + return base - spacing; }, calculateBarWidth: function(barDatasetCount) { //The padding between datasets is to the right of each bar, providing that there are more than 1 dataset - var baseWidth = this.calculateBaseWidth() - ((barDatasetCount - 1) * this.options.spacing); + var baseWidth = Math.max(this.calculateBaseWidth() - (this.options.stacked ? 0 : (barDatasetCount - 1) * this.options.spacing), 1); if (this.options.stacked) { return baseWidth;