Skip to content

Commit 52f4aae

Browse files
authored
Improve documentation; fix gplothtml; add TagBot (#174)
* Improve Readme and docstring -distinguish args, kwargs -add missing kwargs * fix #166 clarify that Cairo is required to visualize in vscode * Fix #175 to enable plotting to html Checking for System OS was outdated * Document the use of gplothtml in README * Update open_file Now matches gadfly.jl (https://github.com/GiovineItalia/Gadfly.jl/blob/master/src/open_file.jl) * Minor changes: -allow gplothtml to accept same arguments as gplot -allow x/y-locs to be of different type (<: Real) * add TagBot to repo
1 parent 9e0d037 commit 52f4aae

File tree

3 files changed

+100
-50
lines changed

3 files changed

+100
-50
lines changed

.github/workflows/tagbot.yml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: TagBot
2+
on:
3+
issue_comment:
4+
types:
5+
- created
6+
workflow_dispatch:
7+
inputs:
8+
lookback:
9+
default: 3
10+
permissions:
11+
contents: write
12+
jobs:
13+
TagBot:
14+
if: github.event_name == 'workflow_dispatch' || github.actor == 'JuliaTagBot'
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: JuliaRegistries/TagBot@v1
18+
with:
19+
token: ${{ secrets.GITHUB_TOKEN }}
20+
ssh: ${{ secrets.DOCUMENTER_KEY }}

README.md

+36-16
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Other layout algorithms are wrapped from [NetworkX](https://github.com/networkx/
1414
# Getting Started
1515

1616
From the Julia REPL the latest version can be installed with
17-
```{execute="false"}
17+
```julia
1818
Pkg.add("GraphPlot")
1919
```
2020
GraphPlot is then loaded with
@@ -132,9 +132,14 @@ gplot(g, locs_x, locs_y, nodelabel=nodelabel)
132132
gplot(g, linetype="curve")
133133
```
134134

135+
## Show plot
136+
137+
When using an IDE such as VSCode, `Cairo.jl` is required to visualize the plot inside the IDE.
138+
When using the REPL, `gplothtml` will allow displaying the plot on a browser.
139+
135140
## Save to figure
136-
```{execute="false"}
137-
using Cairo, Compose
141+
```julia
142+
using Compose
138143
# save to pdf
139144
draw(PDF("karate.pdf", 16cm, 16cm), gplot(g))
140145
# save to png
@@ -150,19 +155,34 @@ gplot(h)
150155
```
151156

152157
# Arguments
153-
+ `G` graph to plot
154-
+ `layout` Optional. layout algorithm. Currently can choose from
155-
[random_layout, circular_layout, spring_layout, stressmajorize_layout,
156-
shell_layout, spectral_layout].
157-
Default: `spring_layout`
158-
+ `nodelabel` Optional. Labels for the vertices. Default: `nothing`
159-
+ `nodefillc` Optional. Color to fill the nodes with.
160-
Default: `colorant"turquoise"`
161-
+ `nodestrokec` Color for the node stroke.
162-
Default: `nothing`
163-
+ `arrowlengthfrac` Fraction of line length to use for arrows.
164-
Set to 0 for no arrows. Default: 0 for undirected graph and 0.1 for directed graph
165-
+ `arrowangleoffset` angular width in radians for the arrows. Default: `π/9` (20 degrees)
158+
+ `G` Graph to draw
159+
+ `locs_x, locs_y` Locations of the nodes (will be normalized and centered). If not specified, will be obtained from `layout` kwarg.
160+
161+
# Keyword Arguments
162+
+ `layout` Layout algorithm: `random_layout`, `circular_layout`, `spring_layout`, `shell_layout`, `stressmajorize_layout`, `spectral_layout`. Default: `spring_layout`
163+
+ `NODESIZE` Max size for the nodes. Default: `3.0/sqrt(N)`
164+
+ `nodesize` Relative size for the nodes, can be a Vector. Default: `1.0`
165+
+ `nodelabel` Labels for the vertices, a Vector or nothing. Default: `nothing`
166+
+ `nodelabelc` Color for the node labels, can be a Vector. Default: `colorant"black"`
167+
+ `nodelabeldist` Distances for the node labels from center of nodes. Default: `0.0`
168+
+ `nodelabelangleoffset` Angle offset for the node labels. Default: `π/4.0`
169+
+ `NODELABELSIZE` Largest fontsize for the vertice labels. Default: `4.0`
170+
+ `nodelabelsize` Relative fontsize for the vertice labels, can be a Vector. Default: `1.0`
171+
+ `nodefillc` Color to fill the nodes with, can be a Vector. Default: `colorant"turquoise"`
172+
+ `nodestrokec` Color for the nodes stroke, can be a Vector. Default: `nothing`
173+
+ `nodestrokelw` Line width for the nodes stroke, can be a Vector. Default: `0.0`
174+
+ `edgelabel` Labels for the edges, a Vector or nothing. Default: `[]`
175+
+ `edgelabelc` Color for the edge labels, can be a Vector. Default: `colorant"black"`
176+
+ `edgelabeldistx, edgelabeldisty` Distance for the edge label from center of edge. Default: `0.0`
177+
+ `EDGELABELSIZE` Largest fontsize for the edge labels. Default: `4.0`
178+
+ `edgelabelsize` Relative fontsize for the edge labels, can be a Vector. Default: `1.0`
179+
+ `EDGELINEWIDTH` Max line width for the edges. Default: `0.25/sqrt(N)`
180+
+ `edgelinewidth` Relative line width for the edges, can be a Vector. Default: `1.0`
181+
+ `edgestrokec` Color for the edge strokes, can be a Vector. Default: `colorant"lightgray"`
182+
+ `arrowlengthfrac` Fraction of line length to use for arrows. Equal to 0 for undirected graphs. Default: `0.1` for the directed graphs
183+
+ `arrowangleoffset` Angular width in radians for the arrows. Default: `π/9 (20 degrees)`
184+
+ `linetype` Type of line used for edges ("straight", "curve"). Default: "straight"
185+
+ `outangle` Angular width in radians for the edges (only used if `linetype = "curve`). Default: `π/5 (36 degrees)`
166186

167187
# Reporting Bugs
168188

src/plot.jl

+44-34
Original file line numberDiff line numberDiff line change
@@ -10,83 +10,93 @@ a Compose tree of the graph layout
1010
`G`
1111
Graph to draw
1212
13+
`locs_x, locs_y`
14+
Locations of the nodes. Can be any units you want,
15+
but will be normalized and centered anyway. If not provided, will
16+
be obtained from `layout` kwarg.
17+
18+
**Keyword Arguments**
19+
1320
`layout`
14-
Optional. Layout algorithm. Currently can be one of [`random_layout`,
21+
Layout algorithm. Currently can be one of [`random_layout`,
1522
`circular_layout`, `spring_layout`, `shell_layout`, `stressmajorize_layout`,
1623
`spectral_layout`].
1724
Default: `spring_layout`
1825
19-
`locs_x, locs_y`
20-
Locations of the nodes. Can be any units you want,
21-
but will be normalized and centered anyway
22-
2326
`NODESIZE`
24-
Optional. Max size for the nodes. Default: `3.0/sqrt(N)`
27+
Max size for the nodes. Default: `3.0/sqrt(N)`
2528
2629
`nodesize`
27-
Optional. Relative size for the nodes, can be a Vector. Default: `1.0`
30+
Relative size for the nodes, can be a Vector. Default: `1.0`
2831
2932
`nodelabel`
30-
Optional. Labels for the vertices, a Vector or nothing. Default: `nothing`
33+
Labels for the vertices, a Vector or nothing. Default: `nothing`
3134
3235
`nodelabelc`
33-
Optional. Color for the node labels, can be a Vector. Default: `colorant"black"`
36+
Color for the node labels, can be a Vector. Default: `colorant"black"`
3437
3538
`nodelabeldist`
36-
Optional. Distances for the node labels from center of nodes. Default: `0.0`
39+
Distances for the node labels from center of nodes. Default: `0.0`
3740
3841
`nodelabelangleoffset`
39-
Optional. Angle offset for the node labels. Default: `π/4.0`
42+
Angle offset for the node labels. Default: `π/4.0`
4043
4144
`NODELABELSIZE`
42-
Optional. Largest fontsize for the vertice labels. Default: `4.0`
45+
Largest fontsize for the vertice labels. Default: `4.0`
4346
4447
`nodelabelsize`
45-
Optional. Relative fontsize for the vertice labels, can be a Vector. Default: `1.0`
48+
Relative fontsize for the vertice labels, can be a Vector. Default: `1.0`
4649
4750
`nodefillc`
48-
Optional. Color to fill the nodes with, can be a Vector. Default: `colorant"turquoise"`
51+
Color to fill the nodes with, can be a Vector. Default: `colorant"turquoise"`
4952
5053
`nodestrokec`
51-
Optional. Color for the nodes stroke, can be a Vector. Default: `nothing`
54+
Color for the nodes stroke, can be a Vector. Default: `nothing`
5255
5356
`nodestrokelw`
54-
Optional. Line width for the nodes stroke, can be a Vector. Default: `0.0`
57+
Line width for the nodes stroke, can be a Vector. Default: `0.0`
5558
5659
`edgelabel`
57-
Optional. Labels for the edges, a Vector or nothing. Default: `[]`
60+
Labels for the edges, a Vector or nothing. Default: `[]`
5861
5962
`edgelabelc`
60-
Optional. Color for the edge labels, can be a Vector. Default: `colorant"black"`
63+
Color for the edge labels, can be a Vector. Default: `colorant"black"`
6164
6265
`edgelabeldistx, edgelabeldisty`
63-
Optional. Distance for the edge label from center of edge. Default: `0.0`
66+
Distance for the edge label from center of edge. Default: `0.0`
6467
6568
`EDGELABELSIZE`
66-
Optional. Largest fontsize for the edge labels. Default: `4.0`
69+
Largest fontsize for the edge labels. Default: `4.0`
6770
6871
`edgelabelsize`
69-
Optional. Relative fontsize for the edge labels, can be a Vector. Default: `1.0`
72+
Relative fontsize for the edge labels, can be a Vector. Default: `1.0`
7073
7174
`EDGELINEWIDTH`
72-
Optional. Max line width for the edges. Default: `0.25/sqrt(N)`
75+
Max line width for the edges. Default: `0.25/sqrt(N)`
7376
7477
`edgelinewidth`
75-
Optional. Relative line width for the edges, can be a Vector. Default: `1.0`
78+
Relative line width for the edges, can be a Vector. Default: `1.0`
7679
7780
`edgestrokec`
78-
Optional. Color for the edge strokes, can be a Vector. Default: `colorant"lightgray"`
81+
Color for the edge strokes, can be a Vector. Default: `colorant"lightgray"`
7982
8083
`arrowlengthfrac`
81-
Optional. Fraction of line length to use for arrows.
84+
Fraction of line length to use for arrows.
8285
Equal to 0 for undirected graphs. Default: `0.1` for the directed graphs
8386
8487
`arrowangleoffset`
85-
Optional. Angular width in radians for the arrows. Default: `π/9 (20 degrees)`
88+
Angular width in radians for the arrows. Default: `π/9 (20 degrees)`
89+
90+
`linetype`
91+
Type of line used for edges ("straight", "curve"). Default: "straight"
92+
93+
`outangle`
94+
Angular width in radians for the edges (only used if `linetype = "curve`).
95+
Default: `π/5 (36 degrees)`
8696
8797
"""
8898
function gplot(g::AbstractGraph{T},
89-
locs_x_in::Vector{R}, locs_y_in::Vector{R};
99+
locs_x_in::Vector{R1}, locs_y_in::Vector{R2};
90100
nodelabel = nothing,
91101
nodelabelc = colorant"black",
92102
nodelabelsize = 1.0,
@@ -108,9 +118,9 @@ function gplot(g::AbstractGraph{T},
108118
nodestrokec = nothing,
109119
nodestrokelw = 0.0,
110120
arrowlengthfrac = is_directed(g) ? 0.1 : 0.0,
111-
arrowangleoffset = π / 9.0,
121+
arrowangleoffset = π / 9,
112122
linetype = "straight",
113-
outangle = pi/5) where {T <:Integer, R <: Real}
123+
outangle = π / 5) where {T <:Integer, R1 <: Real, R2 <: Real}
114124

115125
length(locs_x_in) != length(locs_y_in) && error("Vectors must be same length")
116126
N = nv(g)
@@ -231,25 +241,25 @@ end
231241

232242
# take from [Gadfly.jl](https://github.com/dcjones/Gadfly.jl)
233243
function open_file(filename)
234-
if Sys.KERNEL == :Darwin
244+
if Sys.isapple() #apple
235245
run(`open $(filename)`)
236-
elseif Sys.KERNEL == :Linux || Sys.KERNEL == :FreeBSD
246+
elseif Sys.islinux() || Sys.isbsd() #linux
237247
run(`xdg-open $(filename)`)
238-
elseif Sys.KERNEL == :Windows
248+
elseif Sys.iswindows() #windows
239249
run(`$(ENV["COMSPEC"]) /c start $(filename)`)
240250
else
241251
@warn("Showing plots is not supported on OS $(string(Sys.KERNEL))")
242252
end
243253
end
244254

245255
# taken from [Gadfly.jl](https://github.com/dcjones/Gadfly.jl)
246-
function gplothtml(g; layout::Function=spring_layout, keyargs...)
256+
function gplothtml(args...; keyargs...)
247257
filename = string(tempname(), ".html")
248258
output = open(filename, "w")
249259

250260
plot_output = IOBuffer()
251261
draw(SVGJS(plot_output, Compose.default_graphic_width,
252-
Compose.default_graphic_width, false), gplot(g, layout(g)...; keyargs...))
262+
Compose.default_graphic_width, false), gplot(args...; keyargs...))
253263
plotsvg = String(take!(plot_output))
254264

255265
write(output,

0 commit comments

Comments
 (0)