From bb9a6fdcd0678056f153d3b2f529217bd6e1fe48 Mon Sep 17 00:00:00 2001 From: Jukka Kurkela Date: Wed, 8 May 2019 16:55:04 +0300 Subject: [PATCH 1/3] Vertical time scale generates too few ticks --- src/scales/scale.time.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/scales/scale.time.js b/src/scales/scale.time.js index 2e9c14b8e22..bde8753355a 100644 --- a/src/scales/scale.time.js +++ b/src/scales/scale.time.js @@ -765,7 +765,9 @@ module.exports = Scale.extend({ var sinRotation = Math.sin(angle); var tickFontSize = valueOrDefault(ticksOpts.fontSize, defaults.global.defaultFontSize); - return (tickLabelWidth * cosRotation) + (tickFontSize * sinRotation); + return me.isHorizontal() + ? (tickLabelWidth * cosRotation) + (tickFontSize * sinRotation) + : (tickLabelWidth * sinRotation) + (tickFontSize * cosRotation); }, /** From 8640cc46f0808d3322fc2dbdcb23f9272b4a8190 Mon Sep 17 00:00:00 2001 From: Jukka Kurkela Date: Wed, 8 May 2019 19:59:14 +0300 Subject: [PATCH 2/3] _getLabelSize() --- src/scales/scale.time.js | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/scales/scale.time.js b/src/scales/scale.time.js index bde8753355a..85ff696ceb7 100644 --- a/src/scales/scale.time.js +++ b/src/scales/scale.time.js @@ -753,10 +753,9 @@ module.exports = Scale.extend({ }, /** - * Crude approximation of what the label width might be * @private */ - getLabelWidth: function(label) { + _getLabelSize: function(label) { var me = this; var ticksOpts = me.options.ticks; var tickLabelWidth = me.ctx.measureText(label).width; @@ -765,9 +764,18 @@ module.exports = Scale.extend({ var sinRotation = Math.sin(angle); var tickFontSize = valueOrDefault(ticksOpts.fontSize, defaults.global.defaultFontSize); - return me.isHorizontal() - ? (tickLabelWidth * cosRotation) + (tickFontSize * sinRotation) - : (tickLabelWidth * sinRotation) + (tickFontSize * cosRotation); + return { + w: (tickLabelWidth * cosRotation) + (tickFontSize * sinRotation), + h: (tickLabelWidth * sinRotation) + (tickFontSize * cosRotation) + }; + }, + + /** + * Crude approximation of what the label width might be + * @private + */ + getLabelWidth: function(label) { + return this._getLabelSize(label).w; }, /** @@ -781,17 +789,15 @@ module.exports = Scale.extend({ // pick the longest format (milliseconds) for guestimation var format = displayFormats[timeOpts.unit] || displayFormats.millisecond; - var exampleLabel = me.tickFormatFunction(exampleTime, 0, [], format); - var tickLabelWidth = me.getLabelWidth(exampleLabel); + var size = me._getLabelSize(exampleLabel); // Using margins instead of padding because padding is not calculated // at this point (buildTicks). Margins are provided from previous calculation // in layout steps 5/6 - var innerWidth = me.isHorizontal() - ? me.width - (margins.left + margins.right) - : me.height - (margins.top + margins.bottom); - var capacity = Math.floor(innerWidth / tickLabelWidth); + var capacity = Math.floor(me.isHorizontal() + ? (me.width - margins.left - margins.right) / size.w + : (me.height - margins.top - margins.bottom) / size.h); return capacity > 0 ? capacity : 1; } From 505576cae1659834e1ba8d063ca030f22831dcc1 Mon Sep 17 00:00:00 2001 From: Jukka Kurkela Date: Thu, 9 May 2019 14:33:42 +0300 Subject: [PATCH 3/3] Account for options.offset --- src/scales/scale.time.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/scales/scale.time.js b/src/scales/scale.time.js index 85ff696ceb7..5b25653a70f 100644 --- a/src/scales/scale.time.js +++ b/src/scales/scale.time.js @@ -799,6 +799,10 @@ module.exports = Scale.extend({ ? (me.width - margins.left - margins.right) / size.w : (me.height - margins.top - margins.bottom) / size.h); + if (me.options.offset) { + capacity--; + } + return capacity > 0 ? capacity : 1; } });