Use ticks consistently (#6873)

This commit is contained in:
Jukka Kurkela
2019-12-31 00:14:55 +02:00
committed by Evert Timberg
parent 1cda96946b
commit dbd835f4f3
6 changed files with 12 additions and 17 deletions

View File

@@ -53,7 +53,7 @@ function computeMinSampleSize(scale, pixels) {
min = Math.min(min, Math.abs(pixels[i] - pixels[i - 1]));
}
for (i = 0, ilen = scale.getTicks().length; i < ilen; ++i) {
for (i = 0, ilen = scale.ticks.length; i < ilen; ++i) {
curr = scale.getPixelForTick(i);
min = i > 0 ? Math.min(min, Math.abs(curr - prev)) : min;
prev = curr;

View File

@@ -78,7 +78,7 @@ class CategoryScale extends Scale {
if (index < 0 || index > ticks.length - 1) {
return null;
}
return this.getPixelForValue(index * me._numLabels / ticks.length + this.min);
return me.getPixelForValue(index * me._numLabels / ticks.length + me.min);
}
getValueForPixel(pixel) {

View File

@@ -63,11 +63,11 @@ class LinearScale extends LinearScaleBase {
}
getPixelForTick(index) {
var ticks = this._tickValues;
const ticks = this.ticks;
if (index < 0 || index > ticks.length - 1) {
return null;
}
return this.getPixelForValue(ticks[index]);
return this.getPixelForValue(ticks[index].value);
}
}

View File

@@ -231,15 +231,9 @@ class LinearScaleBase extends Scale {
return ticks;
}
generateTickLabels(ticks) {
var me = this;
me._tickValues = ticks.map(t => t.value);
Scale.prototype.generateTickLabels.call(me, ticks);
}
_configure() {
var me = this;
var ticks = me.getTicks();
var ticks = me.ticks;
var start = me.min;
var end = me.max;
var offset;

View File

@@ -450,7 +450,7 @@ class RadialLinearScale extends LinearScaleBase {
if (gridLineOpts.display) {
me.ticks.forEach(function(tick, index) {
if (index !== 0) {
offset = me.getDistanceFromCenterForValue(me._tickValues[index]);
offset = me.getDistanceFromCenterForValue(me.ticks[index].value);
drawRadiusLine(me, gridLineOpts, offset, index);
}
});
@@ -508,7 +508,7 @@ class RadialLinearScale extends LinearScaleBase {
return;
}
offset = me.getDistanceFromCenterForValue(me._tickValues[index]);
offset = me.getDistanceFromCenterForValue(me.ticks[index].value);
if (tickOpts.showLabelBackdrop) {
width = ctx.measureText(tick.label).width;

View File

@@ -703,10 +703,11 @@ class TimeScale extends Scale {
}
getPixelForTick(index) {
const ticks = this.getTicks();
return index >= 0 && index < ticks.length ?
this.getPixelForValue(ticks[index].value) :
null;
const ticks = this.ticks;
if (index < 0 || index > ticks.length - 1) {
return null;
}
return this.getPixelForValue(ticks[index].value);
}
getValueForPixel(pixel) {