From 36a80056a7cf821c095021d0845ee8e29c683c12 Mon Sep 17 00:00:00 2001 From: hdavid16 Date: Mon, 1 Aug 2022 22:05:44 -0500 Subject: [PATCH 1/2] Fix #107 -Allow add title -Set title color and size -Set font family for entire plot -Remove unneded Compose objects (the ones with `nothing` as the arg) --- README.md | 4 ++++ src/plot.jl | 26 ++++++++++++++++++++++---- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index e5dd530..6ba959b 100644 --- a/README.md +++ b/README.md @@ -160,6 +160,10 @@ gplot(h) # Keyword Arguments + `layout` Layout algorithm: `random_layout`, `circular_layout`, `spring_layout`, `shell_layout`, `stressmajorize_layout`, `spectral_layout`. Default: `spring_layout` ++ `title` Plot title. Default: `""` ++ `title_color` Plot title color. Default: `colorant"black"` ++ `title_size` Plot title size. Default: `4.0` ++ `font_family` Font family for all text. Default: `"Helvetica"` + `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` diff --git a/src/plot.jl b/src/plot.jl index af438b7..4ca56fa 100644 --- a/src/plot.jl +++ b/src/plot.jl @@ -23,6 +23,18 @@ Layout algorithm. Currently can be one of [`random_layout`, `spectral_layout`]. Default: `spring_layout` +`title` +Plot title. Default: `""` + +`title_color` +Plot title color. Default: `colorant"black"` + +`title_size` +Plot title size. Default: `4.0` + +`font_family` +Font family for all text. Default: `"Helvetica"` + `NODESIZE` Max size for the nodes. Default: `3.0/sqrt(N)` @@ -97,6 +109,10 @@ Default: `π/5 (36 degrees)` """ function gplot(g::AbstractGraph{T}, locs_x_in::Vector{R1}, locs_y_in::Vector{R2}; + title = "", + title_color = colorant"black", + title_size = 4.0, + font_family = "Helvetica", nodelabel = nothing, nodelabelc = colorant"black", nodelabelsize = 1.0, @@ -227,12 +243,14 @@ function gplot(g::AbstractGraph{T}, end end - compose(context(units=UnitBox(-1.2, -1.2, +2.4, +2.4)), - compose(context(), texts, fill(nodelabelc), stroke(nothing), fontsize(nodelabelsize)), + title_offset = isempty(title) ? 0 : 0.3 + compose(context(units=UnitBox(-1.2, -1.2 - title_offset, +2.4, +2.4 + title_offset)), + compose(context(), text(0,-1.2,title), fill(title_color), fontsize(title_size), font(font_family)), + compose(context(), texts, fill(nodelabelc), fontsize(nodelabelsize), font(font_family)), compose(context(), nodes, fill(nodefillc), stroke(nodestrokec), linewidth(nodestrokelw)), - compose(context(), edgetexts, fill(edgelabelc), stroke(nothing), fontsize(edgelabelsize)), + compose(context(), edgetexts, fill(edgelabelc), fontsize(edgelabelsize), font(font_family)), compose(context(), arrows, stroke(edgestrokec), linewidth(edgelinewidth)), - compose(context(), lines, stroke(edgestrokec), fill(nothing), linewidth(edgelinewidth))) + compose(context(), lines, stroke(edgestrokec), linewidth(edgelinewidth))) end function gplot(g; layout::Function=spring_layout, keyargs...) From c2f707947921496244b5e886ca69167419807048 Mon Sep 17 00:00:00 2001 From: hdavid16 Date: Tue, 2 Aug 2022 06:19:30 -0500 Subject: [PATCH 2/2] scale title margin with title font size --- src/plot.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/plot.jl b/src/plot.jl index 4ca56fa..59a63f0 100644 --- a/src/plot.jl +++ b/src/plot.jl @@ -243,9 +243,9 @@ function gplot(g::AbstractGraph{T}, end end - title_offset = isempty(title) ? 0 : 0.3 + title_offset = isempty(title) ? 0 : 0.1*title_size/4 compose(context(units=UnitBox(-1.2, -1.2 - title_offset, +2.4, +2.4 + title_offset)), - compose(context(), text(0,-1.2,title), fill(title_color), fontsize(title_size), font(font_family)), + compose(context(), text(0, -1.2 - title_offset/2, title, hcenter, vcenter), fill(title_color), fontsize(title_size), font(font_family)), compose(context(), texts, fill(nodelabelc), fontsize(nodelabelsize), font(font_family)), compose(context(), nodes, fill(nodefillc), stroke(nodestrokec), linewidth(nodestrokelw)), compose(context(), edgetexts, fill(edgelabelc), fontsize(edgelabelsize), font(font_family)),