兼容0.4.5版本的关联线

This commit is contained in:
wanglin2 2023-03-22 14:40:07 +08:00
parent cc331065eb
commit de97ea9e75
2 changed files with 38 additions and 5 deletions

View File

@ -7,7 +7,8 @@ import {
cubicBezierPath,
getNodePoint,
computeNodePoints,
getNodeLinePath
getNodeLinePath,
getDefaultControlPointOffsets
} from './utils/associativeLineUtils'
// 关联线类
@ -467,8 +468,14 @@ class AssociativeLine {
this.controlPointMousemoveState.endPoint = endPoint
let targetIndex = getAssociativeLineTargetIndex(node, toNode)
this.controlPointMousemoveState.targetIndex = targetIndex
let offsets =
node.nodeData.data.associativeLineTargetControlOffsets[targetIndex]
let offsets = []
let associativeLineTargetControlOffsets = node.nodeData.data.associativeLineTargetControlOffsets
if (!associativeLineTargetControlOffsets) {
// 兼容0.4.5版本没有associativeLineTargetControlOffsets的情况
offsets = getDefaultControlPointOffsets(startPoint, endPoint)
} else {
offsets = associativeLineTargetControlOffsets[targetIndex]
}
let point1 = null
let point2 = null
// 拖拽的是控制点1
@ -510,8 +517,14 @@ class AssociativeLine {
let { pos, startPoint, endPoint, targetIndex } =
this.controlPointMousemoveState
let [, , node] = this.activeLine
let offsetList =
node.nodeData.data.associativeLineTargetControlOffsets || []
let offsetList = []
let associativeLineTargetControlOffsets = node.nodeData.data.associativeLineTargetControlOffsets
if (!associativeLineTargetControlOffsets) {
// 兼容0.4.5版本没有associativeLineTargetControlOffsets的情况
offsetList[targetIndex] = getDefaultControlPointOffsets(startPoint, endPoint)
} else {
offsetList = associativeLineTargetControlOffsets
}
let offset1 = null
let offset2 = null
if (this.mousedownControlPointKey === 'controlPoint1') {

View File

@ -160,3 +160,23 @@ export const getNodeLinePath = (startPoint, endPoint, node, toNode) => {
controlPoints
}
}
// 获取默认的控制点差值
export const getDefaultControlPointOffsets = (startPoint, endPoint) => {
let controlPoints = computeCubicBezierPathPoints(
startPoint.x,
startPoint.y,
endPoint.x,
endPoint.y
)
return [
{
x: controlPoints[0].x - startPoint.x,
y: controlPoints[0].y - startPoint.y
},
{
x: controlPoints[1].x - endPoint.x,
y: controlPoints[1].y - endPoint.y
}
]
}