]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Fix scale fitting to give padding around the scale title & to account for label rotation
authorEvert Timberg <evert.timberg@gmail.com>
Thu, 24 Sep 2015 22:53:48 +0000 (18:53 -0400)
committerEvert Timberg <evert.timberg@gmail.com>
Thu, 24 Sep 2015 22:53:48 +0000 (18:53 -0400)
src/core/core.scale.js

index b11ed5f98a51b6cdc9bcbe2135305a5f87ec285c..4a7347a046af0796f611dd8141c1715722cd405d 100644 (file)
                                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;
                                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);