mirror of
https://github.com/chartjs/Chart.js.git
synced 2026-03-23 00:26:52 +01:00
getPixelForTick cleanup (#7225)
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
@@ -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}
|
||||
|
||||
Reference in New Issue
Block a user