diff --git a/README.md b/README.md index 63d836a..f83da80 100644 --- a/README.md +++ b/README.md @@ -86,6 +86,15 @@ edgelabel = 1:Graphs.ne(g) gplot(g, edgelabel=edgelabel, nodelabel=nodelabel, edgelabeldistx=0.5, edgelabeldisty=0.5) ``` +## Add dash style to edges +```julia +using Measures +gplot(g, edgedashstyle=[5mm, 2mm]) +# vary edge styles +using Compose +gplot(g, EDGELINEWIDTH=0.7, edgedashstyle=[[10px, 5px], [10px, 5px, 3px, 5px], [4px, 4px], []]) +``` + ## Color the graph ```julia # nodes membership diff --git a/src/plot.jl b/src/plot.jl index b38554c..e2ae02e 100644 --- a/src/plot.jl +++ b/src/plot.jl @@ -77,6 +77,9 @@ Optional. Relative line width for the edges, can be a Vector. Default: `1.0` `edgestrokec` Optional. Color for the edge strokes, can be a Vector. Default: `colorant"lightgray"` +`edgedashstyle` +Optional. Dash style for the edge, can be a Vector. Default: no dashed line. + `arrowlengthfrac` Optional. Fraction of line length to use for arrows. Equal to 0 for undirected graphs. Default: `0.1` for the directed graphs @@ -96,6 +99,7 @@ function gplot(g::AbstractGraph{T}, edgelabel = [], edgelabelc = colorant"black", edgelabelsize = 1.0, + edgedashstyle = [], EDGELABELSIZE = 4.0, edgestrokec = colorant"lightgray", edgelinewidth = 1.0, @@ -138,6 +142,9 @@ function gplot(g::AbstractGraph{T}, map!(z -> scaler(z, min_x, max_x), locs_x, locs_x) map!(z -> scaler(z, min_y, max_y), locs_y, locs_y) + # Calculate the size of the box + units = UnitBox(-1.2, -1.2, 2.4, 2.4) + # Determine sizes #NODESIZE = 0.25/sqrt(N) #LINEWIDTH = 3.0/sqrt(N) @@ -217,12 +224,12 @@ function gplot(g::AbstractGraph{T}, end end - compose(context(units=UnitBox(-1.2, -1.2, +2.4, +2.4)), + compose(context(units=units), compose(context(), texts, fill(nodelabelc), stroke(nothing), fontsize(nodelabelsize)), compose(context(), nodes, fill(nodefillc), stroke(nodestrokec), linewidth(nodestrokelw)), 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))) + compose(context(), lines, stroke(edgestrokec), strokedash(edgedashstyle), fill(nothing), linewidth(edgelinewidth))) end function gplot(g; layout::Function=spring_layout, keyargs...)