forked from chartjs/Chart.js
-
Notifications
You must be signed in to change notification settings - Fork 1
/
box-padding.js
71 lines (69 loc) · 1.52 KB
/
box-padding.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
71
const data = [];
for (let x = 0; x < 3; x++) {
for (let y = 0; y < 3; y++) {
data.push({x, y});
}
}
module.exports = {
config: {
type: 'scatter',
data: {
datasets: [{
data,
backgroundColor: 'red',
radius: 1,
hoverRadius: 0
}],
},
options: {
scales: {
x: {display: false},
y: {display: false}
},
plugins: {
legend: false,
title: false,
filler: false,
tooltip: {
mode: 'point',
intersect: true,
// spriteText: use white background to hide any gaps between fonts
backgroundColor: 'white',
borderColor: 'black',
borderWidth: 1,
callbacks: {
label: () => 'label',
},
boxPadding: 30
},
},
},
plugins: [{
afterDraw: function(chart) {
const canvas = chart.canvas;
const rect = canvas.getBoundingClientRect();
const meta = chart.getDatasetMeta(0);
let point, event;
for (let i = 0; i < data.length; i++) {
point = meta.data[i];
event = {
type: 'mousemove',
target: canvas,
clientX: rect.left + point.x,
clientY: rect.top + point.y
};
chart._handleEvent(event);
chart.tooltip.handleEvent(event);
chart.tooltip.draw(chart.ctx);
}
}
}]
},
options: {
spriteText: true,
canvas: {
height: 400,
width: 500
}
}
};