forked from chartjs/chartjs-plugin-zoom
/
dragDrawTime.js
55 lines (54 loc) · 1.16 KB
/
dragDrawTime.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
const data = [];
for (let i = 0; i < 100; i++) {
data.push({x: i, y: Math.sin(i / 25 * Math.PI) * 10});
}
module.exports = {
tolerance: 0.004,
config: {
type: 'line',
data: {
datasets: [{
data,
borderColor: 'red'
}]
},
options: {
scales: {
x: {type: 'linear', display: false},
y: {display: false}
},
plugins: {
legend: false,
zoom: {
zoom: {
drag: {
enabled: true,
backgroundColor: 'yellow',
borderColor: 'black',
borderWidth: 1,
drawTime: 'afterDraw'
},
}
}
},
layout: {
padding: 2
}
}
},
options: {
run(chart) {
const scaleX = chart.scales.x;
const scaleY = chart.scales.y;
jasmine.triggerMouseEvent(chart, 'mousedown', {
x: scaleX.getPixelForValue(5),
y: scaleY.getPixelForValue(10)
});
jasmine.triggerMouseEvent(chart, 'mousemove', {
x: scaleX.getPixelForValue(60),
y: scaleY.getPixelForValue(0)
});
chart.render = function() { };
}
}
};