getPixelForTick cleanup (#7225)

This commit is contained in:
Ben McCann
2020-03-27 16:48:04 -07:00
committed by GitHub
parent 40a11914f5
commit 0e196fc514
5 changed files with 7 additions and 36 deletions

View File

@@ -960,14 +960,11 @@ export default class Scale extends Element {
* @return {number}
*/
getPixelForTick(index) {
const me = this;
const offset = me.options.offset;
const numTicks = me.ticks.length;
const tickWidth = 1 / Math.max(numTicks - (offset ? 0 : 1), 1);
return index < 0 || index > numTicks - 1
? null
: me.getPixelForDecimal(index * tickWidth + (offset ? tickWidth / 2 : 0));
const ticks = this.ticks;
if (index < 0 || index > ticks.length - 1) {
return null;
}
return this.getPixelForValue(ticks[index].value);
}
/**

View File

@@ -88,6 +88,8 @@ export default class CategoryScale extends Scale {
return me.getPixelForDecimal((value - me._startValue) / me._valueRange);
}
// Must override base implementation becuase it calls getPixelForValue
// and category scale can have duplicate values
getPixelForTick(index) {
const me = this;
const ticks = me.ticks;

View File

@@ -66,12 +66,4 @@ export default class LinearScale extends LinearScaleBase {
getValueForPixel(pixel) {
return this._startValue + this.getDecimalForPixel(pixel) * this._valueRange;
}
getPixelForTick(index) {
const ticks = this.ticks;
if (index < 0 || index > ticks.length - 1) {
return null;
}
return this.getPixelForValue(ticks[index].value);
}
}

View File

@@ -158,14 +158,6 @@ export default class LogarithmicScale extends Scale {
return value === undefined ? '0' : new Intl.NumberFormat(this.options.locale).format(value);
}
getPixelForTick(index) {
const ticks = this.ticks;
if (index < 0 || index > ticks.length - 1) {
return null;
}
return this.getPixelForValue(ticks[index].value);
}
/**
* @protected
*/

View File

@@ -757,18 +757,6 @@ export default class TimeScale extends Scale {
return me.getPixelForDecimal((offsets.start + pos) * offsets.factor);
}
/**
* @param {number} index
* @return {number}
*/
getPixelForTick(index) {
const ticks = this.ticks;
if (index < 0 || index > ticks.length - 1) {
return null;
}
return this.getPixelForValue(ticks[index].value);
}
/**
* @param {number} pixel
* @return {number}