From: Ben McCann <322311+benmccann@users.noreply.github.com> Date: Thu, 14 Nov 2019 12:17:29 +0000 (-0800) Subject: Include helpers._alignPixel only once (#6735) X-Git-Tag: v3.0.0-alpha~239 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=64b47762429ac5f5752d5a1126baf10f3282369f;p=thirdparty%2FChart.js.git Include helpers._alignPixel only once (#6735) --- diff --git a/docs/getting-started/v3-migration.md b/docs/getting-started/v3-migration.md index 66486cf80..4d8f0f779 100644 --- a/docs/getting-started/v3-migration.md +++ b/docs/getting-started/v3-migration.md @@ -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 diff --git a/src/core/core.helpers.js b/src/core/core.helpers.js index 84c737935..9f86f2199 100644 --- a/src/core/core.helpers.js +++ b/src/core/core.helpers.js @@ -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 diff --git a/src/core/core.scale.js b/src/core/core.scale.js index cd2bcb3b5..89d8d1c85 100644 --- a/src/core/core.scale.js +++ b/src/core/core.scale.js @@ -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], diff --git a/src/helpers/helpers.canvas.js b/src/helpers/helpers.canvas.js index 221e7de2c..2a3b4cba0 100644 --- a/src/helpers/helpers.canvas.js +++ b/src/helpers/helpers.canvas.js @@ -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;