Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/getting-started/v3-migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,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
Expand Down
14 changes: 0 additions & 14 deletions src/core/core.helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions src/core/core.scale.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 isNullOrUndef = helpers.isNullOrUndef;
const valueOrDefault = helpers.valueOrDefault;
Expand Down Expand Up @@ -976,7 +977,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);
};
Expand Down Expand Up @@ -1137,7 +1137,6 @@ class Scale extends Element {

var ctx = me.ctx;
var chart = me.chart;
var alignPixel = helpers._alignPixel;
var context = {
scale: me,
tick: me._ticksToDraw[0],
Expand Down
30 changes: 21 additions & 9 deletions src/helpers/helpers.canvas.js
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -229,5 +243,3 @@ var exports = {
target.y);
}
};

module.exports = exports;