Skip to content

Commit bbdc0d3

Browse files
authored
Merge pull request #3 from hdavid16/add_title
Add title
2 parents 4a1002d + c2f7079 commit bbdc0d3

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@ gplot(h)
160160

161161
# Keyword Arguments
162162
+ `layout` Layout algorithm: `random_layout`, `circular_layout`, `spring_layout`, `shell_layout`, `stressmajorize_layout`, `spectral_layout`. Default: `spring_layout`
163+
+ `title` Plot title. Default: `""`
164+
+ `title_color` Plot title color. Default: `colorant"black"`
165+
+ `title_size` Plot title size. Default: `4.0`
166+
+ `font_family` Font family for all text. Default: `"Helvetica"`
163167
+ `NODESIZE` Max size for the nodes. Default: `3.0/sqrt(N)`
164168
+ `nodesize` Relative size for the nodes, can be a Vector. Default: `1.0`
165169
+ `nodelabel` Labels for the vertices, a Vector or nothing. Default: `nothing`

src/plot.jl

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,18 @@ Layout algorithm. Currently can be one of [`random_layout`,
2323
`spectral_layout`].
2424
Default: `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`
2739
Max size for the nodes. Default: `3.0/sqrt(N)`
2840
@@ -97,6 +109,10 @@ Default: `π/5 (36 degrees)`
97109
"""
98110
function gplot(g::AbstractGraph{T},
99111
locs_x_in::Vector{R1}, locs_y_in::Vector{R2};
112+
title = "",
113+
title_color = colorant"black",
114+
title_size = 4.0,
115+
font_family = "Helvetica",
100116
nodelabel = nothing,
101117
nodelabelc = colorant"black",
102118
nodelabelsize = 1.0,
@@ -227,12 +243,14 @@ function gplot(g::AbstractGraph{T},
227243
end
228244
end
229245

230-
compose(context(units=UnitBox(-1.2, -1.2, +2.4, +2.4)),
231-
compose(context(), texts, fill(nodelabelc), stroke(nothing), fontsize(nodelabelsize)),
246+
title_offset = isempty(title) ? 0 : 0.1*title_size/4
247+
compose(context(units=UnitBox(-1.2, -1.2 - title_offset, +2.4, +2.4 + title_offset)),
248+
compose(context(), text(0, -1.2 - title_offset/2, title, hcenter, vcenter), fill(title_color), fontsize(title_size), font(font_family)),
249+
compose(context(), texts, fill(nodelabelc), fontsize(nodelabelsize), font(font_family)),
232250
compose(context(), nodes, fill(nodefillc), stroke(nodestrokec), linewidth(nodestrokelw)),
233-
compose(context(), edgetexts, fill(edgelabelc), stroke(nothing), fontsize(edgelabelsize)),
251+
compose(context(), edgetexts, fill(edgelabelc), fontsize(edgelabelsize), font(font_family)),
234252
compose(context(), arrows, stroke(edgestrokec), linewidth(edgelinewidth)),
235-
compose(context(), lines, stroke(edgestrokec), fill(nothing), linewidth(edgelinewidth)))
253+
compose(context(), lines, stroke(edgestrokec), linewidth(edgelinewidth)))
236254
end
237255

238256
function gplot(g; layout::Function=spring_layout, keyargs...)

0 commit comments

Comments
 (0)