-
Notifications
You must be signed in to change notification settings - Fork 342
/
Copy pathpoint.js
70 lines (62 loc) · 2.09 KB
/
point.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import {Element} from 'chart.js';
import {drawPoint} from 'chart.js/helpers';
import {inPointRange, getElementCenterPoint, resolvePointProperties, setBorderStyle, setShadowStyle, isImageOrCanvas} from '../helpers';
export default class PointAnnotation extends Element {
inRange(mouseX, mouseY, axis, useFinalPosition) {
const {x, y, x2, y2, width} = this.getProps(['x', 'y', 'x2', 'y2', 'width'], useFinalPosition);
const borderWidth = this.options.borderWidth;
if (axis !== 'x' && axis !== 'y') {
return inPointRange({x: mouseX, y: mouseY}, this.getCenterPoint(useFinalPosition), width / 2, borderWidth);
}
const hBorderWidth = borderWidth / 2;
const limit = axis === 'y' ? {start: y, end: y2, value: mouseY} : {start: x, end: x2, value: mouseX};
return limit.value >= limit.start - hBorderWidth && limit.value <= limit.end + hBorderWidth;
}
getCenterPoint(useFinalPosition) {
return getElementCenterPoint(this, useFinalPosition);
}
draw(ctx) {
const options = this.options;
const borderWidth = options.borderWidth;
if (options.radius < 0.1) {
return;
}
ctx.save();
ctx.fillStyle = options.backgroundColor;
setShadowStyle(ctx, options);
const stroke = setBorderStyle(ctx, options);
options.borderWidth = 0;
drawPoint(ctx, options, this.centerX, this.centerY);
if (stroke && !isImageOrCanvas(options.pointStyle)) {
ctx.shadowColor = options.borderShadowColor;
ctx.stroke();
}
ctx.restore();
options.borderWidth = borderWidth;
}
resolveElementProperties(chart, options) {
return resolvePointProperties(chart, options);
}
}
PointAnnotation.id = 'pointAnnotation';
PointAnnotation.defaults = {
adjustScaleRange: true,
backgroundShadowColor: 'transparent',
borderDash: [],
borderDashOffset: 0,
borderShadowColor: 'transparent',
borderWidth: 1,
display: true,
pointStyle: 'circle',
radius: 10,
rotation: 0,
shadowBlur: 0,
shadowOffsetX: 0,
shadowOffsetY: 0,
xAdjust: 0,
yAdjust: 0,
};
PointAnnotation.defaultRoutes = {
borderColor: 'color',
backgroundColor: 'color'
};