Include helpers._alignPixel only once (#6735)

This commit is contained in:
Ben McCann 2019-11-14 04:17:29 -08:00 committed by Evert Timberg
parent cb95a36b94
commit 64b4776242
4 changed files with 26 additions and 25 deletions

View 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

View 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

View 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],

View 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;