Skip to content

Commit 0f9ca82

Browse files
committed
fix visualization of double sided arcs
1 parent 419655a commit 0f9ca82

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

src/lines.jl

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
"""
22
Return lines and arrow heads
33
"""
4+
function midpoint(pt1,pt2)
5+
x = (pt1[1] + pt2[1]) / 2
6+
y = (pt1[2] + pt2[2]) / 2
7+
return x,y
8+
end
9+
410
function graphline(edge_list, locs_x, locs_y, nodesize::Vector{T}, arrowlength, angleoffset) where {T<:Real}
511
num_edges = length(edge_list)
612
lines = Array{Vector{Tuple{Float64,Float64}}}(undef, num_edges)
@@ -16,8 +22,12 @@ function graphline(edge_list, locs_x, locs_y, nodesize::Vector{T}, arrowlength,
1622
endx = locs_x[j] + nodesize[j]*cos+π)
1723
endy = locs_y[j] + nodesize[j]*sin+π)
1824
arr1, arr2 = arrowcoords(θ, endx, endy, arrowlength, angleoffset)
19-
endx0 = (arr1[1] + arr2[1]) / 2
20-
endy0 = (arr1[2] + arr2[2]) / 2
25+
endx0, endy0 = midpoint(arr1, arr2)
26+
if Edge(j,i) in edge_list[1:e_idx-1] #check if a reverse arc exists
27+
e_idx2 = findfirst(==(Edge(j,i)), edge_list) #get index of reverse arc
28+
startx, starty = midpoint(arrows[e_idx2][[1,3]]...) #get midopint of reverse arc and use as new start point
29+
lines[e_idx2][1] = (endx0, endy0) #update endpoint of reverse arc
30+
end
2131
lines[e_idx] = [(startx, starty), (endx0, endy0)]
2232
arrows[e_idx] = [arr1, (endx, endy), arr2]
2333
end
@@ -39,8 +49,12 @@ function graphline(edge_list, locs_x, locs_y, nodesize::Real, arrowlength, angle
3949
endx = locs_x[j] + nodesize*cos+π)
4050
endy = locs_y[j] + nodesize*sin+π)
4151
arr1, arr2 = arrowcoords(θ, endx, endy, arrowlength, angleoffset)
42-
endx0 = (arr1[1] + arr2[1]) / 2
43-
endy0 = (arr1[2] + arr2[2]) / 2
52+
endx0, endy0 = midpoint(arr1, arr2)
53+
if Edge(j,i) in edge_list[1:e_idx-1] #check if a reverse arc exists
54+
e_idx2 = findfirst(==(Edge(j,i)), edge_list) #get index of reverse arc
55+
startx, starty = midpoint(arrows[e_idx2][[1,3]]...) #get midopint of reverse arc and use as new start point
56+
lines[e_idx2][1] = (endx0, endy0) #update endpoint of reverse arc
57+
end
4458
lines[e_idx] = [(startx, starty), (endx0, endy0)]
4559
arrows[e_idx] = [arr1, (endx, endy), arr2]
4660
end

0 commit comments

Comments
 (0)