From 23b2d991f7a6ec199c952f490ef906713398a1df Mon Sep 17 00:00:00 2001 From: Mattias Lyckne Date: Fri, 18 Dec 2015 16:18:49 +0100 Subject: [PATCH 1/4] disable autoSkip when there is a userCallback or autoSkip is set to false --- src/core/core.scale.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/core/core.scale.js b/src/core/core.scale.js index 6f15033e6..aa8b79d3e 100644 --- a/src/core/core.scale.js +++ b/src/core/core.scale.js @@ -46,6 +46,7 @@ padding: 10, reverse: false, display: true, + autoSkip: true, callback: function(value) { return '' + value; }, @@ -403,6 +404,11 @@ var skipRatio; var scaleLabelX; var scaleLabelY; + var useAutoskipper = this.options.ticks.autoSkip; + + if(this.options.ticks.userCallback) { + useAutoskipper = false; + } // Make sure we draw text in the correct color and font this.ctx.fillStyle = this.options.ticks.fontColor; @@ -418,6 +424,10 @@ skipRatio = 1 + Math.floor(((this.options.ticks.fontSize + 4) * this.ticks.length) / (this.width - (this.paddingLeft + this.paddingRight))); } + if (!useAutoskipper) { + skipRatio = false; + } + helpers.each(this.ticks, function(label, index) { // Blank ticks if ((skipRatio > 1 && index % skipRatio > 0) || (label === undefined || label === null)) { From dec4a5f57a75b8dfa96fc6f2f97ad4bc146b289c Mon Sep 17 00:00:00 2001 From: Mattias Lyckne Date: Mon, 21 Dec 2015 08:43:48 +0100 Subject: [PATCH 2/4] Fix tests --- test/core.helpers.tests.js | 2 ++ test/scale.category.tests.js | 1 + test/scale.linear.tests.js | 1 + test/scale.logarithmic.tests.js | 1 + test/scale.radialLinear.tests.js | 2 +- test/scale.time.tests.js | 3 ++- 6 files changed, 8 insertions(+), 2 deletions(-) diff --git a/test/core.helpers.tests.js b/test/core.helpers.tests.js index 6a68d9ec3..5547de774 100644 --- a/test/core.helpers.tests.js +++ b/test/core.helpers.tests.js @@ -244,6 +244,7 @@ describe('Core helper tests', function() { reverse: false, display: true, callback: merged.scales.yAxes[1].ticks.callback, // make it nicer, then check explicitly below + autoSkip: true }, type: 'linear' }, { @@ -280,6 +281,7 @@ describe('Core helper tests', function() { reverse: false, display: true, callback: merged.scales.yAxes[2].ticks.callback, // make it nicer, then check explicitly below + autoSkip: true }, type: 'linear' }] diff --git a/test/scale.category.tests.js b/test/scale.category.tests.js index 74b79045e..002b27fbc 100644 --- a/test/scale.category.tests.js +++ b/test/scale.category.tests.js @@ -43,6 +43,7 @@ describe('Category scale tests', function() { reverse: false, display: true, callback: defaultConfig.ticks.callback, // make this nicer, then check explicitly below + autoSkip: true } }); diff --git a/test/scale.linear.tests.js b/test/scale.linear.tests.js index ef1b2cbb9..cc5ba7b94 100644 --- a/test/scale.linear.tests.js +++ b/test/scale.linear.tests.js @@ -42,6 +42,7 @@ describe('Linear Scale', function() { reverse: false, display: true, callback: defaultConfig.ticks.callback, // make this work nicer, then check below + autoSkip: true } }); diff --git a/test/scale.logarithmic.tests.js b/test/scale.logarithmic.tests.js index 1f05388c6..eabaa8870 100644 --- a/test/scale.logarithmic.tests.js +++ b/test/scale.logarithmic.tests.js @@ -41,6 +41,7 @@ describe('Logarithmic Scale tests', function() { reverse: false, display: true, callback: defaultConfig.ticks.callback, // make this nicer, then check explicitly below + autoSkip: true }, }); diff --git a/test/scale.radialLinear.tests.js b/test/scale.radialLinear.tests.js index dc77aba98..e165daa84 100644 --- a/test/scale.radialLinear.tests.js +++ b/test/scale.radialLinear.tests.js @@ -58,7 +58,7 @@ describe('Test the radial linear scale', function() { showLabelBackdrop: true, display: true, callback: defaultConfig.ticks.callback, // make this nicer, then check explicitly below - + autoSkip: true }, }); diff --git a/test/scale.time.tests.js b/test/scale.time.tests.js index c67b92908..912402e07 100644 --- a/test/scale.time.tests.js +++ b/test/scale.time.tests.js @@ -45,7 +45,8 @@ describe('Time scale tests', function() { padding: 10, reverse: false, display: true, - callback: defaultConfig.ticks.callback, // make this nicer, then check explicitly below + callback: defaultConfig.ticks.callback, // make this nicer, then check explicitly below, + autoSkip: true }, time: { format: false, From 7363c6fcbe41c59386118d5b005de65d66fc1a13 Mon Sep 17 00:00:00 2001 From: Mattias Lyckne Date: Mon, 21 Dec 2015 13:59:29 +0100 Subject: [PATCH 3/4] Dont set autoSkip false if userCallback is defined MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ”The reason being is that the user could replace either callback or userCallbac” --- src/core/core.scale.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/core/core.scale.js b/src/core/core.scale.js index aa8b79d3e..42845ebd4 100644 --- a/src/core/core.scale.js +++ b/src/core/core.scale.js @@ -406,10 +406,6 @@ var scaleLabelY; var useAutoskipper = this.options.ticks.autoSkip; - if(this.options.ticks.userCallback) { - useAutoskipper = false; - } - // 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); From 888a8dd79792bf208c12d91527a4d82fab1992f7 Mon Sep 17 00:00:00 2001 From: Mattias Lyckne Date: Mon, 21 Dec 2015 14:21:51 +0100 Subject: [PATCH 4/4] Update docs --- docs/01-Scales.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/01-Scales.md b/docs/01-Scales.md index 5a4fcc63e..4e299e219 100644 --- a/docs/01-Scales.md +++ b/docs/01-Scales.md @@ -48,6 +48,7 @@ display | Boolean | true | If true, show the scale including gridlines, ticks, a *ticks*.suggestedMax | Number | - | User defined maximum number for the scale, overrides maximum value *except for if* it is lower than the maximum value. *ticks*.min | Number | - | User defined minimum number for the scale, overrides minimum value *ticks*.max | Number | - | User defined minimum number for the scale, overrides maximum value +*ticks*.autoSkip | Boolean | true | If true, automatically calculates how many labels that can be shown and hides labels accordingly. Turn it off to show all labels no matter what *ticks*.callback | Function | `function(value) { return '' + value; } ` | Returns the string representation of the tick value as it should be displayed on the chart. The `callback` method may be used for advanced tick customization. The following callback would display every label in scientific notation