/
last-slice-animate.js
70 lines (67 loc) · 1.57 KB
/
last-slice-animate.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
const canvas = document.createElement('canvas');
canvas.width = 512;
canvas.height = 512;
const ctx = canvas.getContext('2d');
module.exports = {
config: {
type: 'polarArea',
data: {
labels: ['A'],
datasets: [{
data: [20],
backgroundColor: 'red',
}]
},
options: {
animation: {
duration: 0,
easing: 'linear'
},
responsive: false,
plugins: {
legend: false,
title: false,
tooltip: false,
filler: false
},
scales: {
r: {
ticks: {
display: false,
}
}
}
},
},
options: {
canvas: {
height: 512,
width: 512
},
run: function(chart) {
chart.options.animation.duration = 8000;
chart.toggleDataVisibility(0);
chart.update();
const animator = Chart.animator;
// disable animator
const backup = animator._refresh;
animator._refresh = function() { };
return new Promise((resolve) => {
window.requestAnimationFrame(() => {
const anims = animator._getAnims(chart);
const start = anims.items[0]._start;
for (let i = 0; i < 16; i++) {
animator._update(start + i * 500);
let x = i % 4 * 128;
let y = Math.floor(i / 4) * 128;
ctx.drawImage(chart.canvas, x, y, 128, 128);
}
Chart.helpers.clearCanvas(chart.canvas);
chart.ctx.drawImage(canvas, 0, 0);
animator._refresh = backup;
resolve();
});
});
}
}
};