Skip to content

Commit

Permalink
Merge pull request #920 from ecomfe/master
Browse files Browse the repository at this point in the history
Release v5.3.2
  • Loading branch information
Ovilia authored Jun 8, 2022
2 parents d44f50e + f1085eb commit 3ffb28f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
18 changes: 14 additions & 4 deletions src/canvas/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);

Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/graphic/helper/image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export function createOrUpdateImage<T>(
!isImageReady(image) && cachedImgObj.pending.push(pendingWrap);
}
else {
const image = platformApi.loadImage(
image = platformApi.loadImage(
newImageOrSrc, imageOnLoad, imageOnLoad
);
(image as any).__zrImageSrc = newImageOrSrc;
Expand Down
1 change: 0 additions & 1 deletion test/ut/spec/contain/Sector.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ describe('Path', function () {
cy: 625.5,
startAngle: -1.5707963267948966,
endAngle: 4.71238898038469,
innerCornerRadius: 5,
r: 218.92499999999998,
r0: 93.825
},
Expand Down

0 comments on commit 3ffb28f

Please sign in to comment.