From 90b7a47cc86846ebdff7ca98f09e1d975dea338d Mon Sep 17 00:00:00 2001 From: Ben McCann <322311+benmccann@users.noreply.github.com> Date: Sun, 23 Jun 2019 21:02:10 -0700 Subject: [PATCH] AutoSkip in update --- src/core/core.scale.js | 36 ++++++++++++++++++++++++---------- test/specs/scale.time.tests.js | 3 +-- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/src/core/core.scale.js b/src/core/core.scale.js index 298d409aa8e..0ddfd267f99 100644 --- a/src/core/core.scale.js +++ b/src/core/core.scale.js @@ -240,8 +240,17 @@ var Scale = Element.extend({ helpers.callback(this.options.beforeUpdate, [this]); }, + /** + * @param {number} maxWidth - the max width in pixels + * @param {number} maxHeight - the max height in pixels + * @param {object} margins - the space between the edge of the scale and edge of the chart + * This space comes from two sources: + * - padding - space that's required to show the labels at the edges of the scale + * - thickness of scales or legends in another orientation + */ update: function(maxWidth, maxHeight, margins) { var me = this; + var optionTicks = me.options.ticks; var i, ilen, labels, label, ticks, tick; // Update Lifecycle - Probably don't want to ever extend or overwrite this function ;) @@ -325,9 +334,12 @@ var Scale = Element.extend({ me.beforeFit(); me.fit(); me.afterFit(); - // + // Auto-skip + me._ticks = optionTicks.display && optionTicks.autoSkip ? me._autoSkip(me.getTicks()) : me.getTicks(); + me.afterUpdate(); + // TODO: remove minSize as a public property and return value from all layout boxes. It is unused return me.minSize; }, @@ -465,6 +477,7 @@ var Scale = Element.extend({ height: 0 }; + var chart = me.chart; var ticks = me.getTicks(); var opts = me.options; var tickOpts = opts.ticks; @@ -553,8 +566,13 @@ var Scale = Element.extend({ me.handleMargins(); - me.width = minSize.width; - me.height = minSize.height; + if (isHorizontal) { + me.width = chart.width - me.margins.left - me.margins.right; + me.height = minSize.height; + } else { + me.width = minSize.width; + me.height = chart.height - me.margins.top - me.margins.bottom; + } }, /** @@ -563,12 +581,10 @@ var Scale = Element.extend({ */ handleMargins: function() { var me = this; - if (me.margins) { - me.margins.left = Math.max(me.paddingLeft, me.margins.left); - me.margins.top = Math.max(me.paddingTop, me.margins.top); - me.margins.right = Math.max(me.paddingRight, me.margins.right); - me.margins.bottom = Math.max(me.paddingBottom, me.margins.bottom); - } + me.margins.left = Math.max(me.paddingLeft, me.margins.left); + me.margins.top = Math.max(me.paddingTop, me.margins.top); + me.margins.right = Math.max(me.paddingRight, me.margins.right); + me.margins.bottom = Math.max(me.paddingBottom, me.margins.bottom); }, afterFit: function() { @@ -834,7 +850,7 @@ var Scale = Element.extend({ var isMirrored = optionTicks.mirror; var isHorizontal = me.isHorizontal(); - var ticks = optionTicks.display && optionTicks.autoSkip ? me._autoSkip(me.getTicks()) : me.getTicks(); + var ticks = me.getTicks(); var tickFonts = parseTickFontOptions(optionTicks); var tickPadding = optionTicks.padding; var labelOffset = optionTicks.labelOffset; diff --git a/test/specs/scale.time.tests.js b/test/specs/scale.time.tests.js index 8939dcb78a7..37652337bd0 100755 --- a/test/specs/scale.time.tests.js +++ b/test/specs/scale.time.tests.js @@ -600,10 +600,9 @@ describe('Time scale tests', function() { }], } } - }); + }, {canvas: {width: 800, height: 200}}); this.scale = this.chart.scales.xScale0; - this.scale.update(800, 200); }); it('should be bounded by nearest step\'s year start and end', function() {