]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Auto Skip Labels Attempt 1
authorTanner Linsley <tannerlinsley@gmail.com>
Tue, 7 Jul 2015 02:28:05 +0000 (22:28 -0400)
committerTanner Linsley <tannerlinsley@gmail.com>
Tue, 7 Jul 2015 02:28:05 +0000 (22:28 -0400)
src/scales/scale.category.js

index 2b233048f853ed1988971c36de53c84e38ffdd36..b375c25ddec782aeffabc563b0765819fe1ed875 100644 (file)
 
                                //Allow 3 pixels x2 padding either side for label readability
                                // only the index matters for a dataset scale, but we want a consistent interface between scales
-                               var gridWidth = Math.floor(this.getPixelForValue(0, 1) - this.getPixelForValue(0, 0)) - 6;
+
+                               var datasetWidth = 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 <= 90) {
+                               while (this.labelWidth > datasetWidth && this.labelRotation <= 40) {
                                        cosRotation = Math.cos(helpers.toRadians(this.labelRotation));
                                        sinRotation = Math.sin(helpers.toRadians(this.labelRotation));
 
                                        var yTickStart = this.options.position == "bottom" ? this.top : this.bottom - 10;
                                        var yTickEnd = this.options.position == "bottom" ? this.top + 10 : this.bottom;
                                        var isRotated = this.labelRotation !== 0;
+                                       var skipRatio = false;
+
+                                       if ((this.options.labels.fontSize + 4) * this.labels.length > (this.width - (this.paddingLeft + this.paddingRight))) {
+                                               skipRatio = 1 + Math.floor(((this.options.labels.fontSize + 4) * this.labels.length) / (this.width - (this.paddingLeft + this.paddingRight)));
+                                       }
 
                                        helpers.each(this.labels, function(label, index) {
+                                               if (skipRatio > 1 && index % skipRatio > 0) {
+                                                       return;
+                                               }
                                                var xLineValue = this.getPixelForValue(label, index, null, false); // xvalues for grid lines
                                                var xLabelValue = this.getPixelForValue(label, index, null, true); // x values for labels (need to consider offsetLabel option)