Skip to content

fix(handleIcon): unexpected aspect ratio of handleIcon #20895

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
17 changes: 12 additions & 5 deletions src/util/graphic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ import {
*/
export {updateProps, initProps, removeElement, removeElementWithFadeOut, isElementRemoved};

/* global Image */

const mathMax = Math.max;
const mathMin = Math.min;
Expand Down Expand Up @@ -191,6 +192,10 @@ export function makeImage(
rect: ZRRectLike,
layout?: 'center' | 'cover'
) {
const resizeZRImg = (width: number, height:number) => {
const boundingRect = { width, height };
zrImg.setStyle(centerGraphic(rect, boundingRect));
};
const zrImg = new ZRImage({
style: {
image: imageUrl,
Expand All @@ -201,14 +206,16 @@ export function makeImage(
},
onload(img) {
if (layout === 'center') {
const boundingRect = {
width: img.width,
height: img.height
};
zrImg.setStyle(centerGraphic(rect, boundingRect));
resizeZRImg(img.width, img.height);
}
}
});
if (layout === 'center') {
const img = new Image();
img.onload = () => resizeZRImg(img.width, img.height);
img.src = imageUrl;
resizeZRImg(img.width, img.height);
}
return zrImg;
}

Expand Down