From: Evert Timberg Date: Thu, 24 Sep 2015 22:53:48 +0000 (-0400) Subject: Fix scale fitting to give padding around the scale title & to account for label rotation X-Git-Tag: 2.0.0-alpha4~12^2~13 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f1b704a419f3c9d7b59691e576e6ee66f75c2442;p=thirdparty%2FChart.js.git Fix scale fitting to give padding around the scale title & to account for label rotation --- diff --git a/src/core/core.scale.js b/src/core/core.scale.js index b11ed5f98..4a7347a04 100644 --- a/src/core/core.scale.js +++ b/src/core/core.scale.js @@ -204,6 +204,15 @@ this.minSize.height = this.maxHeight; // fill all the height } + // Are we showing a title for the scale? + if (this.options.scaleLabel.show) { + if (this.isHorizontal()) { + this.minSize.height += (this.options.scaleLabel.fontSize * 1.5); + } else { + this.minSize.width += (this.options.scaleLabel.fontSize * 1.5); + } + } + this.paddingLeft = 0; this.paddingRight = 0; this.paddingTop = 0; @@ -217,7 +226,9 @@ if (this.isHorizontal()) { // A horizontal axis is more constrained by the height. var maxLabelHeight = this.maxHeight - this.minSize.height; - var labelHeight = 1.5 * this.options.ticks.fontSize; + var longestLabelWidth = helpers.longestText(this.ctx, labelFont, this.ticks); + var labelHeight = (Math.sin(helpers.toRadians(this.labelRotation)) * longestLabelWidth) + 1.5 * this.options.ticks.fontSize; + this.minSize.height = Math.min(this.maxHeight, this.minSize.height + labelHeight); labelFont = helpers.fontString(this.options.ticks.fontSize, this.options.ticks.fontStyle, this.options.ticks.fontFamily);