From d0d2bfce7cd269db45aec9f677a45e539762eee9 Mon Sep 17 00:00:00 2001 From: Ben McCann <322311+benmccann@users.noreply.github.com> Date: Thu, 27 Jun 2019 13:47:15 -0700 Subject: [PATCH] Address review comments --- src/core/core.scale.js | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/src/core/core.scale.js b/src/core/core.scale.js index 45c3caf357b..26f7b7e4c72 100644 --- a/src/core/core.scale.js +++ b/src/core/core.scale.js @@ -243,14 +243,14 @@ var Scale = Element.extend({ /** * @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 + * @param {object} margins - the space between the edge of the other scales 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 tickOpts = me.options.ticks; var i, ilen, labels, ticks; // Update Lifecycle - Probably don't want to ever extend or overwrite this function ;) @@ -301,6 +301,13 @@ var Scale = Element.extend({ } else { // Support old implementations (that modified `this.ticks` directly in buildTicks) me.ticks = me.afterBuildTicks(me.ticks); + ticks = []; + for (i = 0, ilen = me.ticks.length; i < ilen; ++i) { + ticks.push({ + value: me.ticks[i], + major: false + }); + } } me.beforeTickToLabelConversion(); @@ -312,20 +319,9 @@ var Scale = Element.extend({ me.afterTickToLabelConversion(); + // IMPORTANT: below this point, we consider that `this.ticks` will NEVER change! me.ticks = labels; // BACKWARD COMPATIBILITY - // IMPORTANT: from this point, we consider that `this.ticks` will NEVER change! - - if (!ticks) { - ticks = []; - for (i = 0, ilen = labels.length; i < ilen; ++i) { - ticks.push({ - value: me.ticks[i], - major: false - }); - } - } - // BACKWARD COMPAT: synchronize `_ticks` with labels (so potentially `this.ticks`) for (i = 0, ilen = labels.length; i < ilen; ++i) { ticks[i].label = labels[i]; @@ -342,7 +338,7 @@ var Scale = Element.extend({ me.fit(); me.afterFit(); // Auto-skip - me._ticks = optionTicks.display && optionTicks.autoSkip ? me._autoSkip(me.getTicks()) : me.getTicks(); + me._ticks = tickOpts.display && tickOpts.autoSkip ? me._autoSkip(me.getTicks()) : me.getTicks(); me.afterUpdate();