@@ -9,12 +9,11 @@ function graphline(g, locs_x, locs_y, nodesize::Vector{T}, arrowlength, angleoff
9
9
j = dst (e)
10
10
Δx = locs_x[j] - locs_x[i]
11
11
Δy = locs_y[j] - locs_y[i]
12
- d = sqrt (Δx^ 2 + Δy^ 2 )
13
- θ = atan (Δy,Δx)
12
+ θ = atan (Δy,Δx)
14
13
startx = locs_x[i] + nodesize[i]* cos (θ)
15
14
starty = locs_y[i] + nodesize[i]* sin (θ)
16
- endx = locs_x[i ] + (d - nodesize[j]) * 1.00 * cos (θ)
17
- endy = locs_y[i ] + (d - nodesize[j]) * 1.00 * sin (θ)
15
+ endx = locs_x[j ] + nodesize[j]* cos (θ+ π )
16
+ endy = locs_y[j ] + nodesize[j]* sin (θ+ π )
18
17
lines[e_idx] = [(startx, starty), (endx, endy)]
19
18
arr1, arr2 = arrowcoords (θ, endx, endy, arrowlength, angleoffset)
20
19
arrows[e_idx] = [arr1, (endx, endy), arr2]
@@ -30,12 +29,11 @@ function graphline(g::AbstractGraph{T}, locs_x, locs_y, nodesize::Real, arrowlen
30
29
j = dst (e)
31
30
Δx = locs_x[j] - locs_x[i]
32
31
Δy = locs_y[j] - locs_y[i]
33
- d = sqrt (Δx^ 2 + Δy^ 2 )
34
- θ = atan (Δy,Δx)
32
+ θ = atan (Δy,Δx)
35
33
startx = locs_x[i] + nodesize* cos (θ)
36
34
starty = locs_y[i] + nodesize* sin (θ)
37
- endx = locs_x[i ] + (d - nodesize) * 1.00 * cos (θ)
38
- endy = locs_y[i ] + (d - nodesize) * 1.00 * sin (θ)
35
+ endx = locs_x[j ] + nodesize* cos (θ+ π )
36
+ endy = locs_y[j ] + nodesize* sin (θ+ π )
39
37
lines[e_idx] = [(startx, starty), (endx, endy)]
40
38
arr1, arr2 = arrowcoords (θ, endx, endy, arrowlength, angleoffset)
41
39
arrows[e_idx] = [arr1, (endx, endy), arr2]
@@ -50,12 +48,11 @@ function graphline(g::AbstractGraph{T}, locs_x, locs_y, nodesize::Vector{<:Real}
50
48
j = dst (e)
51
49
Δx = locs_x[j] - locs_x[i]
52
50
Δy = locs_y[j] - locs_y[i]
53
- d = sqrt (Δx^ 2 + Δy^ 2 )
54
- θ = atan (Δy,Δx)
51
+ θ = atan (Δy,Δx)
55
52
startx = locs_x[i] + nodesize[i]* cos (θ)
56
53
starty = locs_y[i] + nodesize[i]* sin (θ)
57
- endx = locs_x[i ] + (d - nodesize[j]) * 1.00 * cos (θ)
58
- endy = locs_y[i ] + (d - nodesize[j]) * 1.00 * sin (θ)
54
+ endx = locs_x[j ] + nodesize[j]* cos (θ+ π )
55
+ endy = locs_y[j ] + nodesize[j]* sin (θ+ π )
59
56
lines[e_idx] = [(startx, starty), (endx, endy)]
60
57
end
61
58
lines
@@ -68,103 +65,118 @@ function graphline(g::AbstractGraph{T}, locs_x, locs_y, nodesize::Real) where {T
68
65
j = dst (e)
69
66
Δx = locs_x[j] - locs_x[i]
70
67
Δy = locs_y[j] - locs_y[i]
71
- d = sqrt (Δx^ 2 + Δy^ 2 )
72
- θ = atan (Δy,Δx)
68
+ θ = atan (Δy,Δx)
73
69
startx = locs_x[i] + nodesize* cos (θ)
74
70
starty = locs_y[i] + nodesize* sin (θ)
75
- endx = locs_x[i ] + (d - nodesize) * 1.00 * cos (θ)
76
- endy = locs_y[i ] + (d - nodesize) * 1.00 * sin (θ)
71
+ endx = locs_x[j ] + nodesize* cos (θ+ π )
72
+ endy = locs_y[j ] + nodesize* sin (θ+ π )
77
73
lines[e_idx] = [(startx, starty), (endx, endy)]
78
74
end
79
75
return lines
80
76
end
81
77
82
78
function graphcurve (g:: AbstractGraph{T} , locs_x, locs_y, nodesize:: Vector{<:Real} , arrowlength, angleoffset, outangle= pi / 5 ) where {T<: Integer }
83
- lines = Array {Vector} ( ne (g))
79
+ curves = Matrix {Tuple{Float64,Float64}} (undef, ne (g), 4 )
84
80
arrows = Array {Vector{Tuple{Float64,Float64}}} (undef, ne (g))
85
81
for (e_idx, e) in enumerate (edges (g))
86
82
i = src (e)
87
83
j = dst (e)
88
84
Δx = locs_x[j] - locs_x[i]
89
85
Δy = locs_y[j] - locs_y[i]
90
- d = sqrt (Δx^ 2 + Δy^ 2 )
91
- θ = atan (Δy,Δx)
92
- startx = locs_x[i] + nodesize[i]* cos (θ)
93
- starty = locs_y[i] + nodesize[i]* sin (θ)
94
- endx = locs_x[i] + (d- nodesize[j])* 1.00 * cos (θ)
95
- endy = locs_y[i] + (d- nodesize[j])* 1.00 * sin (θ)
96
- lines[e_idx] = curveedge (startx, starty, endx, endy, outangle)
97
- if startx <= endx
98
- arr1, arr2 = curvearrowcoords1 (θ, outangle, endx, endy, arrowlength, angleoffset)
99
- arrows[e_idx] = [arr1, (endx, endy), arr2]
100
- else
101
- arr1, arr2 = curvearrowcoords2 (θ, outangle, endx, endy, arrowlength, angleoffset)
102
- arrows[e_idx] = [arr1, (endx, endy), arr2]
86
+ θ = atan (Δy,Δx)
87
+ startx = locs_x[i] + nodesize[i]* cos (θ+ outangle)
88
+ starty = locs_y[i] + nodesize[i]* sin (θ+ outangle)
89
+ endx = locs_x[j] + nodesize[j]* cos (θ+ π- outangle)
90
+ endy = locs_y[j] + nodesize[j]* sin (θ+ π- outangle)
91
+
92
+ d = hypot (endx- startx, endy- starty)
93
+
94
+ if i == j
95
+ d = 2 * π * nodesize[i]
103
96
end
97
+
98
+ curves[e_idx, :] = curveedge (startx, starty, endx, endy, θ, outangle, d)
99
+
100
+ arr1, arr2 = arrowcoords (θ- outangle, endx, endy, arrowlength, angleoffset)
101
+ arrows[e_idx] = [arr1, (endx, endy), arr2]
104
102
end
105
- return lines , arrows
103
+ return curves , arrows
106
104
end
107
105
108
106
function graphcurve (g, locs_x, locs_y, nodesize:: Real , arrowlength, angleoffset, outangle= pi / 5 )
109
- lines = Array {Vector} ( ne (g))
107
+ curves = Matrix {Tuple{Float64,Float64}} (undef, ne (g), 4 )
110
108
arrows = Array {Vector{Tuple{Float64,Float64}}} (undef, ne (g))
111
109
for (e_idx, e) in enumerate (edges (g))
112
110
i = src (e)
113
111
j = dst (e)
114
112
Δx = locs_x[j] - locs_x[i]
115
113
Δy = locs_y[j] - locs_y[i]
116
- d = sqrt (Δx^ 2 + Δy^ 2 )
117
- θ = atan (Δy,Δx)
118
- startx = locs_x[i] + nodesize* cos (θ)
119
- starty = locs_y[i] + nodesize* sin (θ)
120
- endx = locs_x[i] + (d- nodesize)* 1.00 * cos (θ)
121
- endy = locs_y[i] + (d- nodesize)* 1.00 * sin (θ)
122
- lines[e_idx] = curveedge (startx, starty, endx, endy, outangle)
123
- if startx <= endx
124
- arr1, arr2 = curvearrowcoords1 (θ, outangle, endx, endy, arrowlength, angleoffset)
125
- arrows[e_idx] = [arr1, (endx, endy), arr2]
126
- else
127
- arr1, arr2 = curvearrowcoords2 (θ, outangle, endx, endy, arrowlength, angleoffset)
128
- arrows[e_idx] = [arr1, (endx, endy), arr2]
114
+ θ = atan (Δy,Δx)
115
+ startx = locs_x[i] + nodesize* cos (θ+ outangle)
116
+ starty = locs_y[i] + nodesize* sin (θ+ outangle)
117
+ endx = locs_x[j] + nodesize* cos (θ+ π- outangle)
118
+ endy = locs_y[j] + nodesize* sin (θ+ π- outangle)
119
+
120
+ d = hypot (endx- startx, endy- starty)
121
+
122
+ if i == j
123
+ d = 2 * π * nodesize
129
124
end
125
+
126
+ curves[e_idx, :] = curveedge (startx, starty, endx, endy, θ, outangle, d)
127
+
128
+ arr1, arr2 = arrowcoords (θ- outangle, endx, endy, arrowlength, angleoffset)
129
+ arrows[e_idx] = [arr1, (endx, endy), arr2]
130
130
end
131
- return lines , arrows
131
+ return curves , arrows
132
132
end
133
133
134
134
function graphcurve (g, locs_x, locs_y, nodesize:: Real , outangle)
135
- lines = Array {Vector} ( ne (g))
135
+ curves = Matrix {Tuple{Float64,Float64}} (undef, ne (g), 4 )
136
136
for (e_idx, e) in enumerate (edges (g))
137
137
i = src (e)
138
138
j = dst (e)
139
139
Δx = locs_x[j] - locs_x[i]
140
140
Δy = locs_y[j] - locs_y[i]
141
- d = sqrt (Δx^ 2 + Δy^ 2 )
142
- θ = atan (Δy,Δx)
143
- startx = locs_x[i] + nodesize* cos (θ)
144
- starty = locs_y[i] + nodesize* sin (θ)
145
- endx = locs_x[i] + (d- nodesize)* 1.00 * cos (θ)
146
- endy = locs_y[i] + (d- nodesize)* 1.00 * sin (θ)
147
- lines[e_idx] = curveedge (startx, starty, endx, endy, outangle)
141
+ θ = atan (Δy,Δx)
142
+ startx = locs_x[i] + nodesize* cos (θ+ outangle)
143
+ starty = locs_y[i] + nodesize* sin (θ+ outangle)
144
+ endx = locs_x[j] + nodesize* cos (θ+ π- outangle)
145
+ endy = locs_y[j] + nodesize* sin (θ+ π- outangle)
146
+
147
+ d = hypot (endx- startx, endy- starty)
148
+
149
+ if i == j
150
+ d = 2 * π * nodesize
151
+ end
152
+
153
+ curves[e_idx, :] = curveedge (startx, starty, endx, endy, θ, outangle, d)
148
154
end
149
- lines
155
+ return curves
150
156
end
151
157
152
158
function graphcurve (g:: AbstractGraph{T} , locs_x, locs_y, nodesize:: Vector{<:Real} , outangle) where {T<: Integer }
153
- lines = Array {Vector} ( ne (g))
159
+ curves = Matrix {Tuple{Float64,Float64}} (undef, ne (g), 4 )
154
160
for (e_idx, e) in enumerate (edges (g))
155
161
i = src (e)
156
162
j = dst (e)
157
163
Δx = locs_x[j] - locs_x[i]
158
164
Δy = locs_y[j] - locs_y[i]
159
- d = sqrt (Δx^ 2 + Δy^ 2 )
160
- θ = atan (Δy,Δx)
161
- startx = locs_x[i] + nodesize* cos (θ)
162
- starty = locs_y[i] + nodesize* sin (θ)
163
- endx = locs_x[i] + (d- nodesize)* 1.00 * cos (θ)
164
- endy = locs_y[i] + (d- nodesize)* 1.00 * sin (θ)
165
- lines[e_idx] = curveedge (startx, starty, endx, endy, outangle)
165
+ θ = atan (Δy,Δx)
166
+ startx = locs_x[i] + nodesize[i]* cos (θ+ outangle)
167
+ starty = locs_y[i] + nodesize[i]* sin (θ+ outangle)
168
+ endx = locs_x[j] + nodesize[j]* cos (θ+ π- outangle)
169
+ endy = locs_y[j] + nodesize[j]* sin (θ+ π- outangle)
170
+
171
+ d = hypot (endx- startx, endy- starty)
172
+
173
+ if i == j
174
+ d = 2 * π * nodesize[i]
175
+ end
176
+
177
+ curves[e_idx, :] = curveedge (startx, starty, endx, endy, θ, outangle, d)
166
178
end
167
- return lines
179
+ return curves
168
180
end
169
181
170
182
# this function is copy from [IainNZ](https://github.com/IainNZ)'s [GraphLayout.jl](https://github.com/IainNZ/GraphLayout.jl)
@@ -176,36 +188,16 @@ function arrowcoords(θ, endx, endy, arrowlength, angleoffset=20.0/180.0*π)
176
188
return (arr1x, arr1y), (arr2x, arr2y)
177
189
end
178
190
179
- # using when startx <= endx
180
- # θ1 is the angle between line from start point to end point with x axis
181
- # θ2 is the out angle of edge
182
- function curvearrowcoords1 (θ1, θ2, endx, endy, arrowlength, angleoffset= 20.0 / 180.0 * π)
183
- arr1x = endx + arrowlength* cos (pi + θ1- θ2- angleoffset)
184
- arr1y = endy + arrowlength* sin (pi + θ1- θ2- angleoffset)
185
- arr2x = endx + arrowlength* cos (pi + θ1- θ2+ angleoffset)
186
- arr2y = endy + arrowlength* sin (pi + θ1- θ2+ angleoffset)
187
- return (arr1x, arr1y), (arr2x, arr2y)
188
- end
191
+ function curveedge (x1, y1, x2, y2, θ, outangle, d; k= 0.5 )
189
192
190
- # using when startx > endx
191
- function curvearrowcoords2 (θ1, θ2, endx, endy, arrowlength, angleoffset= 20.0 / 180.0 * π)
192
- arr1x = endx + arrowlength* cos (pi + θ1+ θ2- angleoffset)
193
- arr1y = endy + arrowlength* sin (pi + θ1+ θ2- angleoffset)
194
- arr2x = endx + arrowlength* cos (pi + θ1+ θ2+ angleoffset)
195
- arr2y = endy + arrowlength* sin (pi + θ1+ θ2+ angleoffset)
196
- return (arr1x, arr1y), (arr2x, arr2y)
197
- end
193
+ r = d * k
198
194
199
- function curveedge (x1, y1, x2, y2, θ)
200
- θ1 = atan ((y2- y1)/ (x2- x1))
201
- d = sqrt ((x2- x1)^ 2 + (y2- y1)^ 2 )
202
- r = d/ 2 cos (θ)
203
- if x1 <= x2
204
- x = x1 + r* cos (θ+ θ1)
205
- y = y1 + r* sin (θ+ θ1)
206
- else
207
- x = x2 + r* cos (θ+ θ1)
208
- y = y2 + r* sin (θ+ θ1)
209
- end
210
- return [:M , x1,y1, :Q , x, y, x2, y2]
195
+ # Control points for left bending curve.
196
+ xc1 = x1 + r * cos (θ + outangle)
197
+ yc1 = y1 + r * sin (θ + outangle)
198
+
199
+ xc2 = x2 + r * cos (θ + π - outangle)
200
+ yc2 = y2 + r * sin (θ + π - outangle)
201
+
202
+ return [(x1,y1) (xc1, yc1) (xc2, yc2) (x2, y2)]
211
203
end
0 commit comments