Skip to content

Commit e6742e3

Browse files
authored
Add tests for polarArea chart animations (#8455)
* Add tests for polarArea chart animations * Remove commented code
1 parent e2a4734 commit e6742e3

File tree

4 files changed

+150
-0
lines changed

4 files changed

+150
-0
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
const canvas = document.createElement('canvas');
2+
canvas.width = 512;
3+
canvas.height = 512;
4+
const ctx = canvas.getContext('2d');
5+
6+
module.exports = {
7+
config: {
8+
type: 'polarArea',
9+
data: {
10+
labels: ['A', 'B', 'C', 'D', 'E'],
11+
datasets: [{
12+
data: [1, 5, 10, 2, 4],
13+
backgroundColor: [
14+
'rgba(255, 99, 132, 0.8)',
15+
'rgba(54, 162, 235, 0.8)',
16+
'rgba(255, 206, 86, 0.8)',
17+
'rgba(75, 192, 192, 0.8)',
18+
'rgba(153, 102, 255, 0.8)'
19+
],
20+
borderWidth: 4,
21+
borderColor: [
22+
'rgb(255, 99, 132)',
23+
'rgb(54, 162, 235)',
24+
'rgb(255, 206, 86)',
25+
'rgb(75, 192, 192)',
26+
'rgb(153, 102, 255)'
27+
]
28+
}]
29+
},
30+
options: {
31+
animation: {
32+
animateRotate: true,
33+
animateScale: false,
34+
duration: 800,
35+
easing: 'linear'
36+
},
37+
responsive: false,
38+
plugins: {
39+
legend: false,
40+
title: false,
41+
tooltip: false,
42+
filler: false
43+
},
44+
scales: {
45+
r: {
46+
ticks: {
47+
display: false,
48+
}
49+
}
50+
}
51+
},
52+
},
53+
options: {
54+
canvas: {
55+
height: 512,
56+
width: 512
57+
},
58+
run: function(chart) {
59+
const animator = Chart.animator;
60+
const start = animator._getAnims(chart).items[0]._start;
61+
animator._running = false;
62+
return new Promise((resolve) => setTimeout(() => {
63+
for (let i = 0; i < 16; i++) {
64+
animator._update(start + i * 50);
65+
let x = i % 4 * 128;
66+
let y = Math.floor(i / 4) * 128;
67+
ctx.drawImage(chart.canvas, x, y, 128, 128);
68+
}
69+
Chart.helpers.clearCanvas(chart.canvas);
70+
chart.ctx.drawImage(canvas, 0, 0);
71+
resolve();
72+
}, 100));
73+
}
74+
}
75+
};
67.2 KB
Loading
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
const canvas = document.createElement('canvas');
2+
canvas.width = 512;
3+
canvas.height = 512;
4+
const ctx = canvas.getContext('2d');
5+
6+
module.exports = {
7+
config: {
8+
type: 'polarArea',
9+
data: {
10+
labels: ['A', 'B', 'C', 'D', 'E'],
11+
datasets: [{
12+
data: [1, 5, 10, 2, 4],
13+
backgroundColor: [
14+
'rgba(255, 99, 132, 0.8)',
15+
'rgba(54, 162, 235, 0.8)',
16+
'rgba(255, 206, 86, 0.8)',
17+
'rgba(75, 192, 192, 0.8)',
18+
'rgba(153, 102, 255, 0.8)'
19+
],
20+
borderWidth: 4,
21+
borderColor: [
22+
'rgb(255, 99, 132)',
23+
'rgb(54, 162, 235)',
24+
'rgb(255, 206, 86)',
25+
'rgb(75, 192, 192)',
26+
'rgb(153, 102, 255)'
27+
]
28+
}]
29+
},
30+
options: {
31+
animation: {
32+
animateRotate: false,
33+
animateScale: true,
34+
duration: 800,
35+
easing: 'linear'
36+
},
37+
responsive: false,
38+
plugins: {
39+
legend: false,
40+
title: false,
41+
tooltip: false,
42+
filler: false
43+
},
44+
scales: {
45+
r: {
46+
ticks: {
47+
display: false,
48+
}
49+
}
50+
}
51+
},
52+
},
53+
options: {
54+
canvas: {
55+
height: 512,
56+
width: 512
57+
},
58+
run: function(chart) {
59+
const animator = Chart.animator;
60+
const start = animator._getAnims(chart).items[0]._start;
61+
animator._running = false;
62+
return new Promise((resolve) => setTimeout(() => {
63+
for (let i = 0; i < 16; i++) {
64+
animator._update(start + i * 50);
65+
let x = i % 4 * 128;
66+
let y = Math.floor(i / 4) * 128;
67+
ctx.drawImage(chart.canvas, x, y, 128, 128);
68+
}
69+
Chart.helpers.clearCanvas(chart.canvas);
70+
chart.ctx.drawImage(canvas, 0, 0);
71+
resolve();
72+
}, 100));
73+
}
74+
}
75+
};
52.1 KB
Loading

0 commit comments

Comments
 (0)