fix(nodes): correctly calculate xyzpos from parent

Signed-off-by: Braks <78412429+bcakmakoglu@users.noreply.github.com>
This commit is contained in:
Braks
2021-12-20 19:29:52 +01:00
parent 983c86c938
commit 0e82420142
4 changed files with 8 additions and 11 deletions
+1 -1
View File
@@ -32,7 +32,7 @@ watch([() => node.value.position, () => node.value.parentNode?.position], () =>
z: node.value.computedPosition.z,
}
if (node.value.parentNode) {
node.value.computedPosition = getXYZPos(node.value, xyzPos)
node.value.computedPosition = getXYZPos(node.value.parentNode, xyzPos)
} else {
node.value.computedPosition = xyzPos
}
-1
View File
@@ -14,7 +14,6 @@ export interface Connection {
targetHandle?: string
}
export type OnConnectFunc = (connection: Connection) => void
export type OnConnectStartParams = {
nodeId?: string
handleId?: string
+1 -1
View File
@@ -61,7 +61,7 @@ export interface NodeProps<T = any> {
dragging?: boolean
isValidTargetPos?: ValidConnectionFunc
isValidSourcePos?: ValidConnectionFunc
parentNode?: GraphNode<T>[]
parentNode?: any
isParent?: boolean
children?: Node<T>[]
}
+6 -8
View File
@@ -327,14 +327,12 @@ export const getTransformForBounds = (
return [x, y, clampedZoom]
}
export const getXYZPos = (node: GraphNode, result: XYZPosition): XYZPosition => {
if (!node.parentNode) return result
return getXYZPos(node.parentNode, {
x: result.x + node.parentNode.computedPosition.x,
y: result.y + node.parentNode.computedPosition.y,
z:
node.parentNode.computedPosition.z > node.computedPosition.z ? node.parentNode.computedPosition.z : node.computedPosition.z,
})
export const getXYZPos = (parentNode: GraphNode, computedPosition: XYZPosition): XYZPosition => {
return {
x: computedPosition.x + parentNode.computedPosition.x,
y: computedPosition.y + parentNode.computedPosition.y,
z: parentNode.computedPosition.z > computedPosition.z ? parentNode.computedPosition.z : computedPosition.z,
}
}
export const isParentSelected = (node: GraphNode): boolean => {