]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Category scale label rotation improvements
authorEvert Timberg <evert.timberg@gmail.com>
Sat, 20 Jun 2015 00:24:14 +0000 (20:24 -0400)
committerEvert Timberg <evert.timberg@gmail.com>
Sat, 20 Jun 2015 00:24:14 +0000 (20:24 -0400)
src/scales/scale.category.js

index ffac6fe21000e4189cdfcb39c987bc197e6ae642..7e861dfd7c22d2f46602059e2e3d1091a7cef4a8 100644 (file)
                                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));
 
                // @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 = {
                        // 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;