From 04d1f0f710059fe46ab20e3237689dcfd4db99ce Mon Sep 17 00:00:00 2001 From: Evert Timberg Date: Sun, 23 Aug 2015 13:20:43 -0400 Subject: [PATCH] Category scale filter function will hide the grid line if `null` or `undefined` returned. --- docs/00-Getting-Started.md | 3 +++ samples/line-x-axis-filter.html | 2 +- src/scales/scale.category.js | 3 ++- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/docs/00-Getting-Started.md b/docs/00-Getting-Started.md index 83b3cf691..5aeac0a1b 100644 --- a/docs/00-Getting-Started.md +++ b/docs/00-Getting-Started.md @@ -403,6 +403,9 @@ The `userCallback` method may be useful when there are a lot of labels. The foll xAxes: [{ labels: { maxRotation: 0, // set maxRotation to 0 to turn off auto-rotation + + // Return an empty string to draw the grid line but hide the label + // Return `null` or `undefined` to hide the grid line userCallback: function(labelString, index) { return (index % 5 === 0) ? labelString : ''; } diff --git a/samples/line-x-axis-filter.html b/samples/line-x-axis-filter.html index 3b5b82f28..71a1b8844 100644 --- a/samples/line-x-axis-filter.html +++ b/samples/line-x-axis-filter.html @@ -55,7 +55,7 @@ display: true, labels: { userCallback: function(dataLabel, index) { - return index % 2 === 0 ? dataLabel : ''; + return index % 2 === 0 ? dataLabel : null; } } }], diff --git a/src/scales/scale.category.js b/src/scales/scale.category.js index d97699c1f..7912f8dcb 100644 --- a/src/scales/scale.category.js +++ b/src/scales/scale.category.js @@ -230,7 +230,8 @@ } helpers.each(this.labels, function(label, index) { - if (skipRatio > 1 && index % skipRatio > 0) { + // Blank labels + if ((skipRatio > 1 && index % skipRatio > 0) || (label === undefined || label === null)) { return; } var xLineValue = this.getPixelForValue(label, index, null, false); // xvalues for grid lines -- 2.47.2