fix: compute container height from bound text correctly (#6273)

* fix: compute container height from bound text correctly

* fix specs

* Add tests
This commit is contained in:
Aakansha Doshi 2023-02-23 17:39:02 +05:30 committed by GitHub
parent 9659254fd6
commit 0e95e2b386
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 78 additions and 4 deletions

View file

@ -233,7 +233,7 @@ describe("Test measureText", () => {
type: "ellipse",
...params,
});
expect(computeContainerHeightForBoundText(element, 150)).toEqual(212);
expect(computeContainerHeightForBoundText(element, 150)).toEqual(226);
});
it("should compute container height correctly for diamond", () => {
@ -241,7 +241,7 @@ describe("Test measureText", () => {
type: "diamond",
...params,
});
expect(computeContainerHeightForBoundText(element, 150)).toEqual(300);
expect(computeContainerHeightForBoundText(element, 150)).toEqual(320);
});
});

View file

@ -280,6 +280,8 @@ export const getApproxLineHeight = (font: FontString) => {
return cacheApproxLineHeight[font];
}
const fontSize = parseInt(font);
// Calculate line height relative to font size
cacheApproxLineHeight[font] = fontSize * 1.2;
return cacheApproxLineHeight[font];
};
@ -727,13 +729,15 @@ export const computeContainerHeightForBoundText = (
boundTextElementHeight: number,
) => {
if (container.type === "ellipse") {
return Math.round((boundTextElementHeight / Math.sqrt(2)) * 2);
return Math.round(
((boundTextElementHeight + BOUND_TEXT_PADDING * 2) / Math.sqrt(2)) * 2,
);
}
if (isArrowElement(container)) {
return boundTextElementHeight + BOUND_TEXT_PADDING * 8 * 2;
}
if (container.type === "diamond") {
return 2 * boundTextElementHeight;
return 2 * (boundTextElementHeight + BOUND_TEXT_PADDING * 2);
}
return boundTextElementHeight + BOUND_TEXT_PADDING * 2;
};