Skip to content

Commit

Permalink
fix(core): 外部调用handleResize()没有传入anchor坐标不触发recalcRotatedResizeInfo方法
Browse files Browse the repository at this point in the history
  • Loading branch information
wbccb committed Sep 20, 2024
1 parent 1b00bed commit 853e044
Showing 1 changed file with 26 additions and 14 deletions.
40 changes: 26 additions & 14 deletions packages/core/src/util/resize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ export const recalcResizeInfo = (
freezeWidth = false,
freezeHeight = false,
rotate = 0,
anchorX: number,
anchorY: number,
anchorX: number | undefined,
anchorY: number | undefined,
oldCenterX: number,
oldCenterY: number,
): ResizeInfo => {
Expand Down Expand Up @@ -169,8 +169,11 @@ export const recalcResizeInfo = (
}
return nextResizeInfo
}

if (rotate % (2 * Math.PI) !== 0) {
if (
rotate % (2 * Math.PI) !== 0 &&
anchorX !== undefined &&
anchorY !== undefined
) {
// 角度rotate不为0,则触发另外的计算修正resize的deltaX和deltaY
// 因为rotate不为0的时候,左上角的坐标一直在变化
// 角度rotate不为0得到的resizeInfo.deltaX仅仅代表中心点的变化,而不是宽度的变化
Expand Down Expand Up @@ -280,17 +283,21 @@ export const triggerResizeEvent = (
}

// TODO:确认 handleResize 函数的类型定义
// export type IHandleResizeParams = {
// deltaX: number
// deltaY: number
// index: ResizeControlIndex
// nodeModel: BaseNodeModel
// graphModel: GraphModel
// cancelCallback?: () => void
// }
export type IHandleResizeParams = {
x?: number
y?: number
deltaX: number
deltaY: number
index: ResizeControlIndex
nodeModel: BaseNodeModel
graphModel: GraphModel
cancelCallback?: () => void
}

/**
* 处理节点的 resize 事件,提出来放到 utils 中,方便在外面(extension)中使用
* @param x
* @param y
* @param deltaX
* @param deltaY
* @param index
Expand All @@ -307,7 +314,7 @@ export const handleResize = ({
nodeModel,
graphModel,
cancelCallback,
}) => {
}: IHandleResizeParams) => {
const {
r, // circle
rx, // ellipse/diamond
Expand Down Expand Up @@ -362,7 +369,12 @@ export const handleResize = ({
cancelCallback?.()
return
}
if (rotate % (2 * Math.PI) == 0 || PCTResizeInfo) {
if (
rotate % (2 * Math.PI) == 0 ||
PCTResizeInfo ||
anchorX === undefined ||
anchorY === undefined
) {
// rotate!==0并且不是PCTResizeInfo时,即使是isFreezeWidth||isFreezeHeight
// recalcRotatedResizeInfo()计算出来的中心点会发生变化

Expand Down

0 comments on commit 853e044

Please sign in to comment.