From: Evert Timberg Date: Sat, 20 Jun 2015 00:24:14 +0000 (-0400) Subject: Category scale label rotation improvements X-Git-Tag: 2.0.0-alpha4~69^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=48be4edbdd0ed0f485abbf510c38d2225f4beed8;p=thirdparty%2FChart.js.git Category scale label rotation improvements --- diff --git a/src/scales/scale.category.js b/src/scales/scale.category.js index ffac6fe21..7e861dfd7 100644 --- a/src/scales/scale.category.js +++ b/src/scales/scale.category.js @@ -113,7 +113,7 @@ var gridWidth = Math.floor(this.getPixelForValue(0, 1) - this.getPixelForValue(0, 0)) - 6; //Max label rotate should be 90 - also act as a loop counter - while ((this.labelWidth > gridWidth && this.labelRotation === 0) || (this.labelWidth > gridWidth && this.labelRotation <= 90 && this.labelRotation > 0)) { + while (this.labelWidth > gridWidth && this.labelRotation <= 90) { cosRotation = Math.cos(helpers.toRadians(this.labelRotation)); sinRotation = Math.sin(helpers.toRadians(this.labelRotation)); @@ -157,6 +157,13 @@ // @param {number} maxHeight: the max height the axis can be // @return {object} minSize : the minimum size needed to draw the axis fit: function(maxWidth, maxHeight, margins) { + // Set the unconstrained dimension before label rotation + if (this.isHorizontal()) { + this.width = maxWidth; + } else { + this.height = maxHeight; + } + this.calculateLabelRotation(maxHeight, margins); var minSize = { @@ -170,17 +177,16 @@ // Width if (this.isHorizontal()) { minSize.width = maxWidth; - this.width = maxWidth; } else if (this.options.display) { minSize.width = Math.min(longestLabelWidth + 6, maxWidth); } // Height if (this.isHorizontal() && this.options.display) { - var labelHeight = (Math.cos(helpers.toRadians(this.labelRotation)) * longestLabelWidth) + 1.5 * this.options.labels.fontSize; + var labelHeight = (Math.sin(helpers.toRadians(this.labelRotation)) * longestLabelWidth) + 1.5 * this.options.labels.fontSize; minSize.height = Math.min(labelHeight, maxHeight); } else if (this.options.display) { - minSize.width = Math.min(longestLabelWidth + 6, maxWidth); + minSize.height = maxHeight; } this.width = minSize.width;