diff --git a/docs/01-Scales.md b/docs/01-Scales.md index 06f406a43..5bcab3303 100644 --- a/docs/01-Scales.md +++ b/docs/01-Scales.md @@ -62,6 +62,7 @@ afterUpdate | Function | undefined | Callback that runs at the end of the update *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 diff --git a/src/core/core.scale.js b/src/core/core.scale.js index acd712eb5..3269fe118 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; }, @@ -441,6 +442,7 @@ var skipRatio; var scaleLabelX; var scaleLabelY; + var useAutoskipper = this.options.ticks.autoSkip; // Make sure we draw text in the correct color and font this.ctx.fillStyle = this.options.ticks.fontColor; @@ -456,6 +458,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)) { 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 65b7444da..64c4e3a44 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 2a9400852..29b077130 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,