Skip to content

Commit 64b4776

Browse files
benmccannetimberg
authored andcommitted
Include helpers._alignPixel only once (#6735)
1 parent cb95a36 commit 64b4776

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
@@ -91,6 +91,10 @@ Chart.js is no longer providing the `Chart.bundle.js` and `Chart.bundle.min.js`.
9191
* `TimeScale.tickFormatFunction` was renamed to `TimeScale._tickFormatFunction`
9292
* `TimeScale.getPixelForOffset` was renamed to `TimeScale._getPixelForOffset`
9393

94+
#### Renamed private APIs
95+
96+
* `helpers._alignPixel` was renamed to `helpers.canvas._alignPixel`
97+
9498
### Changed
9599

96100
#### 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 isFinite = helpers.isFinite;
1011
const isNullOrUndef = helpers.isNullOrUndef;
@@ -998,7 +999,6 @@ class Scale extends Element {
998999
};
9991000
var axisWidth = gridLines.drawBorder ? resolve([gridLines.lineWidth, 0], context, 0) : 0;
10001001
var axisHalfWidth = axisWidth / 2;
1001-
var alignPixel = helpers._alignPixel;
10021002
var alignBorderValue = function(pixel) {
10031003
return alignPixel(chart, pixel, axisWidth);
10041004
};
@@ -1159,7 +1159,6 @@ class Scale extends Element {
11591159

11601160
var ctx = me.ctx;
11611161
var chart = me.chart;
1162-
var alignPixel = helpers._alignPixel;
11631162
var context = {
11641163
scale: me,
11651164
tick: me.ticks[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)