Skip to content

Commit 14d62b4

Browse files
committed
Fix JuliaGraphs#172. set background color (backgroundc kwarg):
and minor changes to plots.jl update README
1 parent dfcdf19 commit 14d62b4

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ gplot(h)
183183
+ `arrowangleoffset` Angular width in radians for the arrows. Default: `π/9 (20 degrees)`
184184
+ `linetype` Type of line used for edges ("straight", "curve"). Default: "straight"
185185
+ `outangle` Angular width in radians for the edges (only used if `linetype = "curve`). Default: `π/5 (36 degrees)`
186+
+ `backgroundc` Color for the plot background. Default: `nothing`
186187

187188
# Reporting Bugs
188189

src/plot.jl

+17-13
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ Distances for the node labels from center of nodes. Default: `0.0`
4242
Angle offset for the node labels. Default: `π/4.0`
4343
4444
`NODELABELSIZE`
45-
Largest fontsize for the vertice labels. Default: `4.0`
45+
Largest fontsize for the vertex labels. Default: `4.0`
4646
4747
`nodelabelsize`
48-
Relative fontsize for the vertice labels, can be a Vector. Default: `1.0`
48+
Relative fontsize for the vertex labels, can be a Vector. Default: `1.0`
4949
5050
`nodefillc`
5151
Color to fill the nodes with, can be a Vector. Default: `colorant"turquoise"`
@@ -94,6 +94,9 @@ Type of line used for edges ("straight", "curve"). Default: "straight"
9494
Angular width in radians for the edges (only used if `linetype = "curve`).
9595
Default: `π/5 (36 degrees)`
9696
97+
`backgroundc`
98+
Color for the plot background. Default: `nothing`
99+
97100
"""
98101
function gplot(g::AbstractGraph{T},
99102
locs_x_in::Vector{R1}, locs_y_in::Vector{R2};
@@ -120,7 +123,8 @@ function gplot(g::AbstractGraph{T},
120123
arrowlengthfrac = is_directed(g) ? 0.1 : 0.0,
121124
arrowangleoffset = π / 9,
122125
linetype = "straight",
123-
outangle = π / 5) where {T <:Integer, R1 <: Real, R2 <: Real}
126+
outangle = π / 5,
127+
backgroundc = nothing) where {T <:Integer, R1 <: Real, R2 <: Real}
124128

125129
length(locs_x_in) != length(locs_y_in) && error("Vectors must be same length")
126130
N = nv(g)
@@ -169,19 +173,19 @@ function gplot(g::AbstractGraph{T},
169173
# Create nodes
170174
nodecircle = fill(0.4Compose.w, length(locs_x))
171175
if isa(nodesize, Real)
172-
for i = 1:length(locs_x)
173-
nodecircle[i] *= nodesize
174-
end
175-
else
176-
for i = 1:length(locs_x)
177-
nodecircle[i] *= nodesize[i]
178-
end
179-
end
176+
for i = 1:length(locs_x)
177+
nodecircle[i] *= nodesize
178+
end
179+
else
180+
for i = 1:length(locs_x)
181+
nodecircle[i] *= nodesize[i]
182+
end
183+
end
180184
nodes = circle(locs_x, locs_y, nodecircle)
181185

182186
# Create node labels if provided
183187
texts = nothing
184-
if nodelabel != nothing
188+
if !isnothing(nodelabel)
185189
text_locs_x = deepcopy(locs_x)
186190
text_locs_y = deepcopy(locs_y)
187191
texts = text(text_locs_x .+ nodesize .* (nodelabeldist * cos(nodelabelangleoffset)),
@@ -227,7 +231,7 @@ function gplot(g::AbstractGraph{T},
227231
end
228232
end
229233

230-
compose(context(units=UnitBox(-1.2, -1.2, +2.4, +2.4)),
234+
compose(context(units=UnitBox(-1.2, -1.2, +2.4, +2.4)), rectangle(-1.2, -1.2, +2.4, +2.4), fill(backgroundc),
231235
compose(context(), texts, fill(nodelabelc), stroke(nothing), fontsize(nodelabelsize)),
232236
compose(context(), nodes, fill(nodefillc), stroke(nodestrokec), linewidth(nodestrokelw)),
233237
compose(context(), edgetexts, fill(edgelabelc), stroke(nothing), fontsize(edgelabelsize)),

0 commit comments

Comments
 (0)