-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchart-plugin-select-sample.js
More file actions
33 lines (31 loc) · 1.21 KB
/
chart-plugin-select-sample.js
File metadata and controls
33 lines (31 loc) · 1.21 KB
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
Chart.register({
id: 'selectSample',
afterDraw: function (chart) {
const highlightedSample = chart.options.plugins.selectSample.highlightedSample;
if (!highlightedSample) {
return;
}
const datasets = chart.data.datasets;
for (let i = 0; i < datasets.length; i++) {
const data = datasets[i].data;
for (let j = 0; j < data.length; j++) {
if (data[j].label === highlightedSample) {
const meta = chart.getDatasetMeta(i);
const point = meta.data[j];
if (point) {
const { x, y, options } = point.getProps(['x', 'y', 'options']);
const { ctx } = chart;
ctx.save();
ctx.beginPath();
ctx.strokeStyle = 'red';
ctx.lineWidth = 2;
ctx.arc(x, y, options.radius + 3, 0, 2 * Math.PI);
ctx.stroke();
ctx.restore();
}
return; // Stop searching once the highlighted sample is found.
}
}
}
}
});