chore(examples): update floating edges example

This commit is contained in:
braks
2023-05-29 16:52:40 +02:00
committed by Braks
parent aef12a5743
commit 005f696fbe
3 changed files with 16 additions and 18 deletions
@@ -13,17 +13,17 @@ interface FloatingConnectionLineProps {
const props = defineProps<FloatingConnectionLineProps>() const props = defineProps<FloatingConnectionLineProps>()
const targetNode = computed( const targetNode = computed(() => {
() => return {
({ id: 'connection-target',
id: 'connection-target', computedPosition: { x: props.targetX, y: props.targetY },
position: { x: props.targetX, y: props.targetY }, dimensions: { width: 1, height: 1 },
dimensions: { width: 1, height: 1 }, } as GraphNode
} as GraphNode), })
)
const edgeParams = computed(() => getEdgeParams(props.sourceNode, targetNode.value)) const edgeParams = computed(() => getEdgeParams(props.sourceNode, targetNode.value))
const d = computed(() =>
const edgePath = computed(() =>
getBezierPath({ getBezierPath({
sourceX: edgeParams.value.sx, sourceX: edgeParams.value.sx,
sourceY: edgeParams.value.sy, sourceY: edgeParams.value.sy,
@@ -34,7 +34,7 @@ const d = computed(() =>
<template> <template>
<g> <g>
<path fill="none" stroke="#222" :stroke-width="1.5" class="animated" :d="d[0]" /> <path fill="none" stroke="#222" :stroke-width="1.5" class="animated" :d="edgePath[0]" />
<circle :cx="targetX" :cy="targetY" fill="#fff" :r="3" stroke="#222" :stroke-width="1.5" /> <circle :cx="targetX" :cy="targetY" fill="#fff" :r="3" stroke="#222" :stroke-width="1.5" />
</g> </g>
</template> </template>
@@ -1,7 +1,7 @@
<script lang="ts" setup> <script lang="ts" setup>
import type { CSSProperties } from 'vue' import type { CSSProperties } from 'vue'
import type { EdgeProps, GraphNode, MarkerType } from '@vue-flow/core' import type { EdgeProps, GraphNode, MarkerType } from '@vue-flow/core'
import { getBezierPath } from '@vue-flow/core' import { BaseEdge, getBezierPath } from '@vue-flow/core'
import { getEdgeParams } from './floating-edge-utils' import { getEdgeParams } from './floating-edge-utils'
interface FloatingEdgeProps extends EdgeProps { interface FloatingEdgeProps extends EdgeProps {
@@ -20,7 +20,7 @@ const props = defineProps<FloatingEdgeProps>()
const edgeParams = computed(() => getEdgeParams(props.sourceNode, props.targetNode)) const edgeParams = computed(() => getEdgeParams(props.sourceNode, props.targetNode))
const d = computed( const edgePath = computed(
() => () =>
(edgeParams.value.sx && (edgeParams.value.sx &&
getBezierPath({ getBezierPath({
@@ -36,7 +36,5 @@ const d = computed(
</script> </script>
<template> <template>
<g class="vue-flow__connection"> <BaseEdge :id="id" :path="edgePath[0]" :marker-start="markerStart" :marker-end="markerEnd" :style="style" />
<path :id="id" class="vue-flow__edge-path" :d="d[0]" :marker-start="markerStart" :marker-end="markerEnd" :style="style" />
</g>
</template> </template>
@@ -7,9 +7,9 @@ function getNodeIntersection(intersectionNode: GraphNode, targetNode: GraphNode)
// https://math.stackexchange.com/questions/1724792/an-algorithm-for-finding-the-intersection-point-between-a-center-of-vision-and-a // https://math.stackexchange.com/questions/1724792/an-algorithm-for-finding-the-intersection-point-between-a-center-of-vision-and-a
const { const {
dimensions: { width: intersectionNodeWidth, height: intersectionNodeHeight }, dimensions: { width: intersectionNodeWidth, height: intersectionNodeHeight },
position: intersectionNodePosition, computedPosition: intersectionNodePosition,
} = intersectionNode } = intersectionNode
const targetPosition = targetNode.position const targetPosition = targetNode.computedPosition
const w = intersectionNodeWidth / 2 const w = intersectionNodeWidth / 2
const h = intersectionNodeHeight / 2 const h = intersectionNodeHeight / 2
@@ -32,7 +32,7 @@ function getNodeIntersection(intersectionNode: GraphNode, targetNode: GraphNode)
// returns the position (top,right,bottom or right) passed node compared to the intersection point // returns the position (top,right,bottom or right) passed node compared to the intersection point
function getEdgePosition(node: GraphNode, intersectionPoint: XYPosition) { function getEdgePosition(node: GraphNode, intersectionPoint: XYPosition) {
const n = { ...node.position, ...node.dimensions } const n = { ...node.computedPosition, ...node.dimensions }
const nx = Math.round(n.x) const nx = Math.round(n.x)
const ny = Math.round(n.y) const ny = Math.round(n.y)
const px = Math.round(intersectionPoint.x) const px = Math.round(intersectionPoint.x)