Skip to content

Commit ee69de0

Browse files
committed
fix bug
when node size uses Width units and padding is used, the arrow ends get thrown off (instead, replace Compose.w with 2.4 (unit box width) to make sure that the right size is used regardless of the padding)
1 parent efb5e05 commit ee69de0

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

src/plot.jl

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ function gplot(g::AbstractGraph{T},
202202
end
203203

204204
# Create nodes
205-
nodecircle = fill(0.4Compose.w, length(locs_x))
205+
nodecircle = fill(0.4*2.4, length(locs_x)) #40% of the width of the unit box
206206
if isa(nodesize, Real)
207207
for i = 1:length(locs_x)
208208
nodecircle[i] *= nodesize
@@ -257,28 +257,31 @@ function gplot(g::AbstractGraph{T},
257257
end
258258
Compose.set_default_graphic_size(plot_size...)
259259

260-
# Fix title offset
261-
title_offset = isempty(title) ? 0 : 0.1*title_size/4
262-
263-
# Plot area size
264-
plot_area = (-1.2, -1.2 - title_offset, +2.4, +2.4 + title_offset)
260+
# Plot title
261+
title_offset = isempty(title) ? 0 : 0.1*title_size/4 #Fix title offset
262+
title = text(0, -1.2 - title_offset/2, title, hcenter, vcenter)
265263

266264
# Plot padding
267265
if !isnothing(pad)
268266
leftpad, rightpad, toppad, bottompad = pad, pad, pad, pad
269267
end
268+
269+
# Plot area size
270+
plot_area = (-1.2, -1.2 - title_offset, +2.4, +2.4 + title_offset)
270271

271272
# Build figure
272-
compose(context(units=UnitBox(plot_area...; leftpad, rightpad, toppad, bottompad)),
273-
compose(context(), text(0, -1.2 - title_offset/2, title, hcenter, vcenter), fill(title_color), fontsize(title_size), font(font_family)),
274-
compose(context(), texts, fill(nodelabelc), fontsize(nodelabelsize), font(font_family)),
275-
compose(context(), nodes, fill(nodefillc), stroke(nodestrokec), linewidth(nodestrokelw)),
276-
compose(context(), edgetexts, fill(edgelabelc), fontsize(edgelabelsize)),
277-
compose(context(), larrows, stroke(edgestrokec), linewidth(edgelinewidth)),
278-
compose(context(), carrows, stroke(edgestrokec), linewidth(edgelinewidth)),
279-
compose(context(), lines, stroke(edgestrokec), linewidth(edgelinewidth)),
280-
compose(context(), curves, stroke(edgestrokec), linewidth(edgelinewidth)),
281-
compose(context(units=UnitBox(plot_area...)), rectangle(plot_area...), fill(background_color)))
273+
compose(
274+
context(units=UnitBox(plot_area...; leftpad, rightpad, toppad, bottompad)),
275+
compose(context(), title, fill(title_color), fontsize(title_size), font(font_family)),
276+
compose(context(), texts, fill(nodelabelc), fontsize(nodelabelsize), font(font_family)),
277+
compose(context(), nodes, fill(nodefillc), stroke(nodestrokec), linewidth(nodestrokelw)),
278+
compose(context(), edgetexts, fill(edgelabelc), fontsize(edgelabelsize)),
279+
compose(context(), larrows, stroke(edgestrokec), linewidth(edgelinewidth)),
280+
compose(context(), carrows, stroke(edgestrokec), linewidth(edgelinewidth)),
281+
compose(context(), lines, stroke(edgestrokec), linewidth(edgelinewidth)),
282+
compose(context(), curves, stroke(edgestrokec), linewidth(edgelinewidth)),
283+
compose(context(units=UnitBox(plot_area...)), rectangle(plot_area...), fill(background_color))
284+
)
282285
end
283286

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

0 commit comments

Comments
 (0)