Skip to content

Commit

Permalink
Add error margin for detecting if a point or line is in the chartArea
Browse files Browse the repository at this point in the history
  • Loading branch information
nagix committed Oct 24, 2018
1 parent b3b5c7d commit f0b4864
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/core/core.scale.js
Expand Up @@ -710,6 +710,8 @@ module.exports = Element.extend({
var yTickStart = options.position === 'bottom' ? me.top + axisWidth : me.bottom - tl - axisWidth;
var yTickEnd = options.position === 'bottom' ? me.top + axisWidth + tl : me.bottom + axisWidth;

var errMargin = 1.01; // 1.01 is margin for Accumulated error. (Especially Edge, IE.)

helpers.each(ticks, function(tick, index) {
// autoskipper skipped this tick (#4635)
if (helpers.isNullOrUndef(tick.label)) {
Expand Down Expand Up @@ -753,7 +755,7 @@ module.exports = Element.extend({
}

var xLineValue = getLineValue(me, index, gridLines.offsetGridLines && ticks.length > 1);
if (xLineValue < me.left) {
if (xLineValue < me.left / errMargin) {
lineColor = 'rgba(0,0,0,0)';
}
xLineValue += helpers.aliasPixel(lineWidth);
Expand All @@ -780,7 +782,7 @@ module.exports = Element.extend({
labelX = isLeft ? me.right - labelXOffset : me.left + labelXOffset;

var yLineValue = getLineValue(me, index, gridLines.offsetGridLines && ticks.length > 1);
if (yLineValue < me.top) {
if (yLineValue < me.top / errMargin) {
lineColor = 'rgba(0,0,0,0)';
}
yLineValue += helpers.aliasPixel(lineWidth);
Expand Down
2 changes: 1 addition & 1 deletion src/elements/element.point.js
Expand Up @@ -79,7 +79,7 @@ module.exports = Element.extend({
}

// Clipping for Points.
if (chartArea === undefined || (model.x >= chartArea.left && chartArea.right * errMargin >= model.x && model.y >= chartArea.top && chartArea.bottom * errMargin >= model.y)) {
if (chartArea === undefined || (model.x >= chartArea.left / errMargin && chartArea.right * errMargin >= model.x && model.y >= chartArea.top / errMargin && chartArea.bottom * errMargin >= model.y)) {
ctx.strokeStyle = vm.borderColor || defaultColor;
ctx.lineWidth = helpers.valueOrDefault(vm.borderWidth, defaults.global.elements.point.borderWidth);
ctx.fillStyle = vm.backgroundColor || defaultColor;
Expand Down

0 comments on commit f0b4864

Please sign in to comment.