-
Notifications
You must be signed in to change notification settings - Fork 1
/
CustomEdge.tsx
125 lines (119 loc) · 3.12 KB
/
CustomEdge.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import React, { FC } from 'react';
import { EdgeProps, getSmoothStepPath, EdgeLabelRenderer, BaseEdge, getBezierPath, getStraightPath} from 'reactflow';
const CustomEdge: FC<EdgeProps> = ({
id,
sourceX,
sourceY,
targetX,
targetY,
sourcePosition,
targetPosition,
data,
style,
source,
target
}) => {
let ell; //[edgePath, labelX, labelY]
if (data.type == 'smoothstep') {
ell = getSmoothStepPath({
sourceX,
sourceY,
sourcePosition,
targetX,
targetY,
targetPosition,
});
} else if (data.type == 'straight') {
ell = getStraightPath({
sourceX,
sourceY,
targetX,
targetY,
});
} else {
ell = getBezierPath({
sourceX,
sourceY,
sourcePosition,
targetX,
targetY,
targetPosition,
});
}
const unique_id = id+source+target; //generates a unique id
const [edgePath, labelX, labelY] = ell;
function descShow() {
document.getElementById(unique_id).style.display = 'block'
}
function descOff() {
document.getElementById(unique_id).style.display = 'none'
}
let rel;
if (data.label == "💀") {
rel = "murder victim"
} else if (data.label == "🐶") {
rel = "pet"
}else if (data.label == "👊🏻") {
rel = "friend"
} else {
rel = data.label
}
return (
<>
<BaseEdge id={id} path={edgePath} style={style} />
<EdgeLabelRenderer>
<div
style={{
position: 'absolute',
zIndex: 0,
transform: `translate(-50%, -50%) translate(${labelX}px,${labelY}px)`,
background: '#ffffff',
padding: 4,
paddingTop: 0,
paddingBottom: 0,
fontSize: 10,
fontWeight: 700,
border: "2px solid " + style.stroke,
borderWidth: '2px',
borderRadius: 4,
pointerEvents: 'all',
boxShadow: '0px 2px 4px rgba(0, 0, 0, 0.5)'
}}
className="nodrag nopan"
>
<span onMouseEnter={() => descShow()} onMouseLeave={() => descOff()}>{data.label}</span>
<div id={unique_id} style={{
position: 'absolute',
width:0,
height:0,
left: '115%',
bottom: '30%',
borderTop: '5px solid transparent',
borderRight: '26px solid '+ style.stroke,
borderBottom: '5px solid transparent',
display: 'none',
}}>
<span style={{
position: 'absolute',
marginLeft: 20,
marginTop: -20,
padding: 7,
paddingTop: 0,
paddingBottom: 0,
textAlign: 'center',
borderRadius: '6px',
color: '#000',
backgroundColor: '#fff',
width: '200px',
border: "2px solid " + style.stroke,
fontWeight: "normal"
}}>
{target + " is " + rel + " of " + source.replace(' + ', ' and ') + "."}
</span>
</div>
</div>
</EdgeLabelRenderer>
</>
);
};
export default CustomEdge;