Skip to content

Commit 1cb2399

Browse files
committed
Change arrows to triangles. Fixes point 2 in JuliaGraphs#150
1 parent ee69de0 commit 1cb2399

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

src/lines.jl

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ function graphline(edge_list, locs_x, locs_y, nodesize::Vector{T}, arrowlength,
1515
starty = locs_y[i] + nodesize[i]*sin(θ)
1616
endx = locs_x[j] + nodesize[j]*cos+π)
1717
endy = locs_y[j] + nodesize[j]*sin+π)
18-
lines[e_idx] = [(startx, starty), (endx, endy)]
1918
arr1, arr2 = arrowcoords(θ, endx, endy, arrowlength, angleoffset)
19+
endx0 = (arr1[1] + arr2[1]) / 2
20+
endy0 = (arr1[2] + arr2[2]) / 2
21+
lines[e_idx] = [(startx, starty), (endx0, endy0)]
2022
arrows[e_idx] = [arr1, (endx, endy), arr2]
2123
end
2224
lines, arrows
@@ -36,8 +38,10 @@ function graphline(edge_list, locs_x, locs_y, nodesize::Real, arrowlength, angle
3638
starty = locs_y[i] + nodesize*sin(θ)
3739
endx = locs_x[j] + nodesize*cos+π)
3840
endy = locs_y[j] + nodesize*sin+π)
39-
lines[e_idx] = [(startx, starty), (endx, endy)]
4041
arr1, arr2 = arrowcoords(θ, endx, endy, arrowlength, angleoffset)
42+
endx0 = (arr1[1] + arr2[1]) / 2
43+
endy0 = (arr1[2] + arr2[2]) / 2
44+
lines[e_idx] = [(startx, starty), (endx0, endy0)]
4145
arrows[e_idx] = [arr1, (endx, endy), arr2]
4246
end
4347
lines, arrows
@@ -100,9 +104,10 @@ function graphcurve(edge_list, locs_x, locs_y, nodesize::Vector{T}, arrowlength,
100104
d = 2 * π * nodesize[i]
101105
end
102106

103-
curves[e_idx, :] = curveedge(startx, starty, endx, endy, θ, outangle, d)
104-
105107
arr1, arr2 = arrowcoords-outangle, endx, endy, arrowlength, angleoffset)
108+
endx0 = (arr1[1] + arr2[1]) / 2
109+
endy0 = (arr1[2] + arr2[2]) / 2
110+
curves[e_idx, :] = curveedge(startx, starty, endx0, endy0, θ, outangle, d)
106111
arrows[e_idx] = [arr1, (endx, endy), arr2]
107112
end
108113
return curves, arrows
@@ -129,9 +134,10 @@ function graphcurve(edge_list, locs_x, locs_y, nodesize::Real, arrowlength, angl
129134
d = 2 * π * nodesize
130135
end
131136

132-
curves[e_idx, :] = curveedge(startx, starty, endx, endy, θ, outangle, d)
133-
134137
arr1, arr2 = arrowcoords-outangle, endx, endy, arrowlength, angleoffset)
138+
endx0 = (arr1[1] + arr2[1]) / 2
139+
endy0 = (arr1[2] + arr2[2]) / 2
140+
curves[e_idx, :] = curveedge(startx, starty, endx0, endy0, θ, outangle, d)
135141
arrows[e_idx] = [arr1, (endx, endy), arr2]
136142
end
137143
return curves, arrows
@@ -214,7 +220,7 @@ function build_curved_edges(edge_list, locs_x, locs_y, nodesize, arrowlengthfrac
214220
if arrowlengthfrac > 0.0
215221
curves_cord, arrows_cord = graphcurve(edge_list, locs_x, locs_y, nodesize, arrowlengthfrac, arrowangleoffset, outangle)
216222
curves = curve(curves_cord[:,1], curves_cord[:,2], curves_cord[:,3], curves_cord[:,4])
217-
carrows = line(arrows_cord)
223+
carrows = polygon(arrows_cord)
218224
else
219225
curves_cord = graphcurve(edge_list, locs_x, locs_y, nodesize, outangle)
220226
curves = curve(curves_cord[:,1], curves_cord[:,2], curves_cord[:,3], curves_cord[:,4])
@@ -228,7 +234,7 @@ function build_straight_edges(edge_list, locs_x, locs_y, nodesize, arrowlengthfr
228234
if arrowlengthfrac > 0.0
229235
lines_cord, arrows_cord = graphline(edge_list, locs_x, locs_y, nodesize, arrowlengthfrac, arrowangleoffset)
230236
lines = line(lines_cord)
231-
larrows = line(arrows_cord)
237+
larrows = polygon(arrows_cord)
232238
else
233239
lines_cord = graphline(edge_list, locs_x, locs_y, nodesize)
234240
lines = line(lines_cord)

src/plot.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,8 @@ function gplot(g::AbstractGraph{T},
276276
compose(context(), texts, fill(nodelabelc), fontsize(nodelabelsize), font(font_family)),
277277
compose(context(), nodes, fill(nodefillc), stroke(nodestrokec), linewidth(nodestrokelw)),
278278
compose(context(), edgetexts, fill(edgelabelc), fontsize(edgelabelsize)),
279-
compose(context(), larrows, stroke(edgestrokec), linewidth(edgelinewidth)),
280-
compose(context(), carrows, stroke(edgestrokec), linewidth(edgelinewidth)),
279+
compose(context(), larrows, fill(edgestrokec)),
280+
compose(context(), carrows, fill(edgestrokec)),
281281
compose(context(), lines, stroke(edgestrokec), linewidth(edgelinewidth)),
282282
compose(context(), curves, stroke(edgestrokec), linewidth(edgelinewidth)),
283283
compose(context(units=UnitBox(plot_area...)), rectangle(plot_area...), fill(background_color))

0 commit comments

Comments
 (0)