-
Notifications
You must be signed in to change notification settings - Fork 379
Closed
Description
When a point/polygon annotation is configured using x/yMin and y/xMax, the calculated centerX and centerY are wrong because the center point of result box is used. This is correct only if the box is a square.
chartjs-plugin-annotation/src/helpers/helpers.chart.js
Lines 140 to 149 in 76ba0e9
| return { | |
| x: box.x + options.xAdjust, | |
| y: box.y + options.yAdjust, | |
| x2: box.x + size + options.xAdjust, | |
| y2: box.y + size + options.yAdjust, | |
| centerX: box.centerX + options.xAdjust, | |
| centerY: box.centerY + options.yAdjust, | |
| width: size, | |
| height: size | |
| }; |
To use the center point of the box, it should be:
const adjustCenterX = box.centerX + options.xAdjust;
const adjustCenterY = box.centerY + options.yAdjust;
return {
x: adjustCenterX - radius,
y: adjustCenterY - radius,
x2: adjustCenterX + radius,
y2: adjustCenterY + radius,
centerX: adjustCenterX,
centerY: adjustCenterY,
width: size,
height: size
};