Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update plot.jl to account for line style #176

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Copy link
Contributor

@hdavid16 hdavid16 Aug 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The use of this kwarg should be properly documented. In this case, one edge will have 5mm dashes and the next will have 2mm dashes

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, all edges will have the same style, that is alternating 5mm solid line and 2mm blank line.

# vary edge styles
using Compose
gplot(g, EDGELINEWIDTH=0.7, edgedashstyle=[[10px, 5px], [10px, 5px, 3px, 5px], [4px, 4px], []])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The use of this kwarg should be properly documented. When vectors are passed for each edge, the values define the sequence of dashes and spaces. For example, the first edge will have 10px solid dash with 5px spacing in between; the second edge will have the following alternating sequence: 10px solid - 5 px space - 3px solid - 5 px space - etc...

```

## Color the graph
```julia
# nodes membership
Expand Down
11 changes: 9 additions & 2 deletions src/plot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default here is []


`arrowlengthfrac`
Optional. Fraction of line length to use for arrows.
Equal to 0 for undirected graphs. Default: `0.1` for the directed graphs
Expand All @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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...)
Expand Down