From cd024349434e10822e52ca7d42d634c4644695d8 Mon Sep 17 00:00:00 2001 From: Tore Lervik Date: Mon, 21 Dec 2015 23:30:40 +0100 Subject: [PATCH 1/3] Refactored skipRatio to use the longest label text for calculation. --- src/core/core.scale.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/core.scale.js b/src/core/core.scale.js index 3269fe118..2ef412ba3 100644 --- a/src/core/core.scale.js +++ b/src/core/core.scale.js @@ -454,8 +454,8 @@ var yTickEnd = this.options.position === "bottom" ? this.top + 10 : this.bottom; skipRatio = false; - if ((this.options.ticks.fontSize + 4) * this.ticks.length > (this.width - (this.paddingLeft + this.paddingRight))) { - skipRatio = 1 + Math.floor(((this.options.ticks.fontSize + 4) * this.ticks.length) / (this.width - (this.paddingLeft + this.paddingRight))); + if ((this.options.ticks.fontSize * maxLength) * this.ticks.length > (this.width - (this.paddingLeft + this.paddingRight))) { + skipRatio = 1 + Math.floor((((this.options.ticks.fontSize * maxLength / 2) + (this.options.ticks.autoSkipPadding || 20)) * this.ticks.length) / (this.width - (this.paddingLeft + this.paddingRight))); } if (!useAutoskipper) { From d134394a1d7e7038667b75d4309f18b55c67827c Mon Sep 17 00:00:00 2001 From: Tore Lervik Date: Mon, 21 Dec 2015 23:37:09 +0100 Subject: [PATCH 2/3] Refactored out property --- src/core/core.scale.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/core/core.scale.js b/src/core/core.scale.js index 2ef412ba3..32c63922b 100644 --- a/src/core/core.scale.js +++ b/src/core/core.scale.js @@ -47,6 +47,7 @@ reverse: false, display: true, autoSkip: true, + autoSkipPadding: 20, callback: function(value) { return '' + value; }, @@ -455,7 +456,7 @@ skipRatio = false; if ((this.options.ticks.fontSize * maxLength) * this.ticks.length > (this.width - (this.paddingLeft + this.paddingRight))) { - skipRatio = 1 + Math.floor((((this.options.ticks.fontSize * maxLength / 2) + (this.options.ticks.autoSkipPadding || 20)) * this.ticks.length) / (this.width - (this.paddingLeft + this.paddingRight))); + skipRatio = 1 + Math.floor((((this.options.ticks.fontSize * maxLength / 2) + this.options.ticks.autoSkipPadding) * this.ticks.length) / (this.width - (this.paddingLeft + this.paddingRight))); } if (!useAutoskipper) { From 0437968a4e0ebacdabd160d7fb2238115a27f250 Mon Sep 17 00:00:00 2001 From: Tore Lervik Date: Mon, 21 Dec 2015 23:47:38 +0100 Subject: [PATCH 3/3] Fixed broken tests --- test/core.helpers.tests.js | 6 ++++-- test/scale.category.tests.js | 3 ++- test/scale.linear.tests.js | 3 ++- test/scale.logarithmic.tests.js | 3 ++- test/scale.radialLinear.tests.js | 3 ++- test/scale.time.tests.js | 3 ++- 6 files changed, 14 insertions(+), 7 deletions(-) diff --git a/test/core.helpers.tests.js b/test/core.helpers.tests.js index 5547de774..0e18c7a5c 100644 --- a/test/core.helpers.tests.js +++ b/test/core.helpers.tests.js @@ -244,7 +244,8 @@ 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 + autoSkip: true, + autoSkipPadding: 20 }, type: 'linear' }, { @@ -281,7 +282,8 @@ 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 + autoSkip: true, + autoSkipPadding: 20 }, type: 'linear' }] diff --git a/test/scale.category.tests.js b/test/scale.category.tests.js index 002b27fbc..e844e9aee 100644 --- a/test/scale.category.tests.js +++ b/test/scale.category.tests.js @@ -43,7 +43,8 @@ describe('Category scale tests', function() { reverse: false, display: true, callback: defaultConfig.ticks.callback, // make this nicer, then check explicitly below - autoSkip: true + autoSkip: true, + autoSkipPadding: 20 } }); diff --git a/test/scale.linear.tests.js b/test/scale.linear.tests.js index 64c4e3a44..5ca84951a 100644 --- a/test/scale.linear.tests.js +++ b/test/scale.linear.tests.js @@ -42,7 +42,8 @@ describe('Linear Scale', function() { reverse: false, display: true, callback: defaultConfig.ticks.callback, // make this work nicer, then check below - autoSkip: true + autoSkip: true, + autoSkipPadding: 20 } }); diff --git a/test/scale.logarithmic.tests.js b/test/scale.logarithmic.tests.js index 29b077130..fac226a53 100644 --- a/test/scale.logarithmic.tests.js +++ b/test/scale.logarithmic.tests.js @@ -41,7 +41,8 @@ describe('Logarithmic Scale tests', function() { reverse: false, display: true, callback: defaultConfig.ticks.callback, // make this nicer, then check explicitly below - autoSkip: true + autoSkip: true, + autoSkipPadding: 20 }, }); diff --git a/test/scale.radialLinear.tests.js b/test/scale.radialLinear.tests.js index e165daa84..f0c48aa27 100644 --- a/test/scale.radialLinear.tests.js +++ b/test/scale.radialLinear.tests.js @@ -58,7 +58,8 @@ describe('Test the radial linear scale', function() { showLabelBackdrop: true, display: true, callback: defaultConfig.ticks.callback, // make this nicer, then check explicitly below - autoSkip: true + autoSkip: true, + autoSkipPadding: 20 }, }); diff --git a/test/scale.time.tests.js b/test/scale.time.tests.js index 912402e07..ed3810dc8 100644 --- a/test/scale.time.tests.js +++ b/test/scale.time.tests.js @@ -46,7 +46,8 @@ describe('Time scale tests', function() { reverse: false, display: true, callback: defaultConfig.ticks.callback, // make this nicer, then check explicitly below, - autoSkip: true + autoSkip: true, + autoSkipPadding: 20 }, time: { format: false,