fix(edges): edges not properly calculating position
Signed-off-by: Braks <78412429+bcakmakoglu@users.noreply.github.com>
This commit is contained in:
@@ -16,7 +16,6 @@ interface EdgeWrapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const props = withDefaults(defineProps<EdgeWrapper>(), {})
|
const props = withDefaults(defineProps<EdgeWrapper>(), {})
|
||||||
|
|
||||||
const store = useStore()
|
const store = useStore()
|
||||||
|
|
||||||
const updating = ref<boolean>(false)
|
const updating = ref<boolean>(false)
|
||||||
@@ -64,19 +63,8 @@ const targetNodeHandles = computed(() =>
|
|||||||
? props.edge.targetNode.handleBounds.target
|
? props.edge.targetNode.handleBounds.target
|
||||||
: props.edge.targetNode.handleBounds.target ?? props.edge.targetNode.handleBounds.source,
|
: props.edge.targetNode.handleBounds.target ?? props.edge.targetNode.handleBounds.source,
|
||||||
)
|
)
|
||||||
|
const sourceHandle = computed(() => getHandle(props.edge.sourceNode.handleBounds.source, props.edge.sourceHandle))
|
||||||
const sourceHandle = controlledComputed(
|
const targetHandle = computed(() => getHandle(targetNodeHandles.value, props.edge.targetHandle))
|
||||||
() => props.edge,
|
|
||||||
() => {
|
|
||||||
if (props.edge.sourceNode && props.edge.sourceNode.handleBounds.source)
|
|
||||||
return getHandle(props.edge.sourceNode.handleBounds.source, props.edge.sourceHandle)
|
|
||||||
else return undefined
|
|
||||||
},
|
|
||||||
)
|
|
||||||
const targetHandle = computed(() => {
|
|
||||||
if (targetNodeHandles.value) return getHandle(targetNodeHandles.value, props.edge.targetHandle)
|
|
||||||
else return undefined
|
|
||||||
})
|
|
||||||
const sourcePosition = eagerComputed(() => (sourceHandle.value ? sourceHandle.value.position : Position.Bottom))
|
const sourcePosition = eagerComputed(() => (sourceHandle.value ? sourceHandle.value.position : Position.Bottom))
|
||||||
const targetPosition = eagerComputed(() => (targetHandle.value ? targetHandle.value.position : Position.Top))
|
const targetPosition = eagerComputed(() => (targetHandle.value ? targetHandle.value.position : Position.Top))
|
||||||
|
|
||||||
@@ -94,17 +82,17 @@ const edgePos = computed(() =>
|
|||||||
targetPosition.value,
|
targetPosition.value,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
const isVisible = computed(() =>
|
||||||
const isVisible = ({ sourceX, sourceY, targetX, targetY }: EdgePositions) =>
|
|
||||||
store.onlyRenderVisibleElements
|
store.onlyRenderVisibleElements
|
||||||
? isEdgeVisible({
|
? isEdgeVisible({
|
||||||
sourcePos: { x: sourceX, y: sourceY },
|
sourcePos: { x: edgePos.value.sourceX, y: edgePos.value.sourceY },
|
||||||
targetPos: { x: targetX, y: targetY },
|
targetPos: { x: edgePos.value.targetX, y: edgePos.value.targetY },
|
||||||
width: props.dimensions.width,
|
width: props.dimensions.width,
|
||||||
height: props.dimensions.height,
|
height: props.dimensions.height,
|
||||||
transform: props.transform,
|
transform: props.transform,
|
||||||
})
|
})
|
||||||
: true
|
: true,
|
||||||
|
)
|
||||||
</script>
|
</script>
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
export default {
|
export default {
|
||||||
@@ -113,7 +101,7 @@ export default {
|
|||||||
</script>
|
</script>
|
||||||
<template>
|
<template>
|
||||||
<g
|
<g
|
||||||
v-show="isVisible(edgePos)"
|
v-show="isVisible"
|
||||||
:class="[
|
:class="[
|
||||||
'vue-flow__edge',
|
'vue-flow__edge',
|
||||||
`vue-flow__edge-${props.edge.type || 'default'}`,
|
`vue-flow__edge-${props.edge.type || 'default'}`,
|
||||||
|
|||||||
+26
-15
@@ -1,11 +1,11 @@
|
|||||||
import { rectToBox } from './graph'
|
import { rectToBox } from './graph'
|
||||||
import { EdgePositions, GraphNode, HandleElement, Position, Transform, XYPosition } from '~/types'
|
import { EdgePositions, GraphNode, HandleElement, Position, Rect, Transform, XYPosition } from '~/types'
|
||||||
|
|
||||||
export function getHandlePosition(position: Position, node: GraphNode, handle?: HandleElement): XYPosition {
|
export function getHandlePosition(position: Position, rect: Rect, handle?: HandleElement): XYPosition {
|
||||||
const x = (handle?.x ?? 0) + node.position.x
|
const x = (handle?.x ?? 0) + rect.x
|
||||||
const y = (handle?.y ?? 0) + node.position.y
|
const y = (handle?.y ?? 0) + rect.y
|
||||||
const width = handle?.width ?? node.dimensions.width
|
const width = handle?.width ?? rect.width
|
||||||
const height = handle?.height ?? node.dimensions.height
|
const height = handle?.height ?? rect.height
|
||||||
|
|
||||||
switch (position) {
|
switch (position) {
|
||||||
case Position.Top:
|
case Position.Top:
|
||||||
@@ -31,19 +31,16 @@ export function getHandlePosition(position: Position, node: GraphNode, handle?:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getHandle(bounds: HandleElement[], handleId?: string): HandleElement | undefined {
|
export function getHandle(bounds?: HandleElement[], handleId?: string): HandleElement | undefined {
|
||||||
if (!bounds) return undefined
|
if (!bounds) return undefined
|
||||||
|
|
||||||
// there is no handleId when there are no multiple handles/ handles with ids
|
// there is no handleId when there are no multiple handles/ handles with ids
|
||||||
// so we just pick the first one
|
// so we just pick the first one
|
||||||
let handle
|
let handle
|
||||||
if (bounds.length === 1 ?? !handleId) {
|
if (bounds.length === 1 ?? !handleId) handle = bounds[0]
|
||||||
handle = bounds[0]
|
else if (handleId) handle = bounds.find((d) => d.id === handleId)
|
||||||
} else if (handleId) {
|
|
||||||
handle = bounds.find((d) => d.id === handleId)
|
|
||||||
}
|
|
||||||
|
|
||||||
return !handle ? undefined : handle
|
return handle
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getEdgePositions = (
|
export const getEdgePositions = (
|
||||||
@@ -54,8 +51,22 @@ export const getEdgePositions = (
|
|||||||
targetHandle: HandleElement | undefined,
|
targetHandle: HandleElement | undefined,
|
||||||
targetPosition: Position,
|
targetPosition: Position,
|
||||||
): EdgePositions => {
|
): EdgePositions => {
|
||||||
const sourceHandlePos = getHandlePosition(sourcePosition, sourceNode, sourceHandle)
|
const sourceHandlePos = getHandlePosition(
|
||||||
const targetHandlePos = getHandlePosition(targetPosition, targetNode, targetHandle)
|
sourcePosition,
|
||||||
|
{
|
||||||
|
...sourceNode.dimensions,
|
||||||
|
...sourceNode.computedPosition,
|
||||||
|
},
|
||||||
|
sourceHandle,
|
||||||
|
)
|
||||||
|
const targetHandlePos = getHandlePosition(
|
||||||
|
targetPosition,
|
||||||
|
{
|
||||||
|
...targetNode.dimensions,
|
||||||
|
...targetNode.computedPosition,
|
||||||
|
},
|
||||||
|
targetHandle,
|
||||||
|
)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
sourceX: sourceHandlePos.x,
|
sourceX: sourceHandlePos.x,
|
||||||
|
|||||||
Reference in New Issue
Block a user