Skip to content

Commit 067a413

Browse files
nagixsimonbrunel
authored andcommitted
Support rotation for pointStyle image (chartjs#6287)
1 parent 5a68815 commit 067a413

File tree

3 files changed

+63
-1
lines changed

3 files changed

+63
-1
lines changed

src/helpers/helpers.canvas.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,11 @@ var exports = {
7070
if (style && typeof style === 'object') {
7171
type = style.toString();
7272
if (type === '[object HTMLImageElement]' || type === '[object HTMLCanvasElement]') {
73-
ctx.drawImage(style, x - style.width / 2, y - style.height / 2, style.width, style.height);
73+
ctx.save();
74+
ctx.translate(x, y);
75+
ctx.rotate(rad);
76+
ctx.drawImage(style, -style.width / 2, -style.height / 2, style.width, style.height);
77+
ctx.restore();
7478
return;
7579
}
7680
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
var imageCanvas = document.createElement('canvas');
2+
var imageContext = imageCanvas.getContext('2d');
3+
4+
imageCanvas.width = 40;
5+
imageCanvas.height = 40;
6+
7+
imageContext.fillStyle = '#f00';
8+
imageContext.beginPath();
9+
imageContext.moveTo(20, 0);
10+
imageContext.lineTo(10, 40);
11+
imageContext.lineTo(20, 30);
12+
imageContext.closePath();
13+
imageContext.fill();
14+
15+
imageContext.fillStyle = '#a00';
16+
imageContext.beginPath();
17+
imageContext.moveTo(20, 0);
18+
imageContext.lineTo(30, 40);
19+
imageContext.lineTo(20, 30);
20+
imageContext.closePath();
21+
imageContext.fill();
22+
23+
module.exports = {
24+
config: {
25+
type: 'line',
26+
data: {
27+
labels: [0, 1, 2, 3, 4, 5, 6, 7],
28+
datasets: [{
29+
data: [0, 0, 0, 0, 0, 0, 0, 0],
30+
showLine: false
31+
}]
32+
},
33+
options: {
34+
responsive: false,
35+
legend: false,
36+
title: false,
37+
elements: {
38+
point: {
39+
pointStyle: imageCanvas,
40+
rotation: [0, 45, 90, 135, 180, 225, 270, 315]
41+
}
42+
},
43+
layout: {
44+
padding: 20
45+
},
46+
scales: {
47+
xAxes: [{display: false}],
48+
yAxes: [{display: false}]
49+
}
50+
}
51+
},
52+
options: {
53+
canvas: {
54+
height: 256,
55+
width: 512
56+
}
57+
}
58+
};
Loading

0 commit comments

Comments
 (0)