]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Fix tests
authorEvert Timberg <evert.timberg@gmail.com>
Tue, 22 Dec 2015 14:13:02 +0000 (09:13 -0500)
committerEvert Timberg <evert.timberg@gmail.com>
Tue, 22 Dec 2015 14:13:02 +0000 (09:13 -0500)
src/core/core.scale.js

index 32c63922bed79f7eedb64b5d746b63f0d7044379..1f3f624b5233c03cc4331a50cdd0e438cf2f24f1 100644 (file)
 
                                if (this.isHorizontal()) {
                                        // A horizontal axis is more constrained by the height.
-                                       var longestLabelWidth = helpers.longestText(this.ctx, labelFont, this.ticks);
+                                       this.longestLabelWidth = helpers.longestText(this.ctx, labelFont, this.ticks);
 
                                        // TODO - improve this calculation
-                                       var labelHeight = (Math.sin(helpers.toRadians(this.labelRotation)) * longestLabelWidth) + 1.5 * this.options.ticks.fontSize;
+                                       var labelHeight = (Math.sin(helpers.toRadians(this.labelRotation)) * this.longestLabelWidth) + 1.5 * this.options.ticks.fontSize;
 
                                        this.minSize.height = Math.min(this.maxHeight, this.minSize.height + labelHeight);
 
                                this.ctx.fillStyle = this.options.ticks.fontColor;
                                var labelFont = helpers.fontString(this.options.ticks.fontSize, this.options.ticks.fontStyle, this.options.ticks.fontFamily);
 
+                               var cosRotation = Math.cos(helpers.toRadians(this.labelRotation));
+                               var sinRotation = Math.sin(helpers.toRadians(this.labelRotation));
+                               var longestRotatedLabel = this.longestLabelWidth * cosRotation;
+                               var rotatedLabelHeight = this.options.ticks.fontSize * sinRotation;
+
                                if (this.isHorizontal()) {
                                        setContextLineSettings = true;
                                        var yTickStart = this.options.position === "bottom" ? this.top : this.bottom - 10;
                                        var yTickEnd = this.options.position === "bottom" ? this.top + 10 : this.bottom;
                                        skipRatio = false;
 
-                                       if ((this.options.ticks.fontSize * maxLength) * this.ticks.length > (this.width - (this.paddingLeft + this.paddingRight))) {
-                                           skipRatio = 1 + Math.floor((((this.options.ticks.fontSize * maxLength / 2) + this.options.ticks.autoSkipPadding) * this.ticks.length) / (this.width - (this.paddingLeft + this.paddingRight)));
+                                       if ((longestRotatedLabel + rotatedLabelHeight) * this.ticks.length > (this.width - (this.paddingLeft + this.paddingRight))) {
+                                           skipRatio = 1 + Math.floor((((longestRotatedLabel / 2) + this.options.ticks.autoSkipPadding) * this.ticks.length) / (this.width - (this.paddingLeft + this.paddingRight)));
                                        }
 
                                        if (!useAutoskipper) {