Skip to content

Commit

Permalink
Make helpers.canvas.isPointInArea a private method
Browse files Browse the repository at this point in the history
  • Loading branch information
nagix committed Jan 4, 2019
1 parent 4541312 commit 1ed3f50
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
9 changes: 5 additions & 4 deletions src/controllers/controller.line.js
Expand Up @@ -5,6 +5,8 @@ var defaults = require('../core/core.defaults');
var elements = require('../elements/index');
var helpers = require('../helpers/index');

var _isPointInArea = helpers.canvas._isPointInArea;

defaults._set('line', {
showLines: true,
spanGaps: false,
Expand Down Expand Up @@ -248,7 +250,6 @@ module.exports = DatasetController.extend({
var lineModel = meta.dataset._model;
var area = chart.chartArea;
var points = meta.data || [];
var isPointInArea = helpers.canvas.isPointInArea;
var i, ilen, point, model, controlPoints;

// Only consider points that are drawn in case the spanGaps option is used
Expand Down Expand Up @@ -284,12 +285,12 @@ module.exports = DatasetController.extend({
if (chart.options.elements.line.capBezierPoints) {
for (i = 0, ilen = points.length; i < ilen; ++i) {
model = points[i]._model;
if (isPointInArea(model, area)) {
if (i > 0 && isPointInArea(points[i - 1]._model, area)) {
if (_isPointInArea(model, area)) {
if (i > 0 && _isPointInArea(points[i - 1]._model, area)) {
model.controlPointPreviousX = capControlPoint(model.controlPointPreviousX, area.left, area.right);
model.controlPointPreviousY = capControlPoint(model.controlPointPreviousY, area.top, area.bottom);
}
if (i < points.length - 1 && isPointInArea(points[i + 1]._model, area)) {
if (i < points.length - 1 && _isPointInArea(points[i + 1]._model, area)) {
model.controlPointNextX = capControlPoint(model.controlPointNextX, area.left, area.right);
model.controlPointNextY = capControlPoint(model.controlPointNextY, area.top, area.bottom);
}
Expand Down
11 changes: 9 additions & 2 deletions src/helpers/helpers.canvas.js
Expand Up @@ -172,8 +172,15 @@ var exports = {
ctx.stroke();
},

isPointInArea: function(point, area) {
var epsilon = 1e-6; // 1e-6 is margin in pixels for Accumulated error.
/**
* Returns true if the point is inside the rectangle
* @param {Object} point - The point to test
* @param {Object} area - The rectangle
* @returns {Boolean}
* @private
*/
_isPointInArea: function(point, area) {
var epsilon = 1e-6; // 1e-6 is margin in pixels for accumulated error.

return point.x > area.left - epsilon && point.x < area.right + epsilon &&
point.y > area.top - epsilon && point.y < area.bottom + epsilon;
Expand Down

0 comments on commit 1ed3f50

Please sign in to comment.