Skip to content

Commit 005f696

Browse files
committed
chore(examples): update floating edges example
1 parent aef12a5 commit 005f696

File tree

3 files changed

+16
-18
lines changed

3 files changed

+16
-18
lines changed

examples/vite/src/FloatingEdges/FloatingConnectionLine.vue

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@ interface FloatingConnectionLineProps {
1313
1414
const props = defineProps<FloatingConnectionLineProps>()
1515
16-
const targetNode = computed(
17-
() =>
18-
({
19-
id: 'connection-target',
20-
position: { x: props.targetX, y: props.targetY },
21-
dimensions: { width: 1, height: 1 },
22-
} as GraphNode),
23-
)
16+
const targetNode = computed(() => {
17+
return {
18+
id: 'connection-target',
19+
computedPosition: { x: props.targetX, y: props.targetY },
20+
dimensions: { width: 1, height: 1 },
21+
} as GraphNode
22+
})
2423
2524
const edgeParams = computed(() => getEdgeParams(props.sourceNode, targetNode.value))
26-
const d = computed(() =>
25+
26+
const edgePath = computed(() =>
2727
getBezierPath({
2828
sourceX: edgeParams.value.sx,
2929
sourceY: edgeParams.value.sy,
@@ -34,7 +34,7 @@ const d = computed(() =>
3434

3535
<template>
3636
<g>
37-
<path fill="none" stroke="#222" :stroke-width="1.5" class="animated" :d="d[0]" />
37+
<path fill="none" stroke="#222" :stroke-width="1.5" class="animated" :d="edgePath[0]" />
3838
<circle :cx="targetX" :cy="targetY" fill="#fff" :r="3" stroke="#222" :stroke-width="1.5" />
3939
</g>
4040
</template>

examples/vite/src/FloatingEdges/FloatingEdge.vue

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script lang="ts" setup>
22
import type { CSSProperties } from 'vue'
33
import type { EdgeProps, GraphNode, MarkerType } from '@vue-flow/core'
4-
import { getBezierPath } from '@vue-flow/core'
4+
import { BaseEdge, getBezierPath } from '@vue-flow/core'
55
import { getEdgeParams } from './floating-edge-utils'
66
77
interface FloatingEdgeProps extends EdgeProps {
@@ -20,7 +20,7 @@ const props = defineProps<FloatingEdgeProps>()
2020
2121
const edgeParams = computed(() => getEdgeParams(props.sourceNode, props.targetNode))
2222
23-
const d = computed(
23+
const edgePath = computed(
2424
() =>
2525
(edgeParams.value.sx &&
2626
getBezierPath({
@@ -36,7 +36,5 @@ const d = computed(
3636
</script>
3737

3838
<template>
39-
<g class="vue-flow__connection">
40-
<path :id="id" class="vue-flow__edge-path" :d="d[0]" :marker-start="markerStart" :marker-end="markerEnd" :style="style" />
41-
</g>
39+
<BaseEdge :id="id" :path="edgePath[0]" :marker-start="markerStart" :marker-end="markerEnd" :style="style" />
4240
</template>

examples/vite/src/FloatingEdges/floating-edge-utils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ function getNodeIntersection(intersectionNode: GraphNode, targetNode: GraphNode)
77
// https://math.stackexchange.com/questions/1724792/an-algorithm-for-finding-the-intersection-point-between-a-center-of-vision-and-a
88
const {
99
dimensions: { width: intersectionNodeWidth, height: intersectionNodeHeight },
10-
position: intersectionNodePosition,
10+
computedPosition: intersectionNodePosition,
1111
} = intersectionNode
12-
const targetPosition = targetNode.position
12+
const targetPosition = targetNode.computedPosition
1313

1414
const w = intersectionNodeWidth / 2
1515
const h = intersectionNodeHeight / 2
@@ -32,7 +32,7 @@ function getNodeIntersection(intersectionNode: GraphNode, targetNode: GraphNode)
3232

3333
// returns the position (top,right,bottom or right) passed node compared to the intersection point
3434
function getEdgePosition(node: GraphNode, intersectionPoint: XYPosition) {
35-
const n = { ...node.position, ...node.dimensions }
35+
const n = { ...node.computedPosition, ...node.dimensions }
3636
const nx = Math.round(n.x)
3737
const ny = Math.round(n.y)
3838
const px = Math.round(intersectionPoint.x)

0 commit comments

Comments
 (0)