]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
getPixelForTick cleanup (#7225)
authorBen McCann <322311+benmccann@users.noreply.github.com>
Fri, 27 Mar 2020 23:48:04 +0000 (16:48 -0700)
committerGitHub <noreply@github.com>
Fri, 27 Mar 2020 23:48:04 +0000 (19:48 -0400)
src/core/core.scale.js
src/scales/scale.category.js
src/scales/scale.linear.js
src/scales/scale.logarithmic.js
src/scales/scale.time.js

index 606bf0cd646964e03b8d0fad4017a6b7d27b9ab2..567a62973e968f43caf35bda2f347e348a5b39e2 100644 (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);
        }
 
        /**
index 9c998b00c2ffadcd0e13399400b04e5c795c38a8..57aa5439bd0176651777948d5e5e54fa91524830 100644 (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;
index a2a4adccac9bce65441203a02e7b3dc1a274b686..7bff8231101b01040e88bc60efa6b3e7bcbc43e5 100644 (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);
-       }
 }
index 2b0d5cba0d9ec0456b8195d369e00e558c35a508..2c750c059cc0f8c5b024920aa08d04c8e6b6a389 100644 (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
         */
index 054d76d95cdaef60d50437c247b07d5457016a88..945bcc08210f6cac6a1f5a7476d4e61b4c73a565 100644 (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}