@@ -23,6 +23,18 @@ Layout algorithm. Currently can be one of [`random_layout`,
2323`spectral_layout`].
2424Default: `spring_layout`
2525
26+ `title`
27+ Plot title. Default: `""`
28+
29+ `title_color`
30+ Plot title color. Default: `colorant"black"`
31+
32+ `title_size`
33+ Plot title size. Default: `4.0`
34+
35+ `font_family`
36+ Font family for all text. Default: `"Helvetica"`
37+
2638`NODESIZE`
2739Max size for the nodes. Default: `3.0/sqrt(N)`
2840
@@ -102,6 +114,10 @@ Padding for the plot margins. Default: `0mm`
102114"""
103115function gplot (g:: AbstractGraph{T} ,
104116 locs_x_in:: Vector{R1} , locs_y_in:: Vector{R2} ;
117+ title = " " ,
118+ title_color = colorant " black" ,
119+ title_size = 4.0 ,
120+ font_family = " Helvetica" ,
105121 nodelabel = nothing ,
106122 nodelabelc = colorant " black" ,
107123 nodelabelsize = 1.0 ,
@@ -217,37 +233,35 @@ function gplot(g::AbstractGraph{T},
217233 end
218234
219235 # Create lines and arrow heads
220- lines, arrows = nothing , nothing
236+ lines, larrows = nothing , nothing
237+ curves, carrows = nothing , nothing
221238 if linetype == " curve"
222- if arrowlengthfrac > 0.0
223- curves_cord, arrows_cord = graphcurve (g, locs_x, locs_y, nodesize, arrowlengthfrac, arrowangleoffset, outangle)
224- lines = curve (curves_cord[:,1 ], curves_cord[:,2 ], curves_cord[:,3 ], curves_cord[:,4 ])
225- arrows = line (arrows_cord)
226- else
227- curves_cord = graphcurve (g, locs_x, locs_y, nodesize, outangle)
228- lines = curve (curves_cord[:,1 ], curves_cord[:,2 ], curves_cord[:,3 ], curves_cord[:,4 ])
229- end
239+ curves, carrows = build_curved_edges (g, locs_x, locs_y, nodesize, arrowlengthfrac, arrowangleoffset, outangle)
240+ elseif has_self_loops (g)
241+ lines, larrows, curves, carrows = build_straight_curved_edges (g, locs_x, locs_y, nodesize, arrowlengthfrac, arrowangleoffset, outangle)
230242 else
231- if arrowlengthfrac > 0.0
232- lines_cord, arrows_cord = graphline (g, locs_x, locs_y, nodesize, arrowlengthfrac, arrowangleoffset)
233- lines = line (lines_cord)
234- arrows = line (arrows_cord)
235- else
236- lines_cord = graphline (g, locs_x, locs_y, nodesize)
237- lines = line (lines_cord)
238- end
243+ lines, larrows = build_straight_edges (g, locs_x, locs_y, nodesize, arrowlengthfrac, arrowangleoffset)
239244 end
240245
246+ # Set plot_size
241247 if length (plot_size) != 2 || ! isa (plot_size[1 ], Compose. AbsoluteLength) || ! isa (plot_size[2 ], Compose. AbsoluteLength)
242248 error (" `plot_size` must be a Tuple of lengths" )
243249 end
244250 Compose. set_default_graphic_size (plot_size... )
245- compose (context (units= UnitBox (- 1.2 , - 1.2 , + 2.4 , + 2.4 ; leftpad, rightpad, toppad, bottompad)),
246- compose (context (), texts, fill (nodelabelc), stroke (nothing ), fontsize (nodelabelsize)),
251+
252+ # Fix title offset
253+ title_offset = isempty (title) ? 0 : 0.1 * title_size/ 4
254+
255+ # Build figure
256+ compose (context (units= UnitBox (- 1.2 , - 1.2 - title_offset, + 2.4 , + 2.4 + title_offset; leftpad, rightpad, toppad, bottompad)),
257+ compose (context (), text (0 , - 1.2 - title_offset/ 2 , title, hcenter, vcenter), fill (title_color), fontsize (title_size), font (font_family)),
258+ compose (context (), texts, fill (nodelabelc), fontsize (nodelabelsize), font (font_family)),
247259 compose (context (), nodes, fill (nodefillc), stroke (nodestrokec), linewidth (nodestrokelw)),
248260 compose (context (), edgetexts, fill (edgelabelc), stroke (nothing ), fontsize (edgelabelsize)),
249- compose (context (), arrows, stroke (edgestrokec), linewidth (edgelinewidth)),
250- compose (context (), lines, stroke (edgestrokec), fill (nothing ), linewidth (edgelinewidth)))
261+ compose (context (), larrows, stroke (edgestrokec), linewidth (edgelinewidth)),
262+ compose (context (), carrows, stroke (edgestrokec), linewidth (edgelinewidth)),
263+ compose (context (), lines, stroke (edgestrokec), fill (nothing ), linewidth (edgelinewidth)),
264+ compose (context (), curves, stroke (edgestrokec), fill (nothing ), linewidth (edgelinewidth)))
251265end
252266
253267function gplot (g; layout:: Function = spring_layout, keyargs... )
0 commit comments