rename getContainerCoords -> computeBoundTextElementCoords

This commit is contained in:
Aakansha Doshi 2023-03-06 15:31:38 +05:30
parent fefd377408
commit 83780b91d2
3 changed files with 11 additions and 15 deletions

View File

@ -2,7 +2,7 @@ import { BOUND_TEXT_PADDING } from "../constants";
import { API } from "../tests/helpers/api"; import { API } from "../tests/helpers/api";
import { import {
computeContainerHeightForBoundText, computeContainerHeightForBoundText,
getContainerCoords, computeBoundTextElementCoords,
getMaxContainerWidth, getMaxContainerWidth,
getMaxContainerHeight, getMaxContainerHeight,
wrapText, wrapText,
@ -177,7 +177,7 @@ break it now`,
}); });
describe("Test measureText", () => { describe("Test measureText", () => {
describe("Test getContainerCoords", () => { describe("Test computeBoundTextElementCoords", () => {
const params = { width: 200, height: 100, x: 10, y: 20 }; const params = { width: 200, height: 100, x: 10, y: 20 };
it("should compute coords correctly when ellipse", () => { it("should compute coords correctly when ellipse", () => {
@ -185,7 +185,7 @@ describe("Test measureText", () => {
type: "ellipse", type: "ellipse",
...params, ...params,
}); });
expect(getContainerCoords(element)).toEqual({ expect(computeBoundTextElementCoords(element)).toEqual({
x: 44.2893218813452455, x: 44.2893218813452455,
y: 39.64466094067262, y: 39.64466094067262,
}); });
@ -196,7 +196,7 @@ describe("Test measureText", () => {
type: "rectangle", type: "rectangle",
...params, ...params,
}); });
expect(getContainerCoords(element)).toEqual({ expect(computeBoundTextElementCoords(element)).toEqual({
x: 15, x: 15,
y: 25, y: 25,
}); });
@ -207,7 +207,7 @@ describe("Test measureText", () => {
type: "diamond", type: "diamond",
...params, ...params,
}); });
expect(getContainerCoords(element)).toEqual({ expect(computeBoundTextElementCoords(element)).toEqual({
x: 65, x: 65,
y: 50, y: 50,
}); });

View File

@ -244,7 +244,7 @@ const computeBoundTextPosition = (
container: ExcalidrawElement, container: ExcalidrawElement,
boundTextElement: ExcalidrawTextElementWithContainer, boundTextElement: ExcalidrawTextElementWithContainer,
) => { ) => {
const containerCoords = getContainerCoords(container); const containerCoords = computeBoundTextElementCoords(container);
const maxContainerHeight = getMaxContainerHeight(container); const maxContainerHeight = getMaxContainerHeight(container);
const maxContainerWidth = getMaxContainerWidth(container); const maxContainerWidth = getMaxContainerWidth(container);
@ -614,7 +614,9 @@ export const getContainerCenter = (
return { x: midSegmentMidpoint[0], y: midSegmentMidpoint[1] }; return { x: midSegmentMidpoint[0], y: midSegmentMidpoint[1] };
}; };
export const getContainerCoords = (container: NonDeletedExcalidrawElement) => { export const computeBoundTextElementCoords = (
container: NonDeletedExcalidrawElement,
) => {
let offsetX = BOUND_TEXT_PADDING; let offsetX = BOUND_TEXT_PADDING;
let offsetY = BOUND_TEXT_PADDING; let offsetY = BOUND_TEXT_PADDING;
@ -810,9 +812,3 @@ export const getMaxContainerHeight = (container: ExcalidrawElement) => {
} }
return height - BOUND_TEXT_PADDING * 2; return height - BOUND_TEXT_PADDING * 2;
}; };
// export const computeContainerCoordsFromBoundText = (
// boundText: ExcalidrawTextElementWithContainer,
// ) => {
// };

View File

@ -24,7 +24,7 @@ import { mutateElement } from "./mutateElement";
import { import {
getApproxLineHeight, getApproxLineHeight,
getBoundTextElementId, getBoundTextElementId,
getContainerCoords, computeBoundTextElementCoords,
getContainerDims, getContainerDims,
getContainerElement, getContainerElement,
getTextElementAngle, getTextElementAngle,
@ -233,7 +233,7 @@ export const textWysiwyg = ({
// Start pushing text upward until a diff of 30px (padding) // Start pushing text upward until a diff of 30px (padding)
// is reached // is reached
else { else {
const containerCoords = getContainerCoords(container); const containerCoords = computeBoundTextElementCoords(container);
// vertically center align the text // vertically center align the text
if (verticalAlign === VERTICAL_ALIGN.MIDDLE) { if (verticalAlign === VERTICAL_ALIGN.MIDDLE) {