From 608552b1959b45488cf8b98acd65a6d14f99fe1f Mon Sep 17 00:00:00 2001 From: davide-f <67809479+davide-f@users.noreply.github.com> Date: Mon, 5 Oct 2020 17:56:35 +0200 Subject: [PATCH 01/13] Update plot.jl Proposal to: 1) add a custom line dash style of the edges 2) specify whether to resize the box as a unit square or preserve the proportions (x and y axes) among the different stations --- src/plot.jl | 43 +++++++++++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/src/plot.jl b/src/plot.jl index b38554c..226a651 100644 --- a/src/plot.jl +++ b/src/plot.jl @@ -20,6 +20,9 @@ Default: `spring_layout` Locations of the nodes. Can be any units you want, but will be normalized and centered anyway +`preserveratio` +True if the plot shall use the same scaling factor for x and y axes. + `NODESIZE` Optional. Max size for the nodes. Default: `3.0/sqrt(N)` @@ -77,6 +80,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. 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 @@ -87,6 +93,7 @@ Optional. Angular width in radians for the arrows. Default: `π/9 (20 degrees)` """ function gplot(g::AbstractGraph{T}, locs_x_in::Vector{R}, locs_y_in::Vector{R}; + preserveratio = false, nodelabel = nothing, nodelabelc = colorant"black", nodelabelsize = 1.0, @@ -96,6 +103,7 @@ function gplot(g::AbstractGraph{T}, edgelabel = [], edgelabelc = colorant"black", edgelabelsize = 1.0, + edgedashstyle = [], EDGELABELSIZE = 4.0, edgestrokec = colorant"lightgray", edgelinewidth = 1.0, @@ -125,18 +133,33 @@ function gplot(g::AbstractGraph{T}, locs_x = Float64.(locs_x_in) locs_y = Float64.(locs_y_in) - # Scale to unit square + # Scale data min_x, max_x = extrema(locs_x) min_y, max_y = extrema(locs_y) - function scaler(z, a, b) - if (a - b) == 0.0 - return 0.5 - else - return 2.0 * ((z - a) / (b - a)) - 1.0 + if preserveratio + # Uniform scale + function scaler(z, min, ratio) + 2 * (z - min) * ratio - 1 + end + min_ratio = min(1/(max_x - min_x), 1/(max_y - min_y)) + map!(z -> scaler(z, min_x, min_ratio), locs_x, locs_x) + map!(z -> scaler(z, min_y, min_ratio), locs_y, locs_y) + else + # Scale to unit square + function scalerunitsquare(z, a, b) + 2.0 * ((z - a) / (b - a)) - 1.0 end + map!(z -> scalerunitsquare(z, min_x, max_x), locs_x, locs_x) + map!(z -> scalerunitsquare(z, min_y, max_y), locs_y, locs_y) end - 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 + min_x, max_x = extrema(locs_x) + min_y, max_y = extrema(locs_y) + bound = 0.2 + units = UnitBox(min_x - bound, min_y - bound, + max_x - min_x + 2*bound, max_y - min_y + 2*bound) + units = UnitBox(-1.2, -1.2, 2.4, 2.4) # Determine sizes #NODESIZE = 0.25/sqrt(N) @@ -217,12 +240,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...) From 921d54d8c30dffc56a7b1112d10a0dae31e5ed65 Mon Sep 17 00:00:00 2001 From: davide-f <67809479+davide-f@users.noreply.github.com> Date: Sun, 1 Nov 2020 17:41:40 +0100 Subject: [PATCH 02/13] Update plot.jl --- src/plot.jl | 30 ++++++------------------------ 1 file changed, 6 insertions(+), 24 deletions(-) diff --git a/src/plot.jl b/src/plot.jl index 226a651..e1d6870 100644 --- a/src/plot.jl +++ b/src/plot.jl @@ -20,9 +20,6 @@ Default: `spring_layout` Locations of the nodes. Can be any units you want, but will be normalized and centered anyway -`preserveratio` -True if the plot shall use the same scaling factor for x and y axes. - `NODESIZE` Optional. Max size for the nodes. Default: `3.0/sqrt(N)` @@ -93,7 +90,6 @@ Optional. Angular width in radians for the arrows. Default: `π/9 (20 degrees)` """ function gplot(g::AbstractGraph{T}, locs_x_in::Vector{R}, locs_y_in::Vector{R}; - preserveratio = false, nodelabel = nothing, nodelabelc = colorant"black", nodelabelsize = 1.0, @@ -136,29 +132,15 @@ function gplot(g::AbstractGraph{T}, # Scale data min_x, max_x = extrema(locs_x) min_y, max_y = extrema(locs_y) - if preserveratio - # Uniform scale - function scaler(z, min, ratio) - 2 * (z - min) * ratio - 1 - end - min_ratio = min(1/(max_x - min_x), 1/(max_y - min_y)) - map!(z -> scaler(z, min_x, min_ratio), locs_x, locs_x) - map!(z -> scaler(z, min_y, min_ratio), locs_y, locs_y) - else - # Scale to unit square - function scalerunitsquare(z, a, b) - 2.0 * ((z - a) / (b - a)) - 1.0 - end - map!(z -> scalerunitsquare(z, min_x, max_x), locs_x, locs_x) - map!(z -> scalerunitsquare(z, min_y, max_y), locs_y, locs_y) + + # Scale to unit square + function scalerunitsquare(z, a, b) + 2.0 * ((z - a) / (b - a)) - 1.0 end + map!(z -> scalerunitsquare(z, min_x, max_x), locs_x, locs_x) + map!(z -> scalerunitsquare(z, min_y, max_y), locs_y, locs_y) # Calculate the size of the box - min_x, max_x = extrema(locs_x) - min_y, max_y = extrema(locs_y) - bound = 0.2 - units = UnitBox(min_x - bound, min_y - bound, - max_x - min_x + 2*bound, max_y - min_y + 2*bound) units = UnitBox(-1.2, -1.2, 2.4, 2.4) # Determine sizes From 40f1010966eee444124d04bbc03e38e45234b367 Mon Sep 17 00:00:00 2001 From: davide-f <67809479+davide-f@users.noreply.github.com> Date: Sun, 1 Nov 2020 17:47:16 +0100 Subject: [PATCH 03/13] Revert "Update plot.jl" This reverts commit 921d54d8c30dffc56a7b1112d10a0dae31e5ed65. --- src/plot.jl | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/src/plot.jl b/src/plot.jl index e1d6870..226a651 100644 --- a/src/plot.jl +++ b/src/plot.jl @@ -20,6 +20,9 @@ Default: `spring_layout` Locations of the nodes. Can be any units you want, but will be normalized and centered anyway +`preserveratio` +True if the plot shall use the same scaling factor for x and y axes. + `NODESIZE` Optional. Max size for the nodes. Default: `3.0/sqrt(N)` @@ -90,6 +93,7 @@ Optional. Angular width in radians for the arrows. Default: `π/9 (20 degrees)` """ function gplot(g::AbstractGraph{T}, locs_x_in::Vector{R}, locs_y_in::Vector{R}; + preserveratio = false, nodelabel = nothing, nodelabelc = colorant"black", nodelabelsize = 1.0, @@ -132,15 +136,29 @@ function gplot(g::AbstractGraph{T}, # Scale data min_x, max_x = extrema(locs_x) min_y, max_y = extrema(locs_y) - - # Scale to unit square - function scalerunitsquare(z, a, b) - 2.0 * ((z - a) / (b - a)) - 1.0 + if preserveratio + # Uniform scale + function scaler(z, min, ratio) + 2 * (z - min) * ratio - 1 + end + min_ratio = min(1/(max_x - min_x), 1/(max_y - min_y)) + map!(z -> scaler(z, min_x, min_ratio), locs_x, locs_x) + map!(z -> scaler(z, min_y, min_ratio), locs_y, locs_y) + else + # Scale to unit square + function scalerunitsquare(z, a, b) + 2.0 * ((z - a) / (b - a)) - 1.0 + end + map!(z -> scalerunitsquare(z, min_x, max_x), locs_x, locs_x) + map!(z -> scalerunitsquare(z, min_y, max_y), locs_y, locs_y) end - map!(z -> scalerunitsquare(z, min_x, max_x), locs_x, locs_x) - map!(z -> scalerunitsquare(z, min_y, max_y), locs_y, locs_y) # Calculate the size of the box + min_x, max_x = extrema(locs_x) + min_y, max_y = extrema(locs_y) + bound = 0.2 + units = UnitBox(min_x - bound, min_y - bound, + max_x - min_x + 2*bound, max_y - min_y + 2*bound) units = UnitBox(-1.2, -1.2, 2.4, 2.4) # Determine sizes From 816106dc3656e515822d8610ea7ab7b0d8b5ffb0 Mon Sep 17 00:00:00 2001 From: davide-f <67809479+davide-f@users.noreply.github.com> Date: Sun, 1 Nov 2020 17:47:27 +0100 Subject: [PATCH 04/13] Revert "Revert "Update plot.jl"" This reverts commit 40f1010966eee444124d04bbc03e38e45234b367. --- src/plot.jl | 30 ++++++------------------------ 1 file changed, 6 insertions(+), 24 deletions(-) diff --git a/src/plot.jl b/src/plot.jl index 226a651..e1d6870 100644 --- a/src/plot.jl +++ b/src/plot.jl @@ -20,9 +20,6 @@ Default: `spring_layout` Locations of the nodes. Can be any units you want, but will be normalized and centered anyway -`preserveratio` -True if the plot shall use the same scaling factor for x and y axes. - `NODESIZE` Optional. Max size for the nodes. Default: `3.0/sqrt(N)` @@ -93,7 +90,6 @@ Optional. Angular width in radians for the arrows. Default: `π/9 (20 degrees)` """ function gplot(g::AbstractGraph{T}, locs_x_in::Vector{R}, locs_y_in::Vector{R}; - preserveratio = false, nodelabel = nothing, nodelabelc = colorant"black", nodelabelsize = 1.0, @@ -136,29 +132,15 @@ function gplot(g::AbstractGraph{T}, # Scale data min_x, max_x = extrema(locs_x) min_y, max_y = extrema(locs_y) - if preserveratio - # Uniform scale - function scaler(z, min, ratio) - 2 * (z - min) * ratio - 1 - end - min_ratio = min(1/(max_x - min_x), 1/(max_y - min_y)) - map!(z -> scaler(z, min_x, min_ratio), locs_x, locs_x) - map!(z -> scaler(z, min_y, min_ratio), locs_y, locs_y) - else - # Scale to unit square - function scalerunitsquare(z, a, b) - 2.0 * ((z - a) / (b - a)) - 1.0 - end - map!(z -> scalerunitsquare(z, min_x, max_x), locs_x, locs_x) - map!(z -> scalerunitsquare(z, min_y, max_y), locs_y, locs_y) + + # Scale to unit square + function scalerunitsquare(z, a, b) + 2.0 * ((z - a) / (b - a)) - 1.0 end + map!(z -> scalerunitsquare(z, min_x, max_x), locs_x, locs_x) + map!(z -> scalerunitsquare(z, min_y, max_y), locs_y, locs_y) # Calculate the size of the box - min_x, max_x = extrema(locs_x) - min_y, max_y = extrema(locs_y) - bound = 0.2 - units = UnitBox(min_x - bound, min_y - bound, - max_x - min_x + 2*bound, max_y - min_y + 2*bound) units = UnitBox(-1.2, -1.2, 2.4, 2.4) # Determine sizes From 39e27ad9d3e0ed68b27d0e8d129a1ccfb4e319c6 Mon Sep 17 00:00:00 2001 From: davide-f <67809479+davide-f@users.noreply.github.com> Date: Sun, 1 Nov 2020 17:48:14 +0100 Subject: [PATCH 05/13] Update plot.jl --- src/plot.jl | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/plot.jl b/src/plot.jl index e1d6870..b43cd90 100644 --- a/src/plot.jl +++ b/src/plot.jl @@ -129,16 +129,19 @@ function gplot(g::AbstractGraph{T}, locs_x = Float64.(locs_x_in) locs_y = Float64.(locs_y_in) + # Scale to unit square # Scale data min_x, max_x = extrema(locs_x) min_y, max_y = extrema(locs_y) - - # Scale to unit square - function scalerunitsquare(z, a, b) - 2.0 * ((z - a) / (b - a)) - 1.0 + function scaler(z, a, b) + if (a - b) == 0.0 + return 0.5 + else + return 2.0 * ((z - a) / (b - a)) - 1.0 + end end - map!(z -> scalerunitsquare(z, min_x, max_x), locs_x, locs_x) - map!(z -> scalerunitsquare(z, min_y, max_y), locs_y, locs_y) + 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) From 387d1a9412e7854fcb9cb5e273ee0571d438b0e0 Mon Sep 17 00:00:00 2001 From: davide-f <67809479+davide-f@users.noreply.github.com> Date: Sun, 1 Nov 2020 17:49:27 +0100 Subject: [PATCH 06/13] Update plot.jl --- src/plot.jl | 1 - 1 file changed, 1 deletion(-) diff --git a/src/plot.jl b/src/plot.jl index b43cd90..864eaf2 100644 --- a/src/plot.jl +++ b/src/plot.jl @@ -130,7 +130,6 @@ function gplot(g::AbstractGraph{T}, locs_y = Float64.(locs_y_in) # Scale to unit square - # Scale data min_x, max_x = extrema(locs_x) min_y, max_y = extrema(locs_y) function scaler(z, a, b) From 94ec1d37fc6ecf181f654136feef2c5760700e92 Mon Sep 17 00:00:00 2001 From: davide-f <67809479+davide-f@users.noreply.github.com> Date: Mon, 5 Oct 2020 17:56:35 +0200 Subject: [PATCH 07/13] Update plot.jl Proposal to: 1) add a custom line dash style of the edges 2) specify whether to resize the box as a unit square or preserve the proportions (x and y axes) among the different stations --- src/plot.jl | 43 +++++++++++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/src/plot.jl b/src/plot.jl index b38554c..226a651 100644 --- a/src/plot.jl +++ b/src/plot.jl @@ -20,6 +20,9 @@ Default: `spring_layout` Locations of the nodes. Can be any units you want, but will be normalized and centered anyway +`preserveratio` +True if the plot shall use the same scaling factor for x and y axes. + `NODESIZE` Optional. Max size for the nodes. Default: `3.0/sqrt(N)` @@ -77,6 +80,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. 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 @@ -87,6 +93,7 @@ Optional. Angular width in radians for the arrows. Default: `π/9 (20 degrees)` """ function gplot(g::AbstractGraph{T}, locs_x_in::Vector{R}, locs_y_in::Vector{R}; + preserveratio = false, nodelabel = nothing, nodelabelc = colorant"black", nodelabelsize = 1.0, @@ -96,6 +103,7 @@ function gplot(g::AbstractGraph{T}, edgelabel = [], edgelabelc = colorant"black", edgelabelsize = 1.0, + edgedashstyle = [], EDGELABELSIZE = 4.0, edgestrokec = colorant"lightgray", edgelinewidth = 1.0, @@ -125,18 +133,33 @@ function gplot(g::AbstractGraph{T}, locs_x = Float64.(locs_x_in) locs_y = Float64.(locs_y_in) - # Scale to unit square + # Scale data min_x, max_x = extrema(locs_x) min_y, max_y = extrema(locs_y) - function scaler(z, a, b) - if (a - b) == 0.0 - return 0.5 - else - return 2.0 * ((z - a) / (b - a)) - 1.0 + if preserveratio + # Uniform scale + function scaler(z, min, ratio) + 2 * (z - min) * ratio - 1 + end + min_ratio = min(1/(max_x - min_x), 1/(max_y - min_y)) + map!(z -> scaler(z, min_x, min_ratio), locs_x, locs_x) + map!(z -> scaler(z, min_y, min_ratio), locs_y, locs_y) + else + # Scale to unit square + function scalerunitsquare(z, a, b) + 2.0 * ((z - a) / (b - a)) - 1.0 end + map!(z -> scalerunitsquare(z, min_x, max_x), locs_x, locs_x) + map!(z -> scalerunitsquare(z, min_y, max_y), locs_y, locs_y) end - 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 + min_x, max_x = extrema(locs_x) + min_y, max_y = extrema(locs_y) + bound = 0.2 + units = UnitBox(min_x - bound, min_y - bound, + max_x - min_x + 2*bound, max_y - min_y + 2*bound) + units = UnitBox(-1.2, -1.2, 2.4, 2.4) # Determine sizes #NODESIZE = 0.25/sqrt(N) @@ -217,12 +240,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...) From 81a9cdf1e35e4e38048a1459e425c2f19398716c Mon Sep 17 00:00:00 2001 From: davide-f <67809479+davide-f@users.noreply.github.com> Date: Sun, 1 Nov 2020 17:41:40 +0100 Subject: [PATCH 08/13] Update plot.jl --- src/plot.jl | 30 ++++++------------------------ 1 file changed, 6 insertions(+), 24 deletions(-) diff --git a/src/plot.jl b/src/plot.jl index 226a651..e1d6870 100644 --- a/src/plot.jl +++ b/src/plot.jl @@ -20,9 +20,6 @@ Default: `spring_layout` Locations of the nodes. Can be any units you want, but will be normalized and centered anyway -`preserveratio` -True if the plot shall use the same scaling factor for x and y axes. - `NODESIZE` Optional. Max size for the nodes. Default: `3.0/sqrt(N)` @@ -93,7 +90,6 @@ Optional. Angular width in radians for the arrows. Default: `π/9 (20 degrees)` """ function gplot(g::AbstractGraph{T}, locs_x_in::Vector{R}, locs_y_in::Vector{R}; - preserveratio = false, nodelabel = nothing, nodelabelc = colorant"black", nodelabelsize = 1.0, @@ -136,29 +132,15 @@ function gplot(g::AbstractGraph{T}, # Scale data min_x, max_x = extrema(locs_x) min_y, max_y = extrema(locs_y) - if preserveratio - # Uniform scale - function scaler(z, min, ratio) - 2 * (z - min) * ratio - 1 - end - min_ratio = min(1/(max_x - min_x), 1/(max_y - min_y)) - map!(z -> scaler(z, min_x, min_ratio), locs_x, locs_x) - map!(z -> scaler(z, min_y, min_ratio), locs_y, locs_y) - else - # Scale to unit square - function scalerunitsquare(z, a, b) - 2.0 * ((z - a) / (b - a)) - 1.0 - end - map!(z -> scalerunitsquare(z, min_x, max_x), locs_x, locs_x) - map!(z -> scalerunitsquare(z, min_y, max_y), locs_y, locs_y) + + # Scale to unit square + function scalerunitsquare(z, a, b) + 2.0 * ((z - a) / (b - a)) - 1.0 end + map!(z -> scalerunitsquare(z, min_x, max_x), locs_x, locs_x) + map!(z -> scalerunitsquare(z, min_y, max_y), locs_y, locs_y) # Calculate the size of the box - min_x, max_x = extrema(locs_x) - min_y, max_y = extrema(locs_y) - bound = 0.2 - units = UnitBox(min_x - bound, min_y - bound, - max_x - min_x + 2*bound, max_y - min_y + 2*bound) units = UnitBox(-1.2, -1.2, 2.4, 2.4) # Determine sizes From 0b79a110eeae2127cd1f5c8b0cca6b15c77a45c0 Mon Sep 17 00:00:00 2001 From: davide-f <67809479+davide-f@users.noreply.github.com> Date: Sun, 1 Nov 2020 17:47:16 +0100 Subject: [PATCH 09/13] Revert "Update plot.jl" This reverts commit 921d54d8c30dffc56a7b1112d10a0dae31e5ed65. --- src/plot.jl | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/src/plot.jl b/src/plot.jl index e1d6870..226a651 100644 --- a/src/plot.jl +++ b/src/plot.jl @@ -20,6 +20,9 @@ Default: `spring_layout` Locations of the nodes. Can be any units you want, but will be normalized and centered anyway +`preserveratio` +True if the plot shall use the same scaling factor for x and y axes. + `NODESIZE` Optional. Max size for the nodes. Default: `3.0/sqrt(N)` @@ -90,6 +93,7 @@ Optional. Angular width in radians for the arrows. Default: `π/9 (20 degrees)` """ function gplot(g::AbstractGraph{T}, locs_x_in::Vector{R}, locs_y_in::Vector{R}; + preserveratio = false, nodelabel = nothing, nodelabelc = colorant"black", nodelabelsize = 1.0, @@ -132,15 +136,29 @@ function gplot(g::AbstractGraph{T}, # Scale data min_x, max_x = extrema(locs_x) min_y, max_y = extrema(locs_y) - - # Scale to unit square - function scalerunitsquare(z, a, b) - 2.0 * ((z - a) / (b - a)) - 1.0 + if preserveratio + # Uniform scale + function scaler(z, min, ratio) + 2 * (z - min) * ratio - 1 + end + min_ratio = min(1/(max_x - min_x), 1/(max_y - min_y)) + map!(z -> scaler(z, min_x, min_ratio), locs_x, locs_x) + map!(z -> scaler(z, min_y, min_ratio), locs_y, locs_y) + else + # Scale to unit square + function scalerunitsquare(z, a, b) + 2.0 * ((z - a) / (b - a)) - 1.0 + end + map!(z -> scalerunitsquare(z, min_x, max_x), locs_x, locs_x) + map!(z -> scalerunitsquare(z, min_y, max_y), locs_y, locs_y) end - map!(z -> scalerunitsquare(z, min_x, max_x), locs_x, locs_x) - map!(z -> scalerunitsquare(z, min_y, max_y), locs_y, locs_y) # Calculate the size of the box + min_x, max_x = extrema(locs_x) + min_y, max_y = extrema(locs_y) + bound = 0.2 + units = UnitBox(min_x - bound, min_y - bound, + max_x - min_x + 2*bound, max_y - min_y + 2*bound) units = UnitBox(-1.2, -1.2, 2.4, 2.4) # Determine sizes From 298a83aaed83d850e9828db3be8f5be666921682 Mon Sep 17 00:00:00 2001 From: davide-f <67809479+davide-f@users.noreply.github.com> Date: Sun, 1 Nov 2020 17:47:27 +0100 Subject: [PATCH 10/13] Revert "Revert "Update plot.jl"" This reverts commit 40f1010966eee444124d04bbc03e38e45234b367. --- src/plot.jl | 30 ++++++------------------------ 1 file changed, 6 insertions(+), 24 deletions(-) diff --git a/src/plot.jl b/src/plot.jl index 226a651..e1d6870 100644 --- a/src/plot.jl +++ b/src/plot.jl @@ -20,9 +20,6 @@ Default: `spring_layout` Locations of the nodes. Can be any units you want, but will be normalized and centered anyway -`preserveratio` -True if the plot shall use the same scaling factor for x and y axes. - `NODESIZE` Optional. Max size for the nodes. Default: `3.0/sqrt(N)` @@ -93,7 +90,6 @@ Optional. Angular width in radians for the arrows. Default: `π/9 (20 degrees)` """ function gplot(g::AbstractGraph{T}, locs_x_in::Vector{R}, locs_y_in::Vector{R}; - preserveratio = false, nodelabel = nothing, nodelabelc = colorant"black", nodelabelsize = 1.0, @@ -136,29 +132,15 @@ function gplot(g::AbstractGraph{T}, # Scale data min_x, max_x = extrema(locs_x) min_y, max_y = extrema(locs_y) - if preserveratio - # Uniform scale - function scaler(z, min, ratio) - 2 * (z - min) * ratio - 1 - end - min_ratio = min(1/(max_x - min_x), 1/(max_y - min_y)) - map!(z -> scaler(z, min_x, min_ratio), locs_x, locs_x) - map!(z -> scaler(z, min_y, min_ratio), locs_y, locs_y) - else - # Scale to unit square - function scalerunitsquare(z, a, b) - 2.0 * ((z - a) / (b - a)) - 1.0 - end - map!(z -> scalerunitsquare(z, min_x, max_x), locs_x, locs_x) - map!(z -> scalerunitsquare(z, min_y, max_y), locs_y, locs_y) + + # Scale to unit square + function scalerunitsquare(z, a, b) + 2.0 * ((z - a) / (b - a)) - 1.0 end + map!(z -> scalerunitsquare(z, min_x, max_x), locs_x, locs_x) + map!(z -> scalerunitsquare(z, min_y, max_y), locs_y, locs_y) # Calculate the size of the box - min_x, max_x = extrema(locs_x) - min_y, max_y = extrema(locs_y) - bound = 0.2 - units = UnitBox(min_x - bound, min_y - bound, - max_x - min_x + 2*bound, max_y - min_y + 2*bound) units = UnitBox(-1.2, -1.2, 2.4, 2.4) # Determine sizes From bf1a00d3d4a43e100d43883e787814e7ed82e4b4 Mon Sep 17 00:00:00 2001 From: davide-f <67809479+davide-f@users.noreply.github.com> Date: Sun, 1 Nov 2020 17:48:14 +0100 Subject: [PATCH 11/13] Update plot.jl --- src/plot.jl | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/plot.jl b/src/plot.jl index e1d6870..b43cd90 100644 --- a/src/plot.jl +++ b/src/plot.jl @@ -129,16 +129,19 @@ function gplot(g::AbstractGraph{T}, locs_x = Float64.(locs_x_in) locs_y = Float64.(locs_y_in) + # Scale to unit square # Scale data min_x, max_x = extrema(locs_x) min_y, max_y = extrema(locs_y) - - # Scale to unit square - function scalerunitsquare(z, a, b) - 2.0 * ((z - a) / (b - a)) - 1.0 + function scaler(z, a, b) + if (a - b) == 0.0 + return 0.5 + else + return 2.0 * ((z - a) / (b - a)) - 1.0 + end end - map!(z -> scalerunitsquare(z, min_x, max_x), locs_x, locs_x) - map!(z -> scalerunitsquare(z, min_y, max_y), locs_y, locs_y) + 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) From 3f20a1996058c86bb27fadf261c41c1477354ebc Mon Sep 17 00:00:00 2001 From: davide-f <67809479+davide-f@users.noreply.github.com> Date: Sun, 1 Nov 2020 17:49:27 +0100 Subject: [PATCH 12/13] Update plot.jl --- src/plot.jl | 1 - 1 file changed, 1 deletion(-) diff --git a/src/plot.jl b/src/plot.jl index b43cd90..864eaf2 100644 --- a/src/plot.jl +++ b/src/plot.jl @@ -130,7 +130,6 @@ function gplot(g::AbstractGraph{T}, locs_y = Float64.(locs_y_in) # Scale to unit square - # Scale data min_x, max_x = extrema(locs_x) min_y, max_y = extrema(locs_y) function scaler(z, a, b) From 13fb265f4058a27fbc44222994ac0b47c31652e4 Mon Sep 17 00:00:00 2001 From: etienneINSA Date: Fri, 22 Jul 2022 13:31:45 +0200 Subject: [PATCH 13/13] add documentation --- README.md | 9 +++++++++ src/plot.jl | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) 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 864eaf2..e2ae02e 100644 --- a/src/plot.jl +++ b/src/plot.jl @@ -78,7 +78,7 @@ Optional. Relative line width for the edges, can be a Vector. Default: `1.0` Optional. Color for the edge strokes, can be a Vector. Default: `colorant"lightgray"` `edgedashstyle` -Optional. Dash style for the edge. Default: no dashed line. +Optional. Dash style for the edge, can be a Vector. Default: no dashed line. `arrowlengthfrac` Optional. Fraction of line length to use for arrows.