ArcElement: Skip draw when radius is negative (#8170)

This commit is contained in:
Jukka Kurkela 2020-12-15 00:13:03 +02:00 committed by GitHub
parent 8ab62f57be
commit e78310c0fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 1 deletions

View File

@ -184,7 +184,7 @@ export default class ArcElement extends Element {
me.pixelMargin = (options.borderAlign === 'inner') ? 0.33 : 0;
me.fullCircles = Math.floor(me.circumference / TAU);
if (me.circumference === 0) {
if (me.circumference === 0 || me.innerRadius < 0 || me.outerRadius < 0) {
return;
}

View File

@ -65,4 +65,36 @@ describe('Arc element tests', function() {
expect(center.x).toBeCloseTo(0.5, 6);
expect(center.y).toBeCloseTo(0.5, 6);
});
it('should not draw when radius < 0', function() {
var ctx = window.createMockContext();
var arc = new Chart.elements.ArcElement({
startAngle: 0,
endAngle: Math.PI / 2,
x: 0,
y: 0,
innerRadius: -0.1,
outerRadius: Math.sqrt(2),
options: {}
});
arc.draw(ctx);
expect(ctx.getCalls().length).toBe(0);
arc = new Chart.elements.ArcElement({
startAngle: 0,
endAngle: Math.PI / 2,
x: 0,
y: 0,
innerRadius: 0,
outerRadius: -1,
options: {}
});
arc.draw(ctx);
expect(ctx.getCalls().length).toBe(0);
});
});