]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
ArcElement: Skip draw when radius is negative (#8170)
authorJukka Kurkela <jukka.kurkela@gmail.com>
Mon, 14 Dec 2020 22:13:03 +0000 (00:13 +0200)
committerGitHub <noreply@github.com>
Mon, 14 Dec 2020 22:13:03 +0000 (17:13 -0500)
src/elements/element.arc.js
test/specs/element.arc.tests.js

index cd558dff204cff37b70e060a0d5a61981d887ebf..7769353138f3b873e976c150d0e06d36facd7909 100644 (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;
                }
 
index 3a744e266934783266e49c9078c770174908e815..65c03b9913be00f3b70cac8e560a7167b981c2e9 100644 (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);
+       });
 });