Optimization: prevent double ticks array reverse for vertical logarithmic axis (#5076)

with ticks option 'reverse: true'.
This commit is contained in:
jcopperfield 2017-12-23 14:34:55 +01:00 committed by Evert Timberg
parent ce1fc28b74
commit 92d033beb2

View File

@ -161,6 +161,7 @@ module.exports = function(Chart) {
var me = this; var me = this;
var opts = me.options; var opts = me.options;
var tickOpts = opts.ticks; var tickOpts = opts.ticks;
var reverse = !me.isHorizontal();
var generationOptions = { var generationOptions = {
min: tickOpts.min, min: tickOpts.min,
@ -168,25 +169,22 @@ module.exports = function(Chart) {
}; };
var ticks = me.ticks = Ticks.generators.logarithmic(generationOptions, me); 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 // At this point, we need to update our max and min given the tick values since we have expanded the
// range of the scale // range of the scale
me.max = helpers.max(ticks); me.max = helpers.max(ticks);
me.min = helpers.min(ticks); me.min = helpers.min(ticks);
if (tickOpts.reverse) { if (tickOpts.reverse) {
ticks.reverse(); reverse = !reverse;
me.start = me.max; me.start = me.max;
me.end = me.min; me.end = me.min;
} else { } else {
me.start = me.min; me.start = me.min;
me.end = me.max; me.end = me.max;
} }
if (reverse) {
ticks.reverse();
}
}, },
convertTicksToLabels: function() { convertTicksToLabels: function() {
this.tickValues = this.ticks.slice(); this.tickValues = this.ticks.slice();