From 9130d0df57240863596b40f4a36f6940704cd07f Mon Sep 17 00:00:00 2001 From: TeroFrondelius Date: Mon, 26 Nov 2018 20:04:21 +0200 Subject: [PATCH] First working version of the bitmap nodes --- src/layout.jl | 4 ++-- src/plot.jl | 13 ++++++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/layout.jl b/src/layout.jl index f8786fa..09acc55 100644 --- a/src/layout.jl +++ b/src/layout.jl @@ -55,12 +55,12 @@ julia> g = simple_house_graph() julia> locs_x, locs_y = circular_layout(g) ``` """ -function circular_layout(g) +function circular_layout(g::AbstractGraph{T}) where {T<:Integer} if nv(g) == 1 return [0.0], [0.0] else # Discard the extra angle since it matches 0 radians. - θ = range(0, stop=2pi, length=_nv(G)+1)[1:end-1] + θ = range(0, stop=2pi, length=nv(g)+1)[1:end-1] return cos.(θ), sin.(θ) end end diff --git a/src/plot.jl b/src/plot.jl index f2f5e95..fe5ffb3 100644 --- a/src/plot.jl +++ b/src/plot.jl @@ -107,6 +107,7 @@ function gplot(g::AbstractGraph{T}, nodefillc = colorant"turquoise", nodestrokec = nothing, nodestrokelw = 0.0, + node_bitmap = [], arrowlengthfrac = is_directed(g) ? 0.1 : 0.0, arrowangleoffset = π / 9.0, linetype = "straight", @@ -163,7 +164,15 @@ function gplot(g::AbstractGraph{T}, nodecircle[i] *= nodesize[i] end end - nodes = circle(locs_x, locs_y, nodecircle) + + if isempty(node_bitmap) + nodes = circle(locs_x, locs_y, nodecircle) + else + bsize = 3*nodesize + xc = locs_x .- bsize/2 + yc = locs_y .- bsize/2 + nodes = bitmap(["image/png"], node_bitmap, xc, yc, [bsize], [bsize]) + end # Create node labels if provided texts = nothing @@ -216,9 +225,11 @@ function gplot(g::AbstractGraph{T}, compose(context(units=UnitBox(-1.2, -1.2, +2.4, +2.4)), compose(context(), texts, fill(nodelabelc), stroke(nothing), fontsize(nodelabelsize)), compose(context(), nodes, fill(nodefillc), stroke(nodestrokec), linewidth(nodestrokelw)), + #compose(context(), nodes), compose(context(), edgetexts, fill(edgelabelc), stroke(nothing), fontsize(edgelabelsize)), compose(context(), arrows, stroke(edgestrokec), linewidth(edgelinewidth)), compose(context(), lines, stroke(edgestrokec), fill(nothing), linewidth(edgelinewidth))) + end function gplot(g; layout::Function=spring_layout, keyargs...)