Skip to content

Commit fed37b6

Browse files
committed
Simplify setting of ticks
1 parent cb74d66 commit fed37b6

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

src/core/core.scale.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ var Scale = Element.extend({
251251
update: function(maxWidth, maxHeight, margins) {
252252
var me = this;
253253
var optionTicks = me.options.ticks;
254-
var i, ilen, labels, label, ticks, tick;
254+
var i, ilen, labels, ticks;
255255

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

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

298298
// Allow modification of ticks in callback.
299-
ticks = me.afterBuildTicks(ticks) || ticks;
299+
if (ticks) {
300+
ticks = me.afterBuildTicks(ticks);
301+
} else {
302+
// Support old implementations (that modified `this.ticks` directly in buildTicks)
303+
me.ticks = me.afterBuildTicks(me.ticks);
304+
}
300305

301306
me.beforeTickToLabelConversion();
302307

@@ -311,20 +316,21 @@ var Scale = Element.extend({
311316

312317
// IMPORTANT: from this point, we consider that `this.ticks` will NEVER change!
313318

314-
// BACKWARD COMPAT: synchronize `_ticks` with labels (so potentially `this.ticks`)
315-
for (i = 0, ilen = labels.length; i < ilen; ++i) {
316-
label = labels[i];
317-
tick = ticks[i];
318-
if (!tick) {
319+
if (!ticks) {
320+
ticks = [];
321+
for (i = 0, ilen = labels.length; i < ilen; ++i) {
319322
ticks.push({
320-
label: label,
323+
value: me.ticks[i],
321324
major: false
322325
});
323-
} else {
324-
tick.label = label;
325326
}
326327
}
327328

329+
// BACKWARD COMPAT: synchronize `_ticks` with labels (so potentially `this.ticks`)
330+
for (i = 0, ilen = labels.length; i < ilen; ++i) {
331+
ticks[i].label = labels[i];
332+
}
333+
328334
me._ticks = ticks;
329335

330336
// Tick Rotation
@@ -395,13 +401,7 @@ var Scale = Element.extend({
395401
buildTicks: helpers.noop,
396402
afterBuildTicks: function(ticks) {
397403
var me = this;
398-
// ticks is empty for old axis implementations here
399-
if (helpers.isArray(ticks) && ticks.length) {
400-
return helpers.callback(me.options.afterBuildTicks, [me, ticks]);
401-
}
402-
// Support old implementations (that modified `this.ticks` directly in buildTicks)
403-
me.ticks = helpers.callback(me.options.afterBuildTicks, [me, me.ticks]) || me.ticks;
404-
return ticks;
404+
return helpers.callback(me.options.afterBuildTicks, [me, ticks]) || ticks;
405405
},
406406

407407
beforeTickToLabelConversion: function() {

0 commit comments

Comments
 (0)