1
1
# Edge
2
2
3
- All default edge components are exported and can be used or extended if necessary.
3
+ Vue Flow exports a couple of utilities you can use to create your own custom edges without having to worry how to actually
4
+ implement the edge path calculation.
5
+
6
+ This can be helpful if you don't want to actually change the way the edge path is calculated
7
+ but just want to implement some custom logic on top of the regular edge behavior.
8
+
9
+ Alternatively, all default edge components are also exported and can be used to create custom edges.
4
10
5
11
``` vue
6
12
<script lang="ts" setup>
7
13
// CustomEdge.vue
8
- import { EdgeProps, BezierEdge } from '@vue-flow/core'
14
+ import { EdgeProps, BezierEdge, SmoothStepEdge, StepEdge, StraightEdge } from '@vue-flow/core'
9
15
10
16
const props = defineProps<EdgeProps>()
11
17
@@ -17,54 +23,161 @@ const props = defineProps<EdgeProps>()
17
23
</template>
18
24
```
19
25
20
- ## Path utils
26
+ ## [ getBezierPath] ( /typedocs/functions/getBezierPath )
27
+
28
+ - Details:
29
+
30
+ A function that returns a bezier path and center positions.
31
+
32
+ - Arguments:
33
+ - ` sourceX ` : The x position of the source handle.
34
+ - ` sourceY ` : The y position of the source handle.
35
+ - ` sourcePosition ` : The position of the source handle.
36
+ - ` targetX ` : The x position of the target handle.
37
+ - ` targetY ` : The y position of the target handle.
38
+ - ` targetPosition ` : The position of the target handle.
39
+ - ` curvature ` : The curvature of the path.
40
+
41
+ - Returns:
42
+ - ` path ` : A string representing the path.
43
+ - ` labelX ` : The x position of the label.
44
+ - ` labelY ` : The y position of the label.
45
+ - ` offsetX ` : The x offset of the label.
46
+ - ` offsetY ` : The y offset of the label.
47
+
48
+ - Example:
21
49
22
- Vue Flow exports a couple of functions you can use to create your own custom edges without having to worry how to actually
23
- create a bezier path.
50
+ ``` vue
51
+ <script lang="ts" setup>
52
+ import { computed } from "vue"
53
+ import { BaseEdge, getBezierPath, EdgeProps } from '@vue-flow/core'
24
54
25
- This can be helpful if you don't want to actually change the way the path is calculated but just want to implement some custom logic on top of the
26
- regular edge behavior.
55
+ const props = defineProps<EdgeProps>()
56
+
57
+ const edgePathParams = computed(() => getBezierPath({ ...props, curvature: 0.5 }))
58
+ </script>
59
+
60
+ <template>
61
+ <BaseEdge :path="edgePathParams[0]" />
62
+ </template>
63
+ ```
27
64
28
- ### [ getBezierPath ] ( /typedocs/functions/getBezierPath )
65
+ ## [ getSimpleBezierPath ] ( /typedocs/functions/getSimpleBezierPath )
29
66
30
67
- Details:
31
68
32
- Returns a bezier path and center positions.
69
+ A function that returns a simple bezier path (no curvature from and toward handles) and center positions.
33
70
34
- ### getBezierCenter (removed)
71
+ - Arguments:
72
+ - ` sourceX ` : The x position of the source handle.
73
+ - ` sourceY ` : The y position of the source handle.
74
+ - ` sourcePosition ` : The position of the source handle.
75
+ - ` targetX ` : The x position of the target handle.
76
+ - ` targetY ` : The y position of the target handle.
77
+ - ` targetPosition ` : The position of the target handle.
35
78
36
- ::: warning
37
- This function has been removed. The edge center positions are returned by ` getBezierPath ` now.
38
- :::
79
+ - Returns:
80
+ - ` path ` : A string representing the path.
81
+ - ` labelX ` : The x position of the label.
82
+ - ` labelY ` : The y position of the label.
83
+ - ` offsetX ` : The x offset of the label.
84
+ - ` offsetY ` : The y offset of the label.
39
85
40
- - Details:
86
+ - Example:
87
+
88
+ ``` vue
89
+ <script lang="ts" setup>
90
+ import { computed } from "vue"
91
+ import { BaseEdge, getSimpleBezierPath, EdgeProps } from '@vue-flow/core'
41
92
42
- Returns a bezier path's center x and y values.
93
+ const props = defineProps<EdgeProps>()
94
+
95
+ const edgePathParams = computed(() => getSimpleBezierPath(props))
96
+ </script>
97
+
98
+ <template>
99
+ <BaseEdge :path="edgePathParams[0]" />
100
+ </template>
101
+ ```
43
102
44
- ### [ getSimpleBezierPath ] ( /typedocs/functions/getSimpleBezierPath )
103
+ ## [ getSmoothStepPath ] ( /typedocs/functions/getSmoothStepPath )
45
104
46
105
- Details:
47
106
48
- Returns a simple bezier path (no curvature at handles) and center positions.
107
+ A function that returns a smoothstep path (you can use a ` borderRadius ` 0 for a step path).
108
+
109
+ - Arguments:
110
+ - ` sourceX ` : The x position of the source handle.
111
+ - ` sourceY ` : The y position of the source handle.
112
+ - ` sourcePosition ` : The position of the source handle.
113
+ - ` targetX ` : The x position of the target handle.
114
+ - ` targetY ` : The y position of the target handle.
115
+ - ` targetPosition ` : The position of the target handle.
116
+ - ` centerX ` : The x position of the center.
117
+ - ` centerY ` : The y position of the center.
118
+ - ` offset ` : The offset of the path.
119
+ - ` borderRadius ` : The border radius of the path.
120
+
121
+ ::: info
122
+ You can use ` borderRadius: 0 ` to create a step path with no smooth corners.
123
+ :::
124
+
125
+ - Returns:
126
+ - ` path ` : A string representing the path.
127
+ - ` labelX ` : The x position of the label.
128
+ - ` labelY ` : The y position of the label.
129
+ - ` offsetX ` : The x offset of the label.
130
+ - ` offsetY ` : The y offset of the label.
131
+
132
+ - Example:
49
133
50
- ### getSimpleBezierCenter (removed)
134
+ ``` vue
135
+ <script lang="ts" setup>
136
+ import { computed } from "vue"
137
+ import { BaseEdge, getSmoothStepPath, EdgeProps } from '@vue-flow/core'
51
138
52
- ::: warning
53
- This function has been removed. The edge center positions are returned by ` getSimpleBezierPath ` now.
54
- :::
139
+ const props = defineProps<EdgeProps>()
55
140
56
- - Details:
141
+ const edgePathParams = computed(() => getSmoothStepPath({ ...props, borderRadius: 8 }))
142
+ </script>
57
143
58
- Returns a simple bezier path's center x and y values.
144
+ <template>
145
+ <BaseEdge :path="edgePathParams[0]" />
146
+ </template>
147
+ ```
59
148
60
- ### [ getSmoothStepPath ] ( /typedocs/functions/getSmoothStepPath )
149
+ ## [ getStraightPath ] ( /typedocs/functions/getStraightPath )
61
150
62
151
- Details:
63
152
64
- Returns a smoothstep path (use border-radius 0 for a step path) .
153
+ A function that returns a straight path.
65
154
66
- ### [ getStraightPath] ( /typedocs/functions/getStraightPath )
155
+ - Arguments:
156
+ - ` sourceX ` : The x position of the source handle.
157
+ - ` sourceY ` : The y position of the source handle.
158
+ - ` targetX ` : The x position of the target handle.
159
+ - ` targetY ` : The y position of the target handle.
67
160
68
- - Details:
161
+ - Returns:
162
+ - ` path ` : A string representing the path.
163
+ - ` labelX ` : The x position of the label.
164
+ - ` labelY ` : The y position of the label.
165
+ - ` offsetX ` : The x offset of the label.
166
+ - ` offsetY ` : The y offset of the label.
69
167
70
- Returns a straight path.
168
+ - Example:
169
+
170
+ ``` vue
171
+ <script lang="ts" setup>
172
+ import { computed } from "vue"
173
+ import { BaseEdge, getStraightPath, EdgeProps } from '@vue-flow/core'
174
+
175
+ const props = defineProps<EdgeProps>()
176
+
177
+ const edgePathParams = computed(() => getStraightPath(props))
178
+ </script>
179
+
180
+ <template>
181
+ <BaseEdge :path="edgePathParams[0]" />
182
+ </template>
183
+ ```
0 commit comments