From 615d375fa25571b19c221fdf810c49461d8a380d Mon Sep 17 00:00:00 2001 From: plainheart Date: Wed, 19 Jan 2022 20:43:27 +0800 Subject: [PATCH 1/2] fix(sector): fix a case in which the angle is NaN. (related to #870) --- src/graphic/helper/roundSector.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/graphic/helper/roundSector.ts b/src/graphic/helper/roundSector.ts index 7a09f2c90..5fb45820d 100644 --- a/src/graphic/helper/roundSector.ts +++ b/src/graphic/helper/roundSector.ts @@ -146,7 +146,10 @@ export function buildPath(ctx: CanvasRenderingContext2D | PathProxy, shape: { } const clockwise = !!shape.clockwise; - const { startAngle, endAngle, cx, cy, cornerRadius } = shape; + const { cx, cy, cornerRadius } = shape; + // may be NaN + const startAngle = shape.startAngle || 0; + const endAngle = shape.endAngle || 0; let arc = mathAbs(endAngle - startAngle); const mod = arc > PI2 && arc % PI2; From 3e70f29017663f532feabcf8fd31f7eb1c5ce871 Mon Sep 17 00:00:00 2001 From: plainheart Date: Wed, 19 Jan 2022 21:32:45 +0800 Subject: [PATCH 2/2] fix(sector): don't draw sector if startAngle or endAngle is NaN. --- src/graphic/helper/roundSector.ts | 11 +++++++---- test/sector.html | 15 +++++++++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/graphic/helper/roundSector.ts b/src/graphic/helper/roundSector.ts index 5fb45820d..9ba5f313b 100644 --- a/src/graphic/helper/roundSector.ts +++ b/src/graphic/helper/roundSector.ts @@ -145,11 +145,13 @@ export function buildPath(ctx: CanvasRenderingContext2D | PathProxy, shape: { innerRadius = tmp; } + const { startAngle, endAngle } = shape; + if (isNaN(startAngle) || isNaN(endAngle)) { + return; + } + + const { cx, cy } = shape; const clockwise = !!shape.clockwise; - const { cx, cy, cornerRadius } = shape; - // may be NaN - const startAngle = shape.startAngle || 0; - const endAngle = shape.endAngle || 0; let arc = mathAbs(endAngle - startAngle); const mod = arc > PI2 && arc % PI2; @@ -204,6 +206,7 @@ export function buildPath(ctx: CanvasRenderingContext2D | PathProxy, shape: { const hasArc = arc > e; if (hasArc) { + const cornerRadius = shape.cornerRadius; if (cornerRadius) { [icrStart, icrEnd, ocrStart, ocrEnd] = normalizeCornerRadius(cornerRadius); } diff --git a/test/sector.html b/test/sector.html index bc2510151..bbf31db1c 100644 --- a/test/sector.html +++ b/test/sector.html @@ -220,6 +220,21 @@ // clockwise: false } })); + + // should show nothing + zr.add(new zrender.Sector({ + position: [400, 650], + scale: [1, 1], + style: { + stroke: 'black', + lineWidth: 10 + }, + shape: { + startAngle: NaN, + endAngle: NaN, + r: 100 + } + }));