Merge pull request #2648 from chartjs/fix/2607

Don't use translates and rotates for drawing rotated rectangles
This commit is contained in:
Evert Timberg 2016-05-26 19:42:37 -04:00
commit 464adcc94b
2 changed files with 23 additions and 15 deletions

View File

@ -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();

View File

@ -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: []