]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Re-enable this; turns out I was mislead by the label spacing 1863/head
authorMorley Zhi <morley@motown.office.okcupid.com>
Thu, 7 Jan 2016 17:41:42 +0000 (12:41 -0500)
committerMorley Zhi <morley@motown.office.okcupid.com>
Thu, 7 Jan 2016 17:41:42 +0000 (12:41 -0500)
src/core/core.scale.js

index acee9222b8598c75c0ae24dabc8b03631a759f66..d9fa3f92f5c2bbf5afe8796be6660eeffea92ee9 100644 (file)
                                var scaleLabelY;
                                var useAutoskipper = this.options.ticks.autoSkip;
 
+
+                               // figure out the maximum number of gridlines to show
+                               var maxTicks;
+
+                               if (this.options.ticks.maxTicksLimit) {
+                                       maxTicks = this.options.ticks.maxTicksLimit;
+                               }
+
                                // Make sure we draw text in the correct color and font
                                this.ctx.fillStyle = this.options.ticks.fontColor;
                                var labelFont = helpers.fontString(this.options.ticks.fontSize, this.options.ticks.fontStyle, this.options.ticks.fontFamily);
                                        if (!useAutoskipper) {
                                                skipRatio = false;
                                        }
+
+                                       // if they defined a max number of ticks, 
+                                       // increase skipRatio until that number is met
+                                       if (maxTicks) {
+                                               while (!skipRatio || this.ticks.length / (skipRatio || 1) > maxTicks) {
+                                                       if (!skipRatio) {
+                                                               skipRatio = 1;
+                                                       }
+                                                       skipRatio += 1;
+                                               }
+                                       }
                                        
                                        helpers.each(this.ticks, function(label, index) {
                                                // Blank ticks
-                                               if ((skipRatio > 1 && index % skipRatio > 0) || (label === undefined || label === null)) {
+                                               var isLastTick = this.ticks.length == index + 1;
+                                               var shouldSkip = skipRatio > 1 && index % skipRatio > 0;
+                                               if (shouldSkip && !isLastTick || (label === undefined || label === null)) {
                                                        return;
                                                }
                                                var xLineValue = this.getPixelForTick(index); // xvalues for grid lines