@@ -9,12 +9,11 @@ function graphline(g, locs_x, locs_y, nodesize::Vector{T}, arrowlength, angleoff
99 j = dst (e)
1010 Δx = locs_x[j] - locs_x[i]
1111 Δy = locs_y[j] - locs_y[i]
12- d = sqrt (Δx^ 2 + Δy^ 2 )
13- θ = atan (Δy,Δx)
12+ θ = atan (Δy,Δx)
1413 startx = locs_x[i] + nodesize[i]* cos (θ)
1514 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 (θ+ π )
1817 lines[e_idx] = [(startx, starty), (endx, endy)]
1918 arr1, arr2 = arrowcoords (θ, endx, endy, arrowlength, angleoffset)
2019 arrows[e_idx] = [arr1, (endx, endy), arr2]
@@ -30,12 +29,11 @@ function graphline(g::AbstractGraph{T}, locs_x, locs_y, nodesize::Real, arrowlen
3029 j = dst (e)
3130 Δx = locs_x[j] - locs_x[i]
3231 Δy = locs_y[j] - locs_y[i]
33- d = sqrt (Δx^ 2 + Δy^ 2 )
34- θ = atan (Δy,Δx)
32+ θ = atan (Δy,Δx)
3533 startx = locs_x[i] + nodesize* cos (θ)
3634 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 (θ+ π )
3937 lines[e_idx] = [(startx, starty), (endx, endy)]
4038 arr1, arr2 = arrowcoords (θ, endx, endy, arrowlength, angleoffset)
4139 arrows[e_idx] = [arr1, (endx, endy), arr2]
@@ -50,12 +48,11 @@ function graphline(g::AbstractGraph{T}, locs_x, locs_y, nodesize::Vector{<:Real}
5048 j = dst (e)
5149 Δx = locs_x[j] - locs_x[i]
5250 Δy = locs_y[j] - locs_y[i]
53- d = sqrt (Δx^ 2 + Δy^ 2 )
54- θ = atan (Δy,Δx)
51+ θ = atan (Δy,Δx)
5552 startx = locs_x[i] + nodesize[i]* cos (θ)
5653 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 (θ+ π )
5956 lines[e_idx] = [(startx, starty), (endx, endy)]
6057 end
6158 lines
@@ -68,103 +65,118 @@ function graphline(g::AbstractGraph{T}, locs_x, locs_y, nodesize::Real) where {T
6865 j = dst (e)
6966 Δx = locs_x[j] - locs_x[i]
7067 Δy = locs_y[j] - locs_y[i]
71- d = sqrt (Δx^ 2 + Δy^ 2 )
72- θ = atan (Δy,Δx)
68+ θ = atan (Δy,Δx)
7369 startx = locs_x[i] + nodesize* cos (θ)
7470 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 (θ+ π )
7773 lines[e_idx] = [(startx, starty), (endx, endy)]
7874 end
7975 return lines
8076end
8177
8278function 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 )
8480 arrows = Array {Vector{Tuple{Float64,Float64}}} (undef, ne (g))
8581 for (e_idx, e) in enumerate (edges (g))
8682 i = src (e)
8783 j = dst (e)
8884 Δx = locs_x[j] - locs_x[i]
8985 Δ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]
10396 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]
104102 end
105- return lines , arrows
103+ return curves , arrows
106104end
107105
108106function 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 )
110108 arrows = Array {Vector{Tuple{Float64,Float64}}} (undef, ne (g))
111109 for (e_idx, e) in enumerate (edges (g))
112110 i = src (e)
113111 j = dst (e)
114112 Δx = locs_x[j] - locs_x[i]
115113 Δ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
129124 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]
130130 end
131- return lines , arrows
131+ return curves , arrows
132132end
133133
134134function 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 )
136136 for (e_idx, e) in enumerate (edges (g))
137137 i = src (e)
138138 j = dst (e)
139139 Δx = locs_x[j] - locs_x[i]
140140 Δ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)
148154 end
149- lines
155+ return curves
150156end
151157
152158function 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 )
154160 for (e_idx, e) in enumerate (edges (g))
155161 i = src (e)
156162 j = dst (e)
157163 Δx = locs_x[j] - locs_x[i]
158164 Δ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)
166178 end
167- return lines
179+ return curves
168180end
169181
170182# 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*π)
176188 return (arr1x, arr1y), (arr2x, arr2y)
177189end
178190
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 )
189192
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
198194
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)]
211203end
0 commit comments