Skip to content

Commit

Permalink
Simplify setting of ticks
Browse files Browse the repository at this point in the history
  • Loading branch information
benmccann committed Jun 27, 2019
1 parent cb74d66 commit 90d4cea
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions src/core/core.scale.js
Expand Up @@ -251,7 +251,7 @@ var Scale = Element.extend({
update: function(maxWidth, maxHeight, margins) {
var me = this;
var optionTicks = me.options.ticks;
var i, ilen, labels, label, ticks, tick;
var i, ilen, labels, ticks;

// Update Lifecycle - Probably don't want to ever extend or overwrite this function ;)
me.beforeUpdate();
Expand Down Expand Up @@ -293,10 +293,15 @@ var Scale = Element.extend({

// New implementations should return an array of objects but for BACKWARD COMPAT,
// we still support no return (`this.ticks` internally set by calling this method).
ticks = me.buildTicks() || [];
ticks = me.buildTicks();

// Allow modification of ticks in callback.
ticks = me.afterBuildTicks(ticks) || ticks;
if (ticks) {
ticks = me.afterBuildTicks(ticks);
} else {
// Support old implementations (that modified `this.ticks` directly in buildTicks)
me.ticks = me.afterBuildTicks(me.ticks);
}

me.beforeTickToLabelConversion();

Expand All @@ -312,16 +317,17 @@ var Scale = Element.extend({
// IMPORTANT: from this point, we consider that `this.ticks` will NEVER change!

// BACKWARD COMPAT: synchronize `_ticks` with labels (so potentially `this.ticks`)
for (i = 0, ilen = labels.length; i < ilen; ++i) {
label = labels[i];
tick = ticks[i];
if (!tick) {
if (ticks) {
for (i = 0, ilen = labels.length; i < ilen; ++i) {
ticks[i].label = labels[i];
}
} else {
ticks = [];
for (i = 0, ilen = labels.length; i < ilen; ++i) {
ticks.push({
label: label,
label: labels[i],
major: false
});
} else {
tick.label = label;
}
}

Expand Down Expand Up @@ -395,13 +401,7 @@ var Scale = Element.extend({
buildTicks: helpers.noop,
afterBuildTicks: function(ticks) {
var me = this;
// ticks is empty for old axis implementations here
if (helpers.isArray(ticks) && ticks.length) {
return helpers.callback(me.options.afterBuildTicks, [me, ticks]);
}
// Support old implementations (that modified `this.ticks` directly in buildTicks)
me.ticks = helpers.callback(me.options.afterBuildTicks, [me, me.ticks]) || me.ticks;
return ticks;
return helpers.callback(me.options.afterBuildTicks, [me, ticks]) || ticks;
},

beforeTickToLabelConversion: function() {
Expand Down

0 comments on commit 90d4cea

Please sign in to comment.