Skip to content

Commit 0a5d681

Browse files
committed
Include helpers._alignPixel only once
1 parent 2354e2f commit 0a5d681

File tree

4 files changed

+26
-25
lines changed

4 files changed

+26
-25
lines changed

docs/getting-started/v3-migration.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ Chart.js is no longer providing the `Chart.bundle.js` and `Chart.bundle.min.js`.
8989
* `TimeScale.tickFormatFunction` was renamed to `TimeScale._tickFormatFunction`
9090
* `TimeScale.getPixelForOffset` was renamed to `TimeScale._getPixelForOffset`
9191

92+
#### Renamed private APIs
93+
94+
* `helpers._alignPixel` was renamed to `helpers.canvas._alignPixel`
95+
9296
### Changed
9397

9498
#### Scales

src/core/core.helpers.js

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -152,20 +152,6 @@ module.exports = function() {
152152
return Math.sqrt(Math.pow(pt2.x - pt1.x, 2) + Math.pow(pt2.y - pt1.y, 2));
153153
};
154154

155-
/**
156-
* Returns the aligned pixel value to avoid anti-aliasing blur
157-
* @param {Chart} chart - The chart instance.
158-
* @param {number} pixel - A pixel value.
159-
* @param {number} width - The width of the element.
160-
* @returns {number} The aligned pixel value.
161-
* @private
162-
*/
163-
helpers._alignPixel = function(chart, pixel, width) {
164-
var devicePixelRatio = chart.currentDevicePixelRatio;
165-
var halfWidth = width / 2;
166-
return Math.round((pixel - halfWidth) * devicePixelRatio) / devicePixelRatio + halfWidth;
167-
};
168-
169155
helpers.splineCurve = function(firstPoint, middlePoint, afterPoint, t) {
170156
// Props to Rob Spencer at scaled innovation for his post on splining between points
171157
// http://scaledinnovation.com/analytics/splines/aboutSplines.html

src/core/core.scale.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const Element = require('./core.element');
55
const helpers = require('../helpers/index');
66
const Ticks = require('./core.ticks');
77

8+
const alignPixel = helpers.canvas._alignPixel;
89
const isArray = helpers.isArray;
910
const isNullOrUndef = helpers.isNullOrUndef;
1011
const valueOrDefault = helpers.valueOrDefault;
@@ -976,7 +977,6 @@ class Scale extends Element {
976977
};
977978
var axisWidth = gridLines.drawBorder ? resolve([gridLines.lineWidth, 0], context, 0) : 0;
978979
var axisHalfWidth = axisWidth / 2;
979-
var alignPixel = helpers._alignPixel;
980980
var alignBorderValue = function(pixel) {
981981
return alignPixel(chart, pixel, axisWidth);
982982
};
@@ -1137,7 +1137,6 @@ class Scale extends Element {
11371137

11381138
var ctx = me.ctx;
11391139
var chart = me.chart;
1140-
var alignPixel = helpers._alignPixel;
11411140
var context = {
11421141
scale: me,
11431142
tick: me._ticksToDraw[0],

src/helpers/helpers.canvas.js

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,30 @@
11
'use strict';
22

3-
var PI = Math.PI;
4-
var RAD_PER_DEG = PI / 180;
5-
var DOUBLE_PI = PI * 2;
6-
var HALF_PI = PI / 2;
7-
var QUARTER_PI = PI / 4;
8-
var TWO_THIRDS_PI = PI * 2 / 3;
3+
const PI = Math.PI;
4+
const RAD_PER_DEG = PI / 180;
5+
const DOUBLE_PI = PI * 2;
6+
const HALF_PI = PI / 2;
7+
const QUARTER_PI = PI / 4;
8+
const TWO_THIRDS_PI = PI * 2 / 3;
99

1010
/**
1111
* @namespace Chart.helpers.canvas
1212
*/
13-
var exports = {
13+
module.exports = {
14+
/**
15+
* Returns the aligned pixel value to avoid anti-aliasing blur
16+
* @param {Chart} chart - The chart instance.
17+
* @param {number} pixel - A pixel value.
18+
* @param {number} width - The width of the element.
19+
* @returns {number} The aligned pixel value.
20+
* @private
21+
*/
22+
_alignPixel: function(chart, pixel, width) {
23+
const devicePixelRatio = chart.currentDevicePixelRatio;
24+
const halfWidth = width / 2;
25+
return Math.round((pixel - halfWidth) * devicePixelRatio) / devicePixelRatio + halfWidth;
26+
},
27+
1428
/**
1529
* Clears the entire canvas associated to the given `chart`.
1630
* @param {Chart} chart - The chart for which to clear the canvas.
@@ -229,5 +243,3 @@ var exports = {
229243
target.y);
230244
}
231245
};
232-
233-
module.exports = exports;

0 commit comments

Comments
 (0)