mirror of
https://github.com/chartjs/Chart.js.git
synced 2024-10-07 04:39:06 +02:00
Merge pull request #2648 from chartjs/fix/2607
Don't use translates and rotates for drawing rotated rectangles
This commit is contained in:
commit
464adcc94b
@ -88,12 +88,14 @@ module.exports = function(Chart) {
|
||||
ctx.strokeRect(x - size, y - size, 2 * size, 2 * size);
|
||||
break;
|
||||
case 'rectRot':
|
||||
ctx.translate(x, y);
|
||||
ctx.rotate(Math.PI / 4);
|
||||
size = 1 / Math.SQRT2 * radius;
|
||||
ctx.fillRect(-size, -size, 2 * size, 2 * size);
|
||||
ctx.strokeRect(-size, -size, 2 * size, 2 * size);
|
||||
ctx.setTransform(1, 0, 0, 1, 0, 0);
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(x - size, y);
|
||||
ctx.lineTo(x, y + size);
|
||||
ctx.lineTo(x + size, y);
|
||||
ctx.lineTo(x, y - size);
|
||||
ctx.closePath();
|
||||
ctx.fill();
|
||||
break;
|
||||
case 'cross':
|
||||
ctx.beginPath();
|
||||
|
@ -189,20 +189,26 @@ describe('Point element tests', function() {
|
||||
name: 'setFillStyle',
|
||||
args: ['rgba(0, 255, 0)']
|
||||
}, {
|
||||
name: 'translate',
|
||||
args: [10, 15]
|
||||
name: 'beginPath',
|
||||
args: []
|
||||
}, {
|
||||
name: 'rotate',
|
||||
args: [Math.PI / 4]
|
||||
name: 'moveTo',
|
||||
args: [10 - 1 / Math.SQRT2 * 2, 15]
|
||||
}, {
|
||||
name: 'fillRect',
|
||||
args: [-1 / Math.SQRT2 * 2, -1 / Math.SQRT2 * 2, 2 / Math.SQRT2 * 2, 2 / Math.SQRT2 * 2],
|
||||
name: 'lineTo',
|
||||
args: [10, 15 + 1 / Math.SQRT2 * 2]
|
||||
}, {
|
||||
name: 'strokeRect',
|
||||
args: [-1 / Math.SQRT2 * 2, -1 / Math.SQRT2 * 2, 2 / Math.SQRT2 * 2, 2 / Math.SQRT2 * 2],
|
||||
name: 'lineTo',
|
||||
args: [10 + 1 / Math.SQRT2 * 2, 15],
|
||||
}, {
|
||||
name: 'setTransform',
|
||||
args: [1, 0, 0, 1, 0, 0],
|
||||
name: 'lineTo',
|
||||
args: [10, 15 - 1 / Math.SQRT2 * 2],
|
||||
}, {
|
||||
name: 'closePath',
|
||||
args: []
|
||||
}, {
|
||||
name: 'fill',
|
||||
args: [],
|
||||
}, {
|
||||
name: 'stroke',
|
||||
args: []
|
||||
|
Loading…
Reference in New Issue
Block a user