From 3368e8917e9308517511cb2778317a1edfd5032c Mon Sep 17 00:00:00 2001 From: hdavid16 Date: Thu, 21 Jul 2022 17:20:53 -0500 Subject: [PATCH 1/7] Improve Readme and docstring -distinguish args, kwargs -add missing kwargs --- README.md | 45 ++++++++++++++++++++++++------------ src/plot.jl | 66 ++++++++++++++++++++++++++++++----------------------- 2 files changed, 68 insertions(+), 43 deletions(-) diff --git a/README.md b/README.md index 63d836a..f5438ca 100644 --- a/README.md +++ b/README.md @@ -133,8 +133,8 @@ gplot(g, linetype="curve") ``` ## Save to figure -```{execute="false"} -using Cairo, Compose +```julia +using Compose # save to pdf draw(PDF("karate.pdf", 16cm, 16cm), gplot(g)) # save to png @@ -150,19 +150,34 @@ gplot(h) ``` # Arguments -+ `G` graph to plot -+ `layout` Optional. layout algorithm. Currently can choose from -[random_layout, circular_layout, spring_layout, stressmajorize_layout, -shell_layout, spectral_layout]. -Default: `spring_layout` -+ `nodelabel` Optional. Labels for the vertices. Default: `nothing` -+ `nodefillc` Optional. Color to fill the nodes with. -Default: `colorant"turquoise"` -+ `nodestrokec` Color for the node stroke. -Default: `nothing` -+ `arrowlengthfrac` Fraction of line length to use for arrows. -Set to 0 for no arrows. Default: 0 for undirected graph and 0.1 for directed graph -+ `arrowangleoffset` angular width in radians for the arrows. Default: `π/9` (20 degrees) ++ `G` Graph to draw ++ `locs_x, locs_y` Locations of the nodes (will be normalized and centered). If not specified, will be obtained from `layout` kwarg. + +# Keyword Arguments ++ `layout` Layout algorithm: `random_layout`, `circular_layout`, `spring_layout`, `shell_layout`, `stressmajorize_layout`, `spectral_layout`. Default: `spring_layout` ++ `NODESIZE` Max size for the nodes. Default: `3.0/sqrt(N)` ++ `nodesize` Relative size for the nodes, can be a Vector. Default: `1.0` ++ `nodelabel` Labels for the vertices, a Vector or nothing. Default: `nothing` ++ `nodelabelc` Color for the node labels, can be a Vector. Default: `colorant"black"` ++ `nodelabeldist` Distances for the node labels from center of nodes. Default: `0.0` ++ `nodelabelangleoffset` Angle offset for the node labels. Default: `π/4.0` ++ `NODELABELSIZE` Largest fontsize for the vertice labels. Default: `4.0` ++ `nodelabelsize` Relative fontsize for the vertice labels, can be a Vector. Default: `1.0` ++ `nodefillc` Color to fill the nodes with, can be a Vector. Default: `colorant"turquoise"` ++ `nodestrokec` Color for the nodes stroke, can be a Vector. Default: `nothing` ++ `nodestrokelw` Line width for the nodes stroke, can be a Vector. Default: `0.0` ++ `edgelabel` Labels for the edges, a Vector or nothing. Default: `[]` ++ `edgelabelc` Color for the edge labels, can be a Vector. Default: `colorant"black"` ++ `edgelabeldistx, edgelabeldisty` Distance for the edge label from center of edge. Default: `0.0` ++ `EDGELABELSIZE` Largest fontsize for the edge labels. Default: `4.0` ++ `edgelabelsize` Relative fontsize for the edge labels, can be a Vector. Default: `1.0` ++ `EDGELINEWIDTH` Max line width for the edges. Default: `0.25/sqrt(N)` ++ `edgelinewidth` Relative line width for the edges, can be a Vector. Default: `1.0` ++ `edgestrokec` Color for the edge strokes, can be a Vector. Default: `colorant"lightgray"` ++ `arrowlengthfrac` Fraction of line length to use for arrows. Equal to 0 for undirected graphs. Default: `0.1` for the directed graphs ++ `arrowangleoffset` Angular width in radians for the arrows. Default: `π/9 (20 degrees)` ++ `linetype` Type of line used for edges ("straight", "curve"). Default: "straight" ++ `outangle` Angular width in radians for the edges (only used if `linetype = "curve`). Default: `π/5 (36 degrees)` # Reporting Bugs diff --git a/src/plot.jl b/src/plot.jl index b38554c..8c4c033 100644 --- a/src/plot.jl +++ b/src/plot.jl @@ -10,79 +10,89 @@ a Compose tree of the graph layout `G` Graph to draw +`locs_x, locs_y` +Locations of the nodes. Can be any units you want, +but will be normalized and centered anyway. If not provided, will +be obtained from `layout` kwarg. + +**Keyword Arguments** + `layout` -Optional. Layout algorithm. Currently can be one of [`random_layout`, +Layout algorithm. Currently can be one of [`random_layout`, `circular_layout`, `spring_layout`, `shell_layout`, `stressmajorize_layout`, `spectral_layout`]. Default: `spring_layout` -`locs_x, locs_y` -Locations of the nodes. Can be any units you want, -but will be normalized and centered anyway - `NODESIZE` -Optional. Max size for the nodes. Default: `3.0/sqrt(N)` +Max size for the nodes. Default: `3.0/sqrt(N)` `nodesize` -Optional. Relative size for the nodes, can be a Vector. Default: `1.0` +Relative size for the nodes, can be a Vector. Default: `1.0` `nodelabel` -Optional. Labels for the vertices, a Vector or nothing. Default: `nothing` +Labels for the vertices, a Vector or nothing. Default: `nothing` `nodelabelc` -Optional. Color for the node labels, can be a Vector. Default: `colorant"black"` +Color for the node labels, can be a Vector. Default: `colorant"black"` `nodelabeldist` -Optional. Distances for the node labels from center of nodes. Default: `0.0` +Distances for the node labels from center of nodes. Default: `0.0` `nodelabelangleoffset` -Optional. Angle offset for the node labels. Default: `π/4.0` +Angle offset for the node labels. Default: `π/4.0` `NODELABELSIZE` -Optional. Largest fontsize for the vertice labels. Default: `4.0` +Largest fontsize for the vertice labels. Default: `4.0` `nodelabelsize` -Optional. Relative fontsize for the vertice labels, can be a Vector. Default: `1.0` +Relative fontsize for the vertice labels, can be a Vector. Default: `1.0` `nodefillc` -Optional. Color to fill the nodes with, can be a Vector. Default: `colorant"turquoise"` +Color to fill the nodes with, can be a Vector. Default: `colorant"turquoise"` `nodestrokec` -Optional. Color for the nodes stroke, can be a Vector. Default: `nothing` +Color for the nodes stroke, can be a Vector. Default: `nothing` `nodestrokelw` -Optional. Line width for the nodes stroke, can be a Vector. Default: `0.0` +Line width for the nodes stroke, can be a Vector. Default: `0.0` `edgelabel` -Optional. Labels for the edges, a Vector or nothing. Default: `[]` +Labels for the edges, a Vector or nothing. Default: `[]` `edgelabelc` -Optional. Color for the edge labels, can be a Vector. Default: `colorant"black"` +Color for the edge labels, can be a Vector. Default: `colorant"black"` `edgelabeldistx, edgelabeldisty` -Optional. Distance for the edge label from center of edge. Default: `0.0` +Distance for the edge label from center of edge. Default: `0.0` `EDGELABELSIZE` -Optional. Largest fontsize for the edge labels. Default: `4.0` +Largest fontsize for the edge labels. Default: `4.0` `edgelabelsize` -Optional. Relative fontsize for the edge labels, can be a Vector. Default: `1.0` +Relative fontsize for the edge labels, can be a Vector. Default: `1.0` `EDGELINEWIDTH` -Optional. Max line width for the edges. Default: `0.25/sqrt(N)` +Max line width for the edges. Default: `0.25/sqrt(N)` `edgelinewidth` -Optional. Relative line width for the edges, can be a Vector. Default: `1.0` +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"` +Color for the edge strokes, can be a Vector. Default: `colorant"lightgray"` `arrowlengthfrac` -Optional. Fraction of line length to use for arrows. +Fraction of line length to use for arrows. Equal to 0 for undirected graphs. Default: `0.1` for the directed graphs `arrowangleoffset` -Optional. Angular width in radians for the arrows. Default: `π/9 (20 degrees)` +Angular width in radians for the arrows. Default: `π/9 (20 degrees)` + +`linetype` +Type of line used for edges ("straight", "curve"). Default: "straight" + +`outangle` +Angular width in radians for the edges (only used if `linetype = "curve`). +Default: `π/5 (36 degrees)` """ function gplot(g::AbstractGraph{T}, @@ -108,9 +118,9 @@ function gplot(g::AbstractGraph{T}, nodestrokec = nothing, nodestrokelw = 0.0, arrowlengthfrac = is_directed(g) ? 0.1 : 0.0, - arrowangleoffset = π / 9.0, + arrowangleoffset = π / 9, linetype = "straight", - outangle = pi/5) where {T <:Integer, R <: Real} + outangle = π / 5) where {T <:Integer, R <: Real} length(locs_x_in) != length(locs_y_in) && error("Vectors must be same length") N = nv(g) From febb53bf5f587a7ec12a7bd4663564f27d21f4e4 Mon Sep 17 00:00:00 2001 From: hdavid16 Date: Thu, 21 Jul 2022 17:44:03 -0500 Subject: [PATCH 2/7] fix #166 clarify that Cairo is required to visualize in vscode --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f5438ca..e385cee 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ Other layout algorithms are wrapped from [NetworkX](https://github.com/networkx/ # Getting Started From the Julia REPL the latest version can be installed with -```{execute="false"} +```julia Pkg.add("GraphPlot") ``` GraphPlot is then loaded with @@ -132,6 +132,10 @@ gplot(g, locs_x, locs_y, nodelabel=nodelabel) gplot(g, linetype="curve") ``` +## Show plot + +When using an IDE such as VSCode, `Cairo.jl` is required to visualize the plot inside the IDE. + ## Save to figure ```julia using Compose From 9bffdd99d381ee4cec8c2b9702a9ed029a856d87 Mon Sep 17 00:00:00 2001 From: Hector Perez Date: Thu, 21 Jul 2022 18:02:52 -0500 Subject: [PATCH 3/7] Fix #175 to enable plotting to html Checking for System OS was outdated --- src/plot.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/plot.jl b/src/plot.jl index 8c4c033..362ac90 100644 --- a/src/plot.jl +++ b/src/plot.jl @@ -241,11 +241,11 @@ end # take from [Gadfly.jl](https://github.com/dcjones/Gadfly.jl) function open_file(filename) - if Sys.KERNEL == :Darwin + if Sys.isapple(Sys.KERNEL) #apple run(`open $(filename)`) - elseif Sys.KERNEL == :Linux || Sys.KERNEL == :FreeBSD + elseif Sys.islinux(Sys.KERNEL) || Sys.isbsd(Sys.KERNEL) #linux run(`xdg-open $(filename)`) - elseif Sys.KERNEL == :Windows + elseif Sys.iswindows(Sys.KERNEL) #windows run(`$(ENV["COMSPEC"]) /c start $(filename)`) else @warn("Showing plots is not supported on OS $(string(Sys.KERNEL))") From 080a1a474edff73a4e9a034c8f90290045b0a20a Mon Sep 17 00:00:00 2001 From: Hector Perez Date: Thu, 21 Jul 2022 18:03:59 -0500 Subject: [PATCH 4/7] Document the use of gplothtml in README --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index e385cee..e5dd530 100644 --- a/README.md +++ b/README.md @@ -135,6 +135,7 @@ gplot(g, linetype="curve") ## Show plot When using an IDE such as VSCode, `Cairo.jl` is required to visualize the plot inside the IDE. +When using the REPL, `gplothtml` will allow displaying the plot on a browser. ## Save to figure ```julia From 3d32d077c5d3bf73a497dddbca9700b4eca8c014 Mon Sep 17 00:00:00 2001 From: Hector Perez Date: Thu, 21 Jul 2022 18:08:05 -0500 Subject: [PATCH 5/7] Update open_file Now matches gadfly.jl (https://github.com/GiovineItalia/Gadfly.jl/blob/master/src/open_file.jl) --- src/plot.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/plot.jl b/src/plot.jl index 362ac90..505f9b6 100644 --- a/src/plot.jl +++ b/src/plot.jl @@ -241,11 +241,11 @@ end # take from [Gadfly.jl](https://github.com/dcjones/Gadfly.jl) function open_file(filename) - if Sys.isapple(Sys.KERNEL) #apple + if Sys.isapple() #apple run(`open $(filename)`) - elseif Sys.islinux(Sys.KERNEL) || Sys.isbsd(Sys.KERNEL) #linux + elseif Sys.islinux() || Sys.isbsd() #linux run(`xdg-open $(filename)`) - elseif Sys.iswindows(Sys.KERNEL) #windows + elseif Sys.iswindows() #windows run(`$(ENV["COMSPEC"]) /c start $(filename)`) else @warn("Showing plots is not supported on OS $(string(Sys.KERNEL))") From 2c64095c0aee95cbb220224ab8022f1be0209e2f Mon Sep 17 00:00:00 2001 From: hdavid16 Date: Mon, 25 Jul 2022 16:22:21 -0500 Subject: [PATCH 6/7] Minor changes: -allow gplothtml to accept same arguments as gplot -allow x/y-locs to be of different type (<: Real) --- src/plot.jl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/plot.jl b/src/plot.jl index 505f9b6..af438b7 100644 --- a/src/plot.jl +++ b/src/plot.jl @@ -96,7 +96,7 @@ Default: `π/5 (36 degrees)` """ function gplot(g::AbstractGraph{T}, - locs_x_in::Vector{R}, locs_y_in::Vector{R}; + locs_x_in::Vector{R1}, locs_y_in::Vector{R2}; nodelabel = nothing, nodelabelc = colorant"black", nodelabelsize = 1.0, @@ -120,7 +120,7 @@ function gplot(g::AbstractGraph{T}, arrowlengthfrac = is_directed(g) ? 0.1 : 0.0, arrowangleoffset = π / 9, linetype = "straight", - outangle = π / 5) where {T <:Integer, R <: Real} + outangle = π / 5) where {T <:Integer, R1 <: Real, R2 <: Real} length(locs_x_in) != length(locs_y_in) && error("Vectors must be same length") N = nv(g) @@ -253,13 +253,13 @@ function open_file(filename) end # taken from [Gadfly.jl](https://github.com/dcjones/Gadfly.jl) -function gplothtml(g; layout::Function=spring_layout, keyargs...) +function gplothtml(args...; keyargs...) filename = string(tempname(), ".html") output = open(filename, "w") plot_output = IOBuffer() draw(SVGJS(plot_output, Compose.default_graphic_width, - Compose.default_graphic_width, false), gplot(g, layout(g)...; keyargs...)) + Compose.default_graphic_width, false), gplot(args...; keyargs...)) plotsvg = String(take!(plot_output)) write(output, From 222fb26a44cabc046779cf7d74bd5680ba7b2c65 Mon Sep 17 00:00:00 2001 From: hdavid16 Date: Mon, 25 Jul 2022 23:26:46 -0500 Subject: [PATCH 7/7] add TagBot to repo --- .github/workflows/tagbot.yml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 .github/workflows/tagbot.yml diff --git a/.github/workflows/tagbot.yml b/.github/workflows/tagbot.yml new file mode 100644 index 0000000..32a9dd8 --- /dev/null +++ b/.github/workflows/tagbot.yml @@ -0,0 +1,20 @@ +name: TagBot +on: + issue_comment: + types: + - created + workflow_dispatch: + inputs: + lookback: + default: 3 +permissions: + contents: write +jobs: + TagBot: + if: github.event_name == 'workflow_dispatch' || github.actor == 'JuliaTagBot' + runs-on: ubuntu-latest + steps: + - uses: JuliaRegistries/TagBot@v1 + with: + token: ${{ secrets.GITHUB_TOKEN }} + ssh: ${{ secrets.DOCUMENTER_KEY }} \ No newline at end of file