From: Jukka Kurkela Date: Mon, 14 Dec 2020 22:13:03 +0000 (+0200) Subject: ArcElement: Skip draw when radius is negative (#8170) X-Git-Tag: v3.0.0-beta.8~65 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e78310c0fd69bd46bd95801e8d753bdc74390a5e;p=thirdparty%2FChart.js.git ArcElement: Skip draw when radius is negative (#8170) --- diff --git a/src/elements/element.arc.js b/src/elements/element.arc.js index cd558dff2..776935313 100644 --- a/src/elements/element.arc.js +++ b/src/elements/element.arc.js @@ -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; } diff --git a/test/specs/element.arc.tests.js b/test/specs/element.arc.tests.js index 3a744e266..65c03b991 100644 --- a/test/specs/element.arc.tests.js +++ b/test/specs/element.arc.tests.js @@ -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); + }); });