1
1
<script setup lang="ts">
2
- import type { BarPosition , ConnectionType } from " ../types"
2
+ import type { BarPosition , ConnectionType , MarkerConnection } from " ../types"
3
3
import { computed , ref } from " vue"
4
4
5
5
interface Props {
@@ -11,6 +11,7 @@ interface Props {
11
11
pattern? : " solid" | " dash" | " dot" | " dashdot"
12
12
animated? : boolean
13
13
animationSpeed? : " slow" | " normal" | " fast"
14
+ marker: MarkerConnection
14
15
}
15
16
16
17
const props = withDefaults (defineProps <Props >(), {
@@ -29,41 +30,46 @@ const animationClass = computed(() => {
29
30
return ` connector-animated-${props .pattern }-${props .animationSpeed } `
30
31
})
31
32
33
+ const markerId = computed (() => ` marker-start-${props .sourceBar .id }-${props .targetBar .id } ` )
34
+ const hasMarkerEnd = computed (() => props .marker === " bidirectional" || props .marker === " forward" )
35
+ const hasMarkerStart = computed (() => props .marker === " bidirectional" )
36
+ const markerDeltaEnd = computed (() => (hasMarkerEnd .value ? 4 : 0 ))
37
+ const markerDeltaStart = computed (() => (hasMarkerStart .value ? 4 : 0 ))
38
+
32
39
const pathData = computed (() => {
33
40
const sourceX = props .sourceBar .x + props .sourceBar .width
34
41
const sourceY = props .sourceBar .y + props .sourceBar .height / 2
35
42
const targetX = props .targetBar .x
36
43
const targetY = props .targetBar .y + props .targetBar .height / 2
37
44
38
45
const OFFSET = 20
39
- const isGoingBack = targetX < sourceX
40
-
46
+ const isGoingBack = targetX <= sourceX
41
47
switch (props .type ) {
42
48
case " straight" :
43
- return ` M ${sourceX },${sourceY } L ${targetX - 4 },${targetY } `
49
+ return ` M ${sourceX },${sourceY } L ${targetX - markerDeltaEnd . value },${targetY } `
44
50
45
51
case " squared" :
46
52
if (isGoingBack ) {
47
- return ` M ${sourceX },${sourceY }
53
+ return ` M ${sourceX + markerDeltaStart . value },${sourceY }
48
54
h ${OFFSET }
49
55
v ${(targetY - sourceY ) / 2 }
50
56
h -${Math .abs (targetX - sourceX ) + OFFSET * 2 }
51
57
v ${(targetY - sourceY ) / 2 }
52
- h ${OFFSET - 4 } `
58
+ h ${OFFSET - markerDeltaEnd . value * 2 } `
53
59
}
54
60
55
- return ` M ${sourceX },${sourceY }
61
+ return ` M ${sourceX + markerDeltaStart . value },${sourceY }
56
62
h ${OFFSET }
57
63
v ${targetY - sourceY }
58
- h ${targetX - sourceX - OFFSET - 4 } `
64
+ h ${targetX - sourceX - OFFSET - markerDeltaEnd . value * 2 } `
59
65
60
66
case " bezier" :
61
67
default :
62
68
const controlPointX = (sourceX + targetX ) / 2
63
- return ` M ${sourceX },${sourceY }
69
+ return ` M ${sourceX + markerDeltaStart . value },${sourceY }
64
70
C ${controlPointX },${sourceY }
65
71
${controlPointX },${targetY }
66
- ${targetX - 4 },${targetY } `
72
+ ${targetX - markerDeltaEnd . value },${targetY } `
67
73
}
68
74
})
69
75
@@ -81,8 +87,6 @@ const nonAnimatedDashArray = computed(() => {
81
87
return " "
82
88
}
83
89
})
84
-
85
- const markerId = computed (() => ` marker-start-${props .sourceBar .id }-${props .targetBar .id } ` )
86
90
</script >
87
91
88
92
<template >
@@ -152,8 +156,8 @@ const markerId = computed(() => `marker-start-${props.sourceBar.id}-${props.targ
152
156
:stroke-dasharray =" nonAnimatedDashArray"
153
157
:class =" ['connector-path', animationClass]"
154
158
:style =" {
155
- markerStart: 'none',
156
- markerEnd: `url(#${markerId})`
159
+ markerStart: hasMarkerStart ? `url(#${markerId})` : 'none',
160
+ markerEnd: hasMarkerEnd ? `url(#${markerId})` : 'none'
157
161
}"
158
162
/>
159
163
</svg >
0 commit comments