Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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