]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Include helpers._alignPixel only once (#6735)
authorBen McCann <322311+benmccann@users.noreply.github.com>
Thu, 14 Nov 2019 12:17:29 +0000 (04:17 -0800)
committerEvert Timberg <evert.timberg+github@gmail.com>
Thu, 14 Nov 2019 12:17:29 +0000 (07:17 -0500)
docs/getting-started/v3-migration.md
src/core/core.helpers.js
src/core/core.scale.js
src/helpers/helpers.canvas.js

index 66486cf804ce3af47f5c152d134e0e9a62d5f7f3..4d8f0f77968afff59fdb5400070001436be1d4ae 100644 (file)
@@ -91,6 +91,10 @@ Chart.js is no longer providing the `Chart.bundle.js` and `Chart.bundle.min.js`.
 * `TimeScale.tickFormatFunction` was renamed to `TimeScale._tickFormatFunction`
 * `TimeScale.getPixelForOffset` was renamed to `TimeScale._getPixelForOffset`
 
+#### Renamed private APIs
+
+* `helpers._alignPixel` was renamed to `helpers.canvas._alignPixel`
+
 ### Changed
 
 #### Scales
index 84c7379353248494a54c2feffdea78b102c4a2bf..9f86f2199fb83cbceb9f2457b391fa3e195e563e 100644 (file)
@@ -152,20 +152,6 @@ module.exports = function() {
                return Math.sqrt(Math.pow(pt2.x - pt1.x, 2) + Math.pow(pt2.y - pt1.y, 2));
        };
 
-       /**
-        * Returns the aligned pixel value to avoid anti-aliasing blur
-        * @param {Chart} chart - The chart instance.
-        * @param {number} pixel - A pixel value.
-        * @param {number} width - The width of the element.
-        * @returns {number} The aligned pixel value.
-        * @private
-        */
-       helpers._alignPixel = function(chart, pixel, width) {
-               var devicePixelRatio = chart.currentDevicePixelRatio;
-               var halfWidth = width / 2;
-               return Math.round((pixel - halfWidth) * devicePixelRatio) / devicePixelRatio + halfWidth;
-       };
-
        helpers.splineCurve = function(firstPoint, middlePoint, afterPoint, t) {
                // Props to Rob Spencer at scaled innovation for his post on splining between points
                // http://scaledinnovation.com/analytics/splines/aboutSplines.html
index cd2bcb3b507963c8cb1a0d377519052d05085e8f..89d8d1c853964bf74399037085546d0c9b33927c 100644 (file)
@@ -5,6 +5,7 @@ const Element = require('./core.element');
 const helpers = require('../helpers/index');
 const Ticks = require('./core.ticks');
 
+const alignPixel = helpers.canvas._alignPixel;
 const isArray = helpers.isArray;
 const isFinite = helpers.isFinite;
 const isNullOrUndef = helpers.isNullOrUndef;
@@ -998,7 +999,6 @@ class Scale extends Element {
                };
                var axisWidth = gridLines.drawBorder ? resolve([gridLines.lineWidth, 0], context, 0) : 0;
                var axisHalfWidth = axisWidth / 2;
-               var alignPixel = helpers._alignPixel;
                var alignBorderValue = function(pixel) {
                        return alignPixel(chart, pixel, axisWidth);
                };
@@ -1159,7 +1159,6 @@ class Scale extends Element {
 
                var ctx = me.ctx;
                var chart = me.chart;
-               var alignPixel = helpers._alignPixel;
                var context = {
                        scale: me,
                        tick: me.ticks[0],
index 221e7de2cad555f119f5431c7a60e593851027aa..2a3b4cba0c6874b84f5a2c51dac2aa7d54d9d4e7 100644 (file)
@@ -1,16 +1,30 @@
 'use strict';
 
-var PI = Math.PI;
-var RAD_PER_DEG = PI / 180;
-var DOUBLE_PI = PI * 2;
-var HALF_PI = PI / 2;
-var QUARTER_PI = PI / 4;
-var TWO_THIRDS_PI = PI * 2 / 3;
+const PI = Math.PI;
+const RAD_PER_DEG = PI / 180;
+const DOUBLE_PI = PI * 2;
+const HALF_PI = PI / 2;
+const QUARTER_PI = PI / 4;
+const TWO_THIRDS_PI = PI * 2 / 3;
 
 /**
  * @namespace Chart.helpers.canvas
  */
-var exports = {
+module.exports = {
+       /**
+        * Returns the aligned pixel value to avoid anti-aliasing blur
+        * @param {Chart} chart - The chart instance.
+        * @param {number} pixel - A pixel value.
+        * @param {number} width - The width of the element.
+        * @returns {number} The aligned pixel value.
+        * @private
+        */
+       _alignPixel: function(chart, pixel, width) {
+               const devicePixelRatio = chart.currentDevicePixelRatio;
+               const halfWidth = width / 2;
+               return Math.round((pixel - halfWidth) * devicePixelRatio) / devicePixelRatio + halfWidth;
+       },
+
        /**
         * Clears the entire canvas associated to the given `chart`.
         * @param {Chart} chart - The chart for which to clear the canvas.
@@ -229,5 +243,3 @@ var exports = {
                        target.y);
        }
 };
-
-module.exports = exports;