Skip to content

Commit

Permalink
Optimization: prevent double ticks array reverse for vertical logarit…
Browse files Browse the repository at this point in the history
…hmic axis (chartjs#5076)

with ticks option 'reverse: true'.
  • Loading branch information
jcopperfield authored and etimberg committed Dec 23, 2017
1 parent 4dccc37 commit cb90072
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/scales/scale.logarithmic.js
Expand Up @@ -161,32 +161,30 @@ module.exports = function(Chart) {
var me = this;
var opts = me.options;
var tickOpts = opts.ticks;
var reverse = !me.isHorizontal();

var generationOptions = {
min: tickOpts.min,
max: tickOpts.max
};
var ticks = me.ticks = Ticks.generators.logarithmic(generationOptions, me);

if (!me.isHorizontal()) {
// We are in a vertical orientation. The top value is the highest. So reverse the array
ticks.reverse();
}

// At this point, we need to update our max and min given the tick values since we have expanded the
// range of the scale
me.max = helpers.max(ticks);
me.min = helpers.min(ticks);

if (tickOpts.reverse) {
ticks.reverse();

reverse = !reverse;
me.start = me.max;
me.end = me.min;
} else {
me.start = me.min;
me.end = me.max;
}
if (reverse) {
ticks.reverse();
}
},
convertTicksToLabels: function() {
this.tickValues = this.ticks.slice();
Expand Down

0 comments on commit cb90072

Please sign in to comment.