From 67c46f39c208bb86df84c0afa63399755747f4ff Mon Sep 17 00:00:00 2001 From: pissang Date: Fri, 15 Apr 2022 13:40:51 +0800 Subject: [PATCH 1/3] fix: Uncaught TypeError: Failed to execute 'createRadialGradient' on 'CanvasRenderingContext2D': The provided double value is non-finite. at createRadialGradient. Excute npm run test error fix! (#16649) fix: Uncaught TypeError: Failed to execute 'createRadialGradient' on 'CanvasRenderingContext2D': The provided double value is non-finite. at createRadialGradient. Excute npm run test error fix! (#16649) fix: Uncaught TypeError: Failed to execute 'createRadialGradient' on 'CanvasRenderingContext2D': The provided double value is non-finite. at createRadialGradient. Excute npm run test error fix! (#16649) fix: Uncaught TypeError: Failed to execute 'createRadialGradient' on 'CanvasRenderingContext2D': The provided double value is non-finite. at createRadialGradient. Excute npm run test error fix! (#16649) fix: Uncaught TypeError: Failed to execute 'createRadialGradient' on 'CanvasRenderingContext2D': The provided double value is non-finite. at createRadialGradient. Excute npm run test error fix! (#16649) fix: Uncaught TypeError: Failed to execute 'createRadialGradient' on 'CanvasRenderingContext2D': The provided double value is non-finite. at createRadialGradient. Excute npm run test error fix! (#16649) fix: Uncaught TypeError: Failed to execute 'createRadialGradient' on 'CanvasRenderingContext2D': The provided double value is non-finite. at createRadialGradient. Excute npm run test error fix! (#16649) fix: Uncaught TypeError: Failed to execute 'createRadialGradient' --- src/canvas/helper.ts | 18 ++++++++++++++---- test/ut/spec/contain/Sector.test.ts | 1 - 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/canvas/helper.ts b/src/canvas/helper.ts index ec6cb721e..59895a19e 100644 --- a/src/canvas/helper.ts +++ b/src/canvas/helper.ts @@ -4,6 +4,11 @@ import { GradientObject } from '../graphic/Gradient'; import { RectLike } from '../core/BoundingRect'; import Path from '../graphic/Path'; +function isSafeNum(num: number) { + // NaN、Infinity、undefined、'xx' + return !isFinite(num); +} + export function createLinearGradient( this: void, ctx: CanvasRenderingContext2D, @@ -23,10 +28,10 @@ export function createLinearGradient( } // Fix NaN when rect is Infinity - x = isNaN(x) ? 0 : x; - x2 = isNaN(x2) ? 1 : x2; - y = isNaN(y) ? 0 : y; - y2 = isNaN(y2) ? 0 : y2; + x = isSafeNum(x) ? x : 0; + x2 = isSafeNum(x2) ? x2 : 1; + y = isSafeNum(y) ? y : 0; + y2 = isSafeNum(y2) ? y2 : 0; const canvasGradient = ctx.createLinearGradient(x, y, x2, y2); @@ -46,12 +51,17 @@ export function createRadialGradient( let x = obj.x == null ? 0.5 : obj.x; let y = obj.y == null ? 0.5 : obj.y; let r = obj.r == null ? 0.5 : obj.r; + if (!obj.global) { x = x * width + rect.x; y = y * height + rect.y; r = r * min; } + x = isSafeNum(x) ? x : 0.5; + y = isSafeNum(y) ? y : 0.5; + r = r >= 0 && isSafeNum(r) ? r : 0.5; + const canvasGradient = ctx.createRadialGradient(x, y, 0, x, y, r); return canvasGradient; diff --git a/test/ut/spec/contain/Sector.test.ts b/test/ut/spec/contain/Sector.test.ts index e3b898289..d008a6fd5 100644 --- a/test/ut/spec/contain/Sector.test.ts +++ b/test/ut/spec/contain/Sector.test.ts @@ -12,7 +12,6 @@ describe('Path', function () { cy: 625.5, startAngle: -1.5707963267948966, endAngle: 4.71238898038469, - innerCornerRadius: 5, r: 218.92499999999998, r0: 93.825 }, From c564acd0b0619df9402790f67ae229c1e4ac8d8b Mon Sep 17 00:00:00 2001 From: yangqin Date: Thu, 28 Apr 2022 19:56:10 +0800 Subject: [PATCH 2/3] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8DcreateOrUpdateImag?= =?UTF-8?q?e=E6=96=B9=E6=B3=95image=E5=AE=9E=E4=BE=8B=E4=B8=A2=E5=A4=B1?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/graphic/helper/image.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/graphic/helper/image.ts b/src/graphic/helper/image.ts index aa2bd37ba..858964056 100644 --- a/src/graphic/helper/image.ts +++ b/src/graphic/helper/image.ts @@ -65,7 +65,7 @@ export function createOrUpdateImage( !isImageReady(image) && cachedImgObj.pending.push(pendingWrap); } else { - const image = platformApi.loadImage( + image = platformApi.loadImage( newImageOrSrc, imageOnLoad, imageOnLoad ); (image as any).__zrImageSrc = newImageOrSrc; From d9e9187525eed96ea1d127a6772a8be30b9101fb Mon Sep 17 00:00:00 2001 From: Ovilia Date: Tue, 7 Jun 2022 15:40:08 +0800 Subject: [PATCH 3/3] fix(gradient): #898 has bug about safe checkingand breaks all gradients --- src/canvas/helper.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/canvas/helper.ts b/src/canvas/helper.ts index 59895a19e..068608f79 100644 --- a/src/canvas/helper.ts +++ b/src/canvas/helper.ts @@ -6,7 +6,7 @@ import Path from '../graphic/Path'; function isSafeNum(num: number) { // NaN、Infinity、undefined、'xx' - return !isFinite(num); + return isFinite(num); } export function createLinearGradient(