Skip to content

Commit

Permalink
support changing plot size (fixes JuliaGraphs#94, JuliaGraphs#147)
Browse files Browse the repository at this point in the history
uses Colorant.set_default_graphic_size
  • Loading branch information
hdavid16 committed Jul 28, 2022
1 parent 52f4aae commit 4244133
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ gplot(h)
+ `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)`
+ `plot_size` Tuple of measures for width x height of plot area. Default: `nothing`

# Reporting Bugs

Expand Down
13 changes: 12 additions & 1 deletion src/plot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ Type of line used for edges ("straight", "curve"). Default: "straight"
Angular width in radians for the edges (only used if `linetype = "curve`).
Default: `π/5 (36 degrees)`
`plot_size`
Tuple of measures for width x height of plot area. Default: `nothing`
"""
function gplot(g::AbstractGraph{T},
locs_x_in::Vector{R1}, locs_y_in::Vector{R2};
Expand All @@ -120,7 +123,9 @@ function gplot(g::AbstractGraph{T},
arrowlengthfrac = is_directed(g) ? 0.1 : 0.0,
arrowangleoffset = π / 9,
linetype = "straight",
outangle = π / 5) where {T <:Integer, R1 <: Real, R2 <: Real}
outangle = π / 5,
plot_size = nothing
) where {T <:Integer, R1 <: Real, R2 <: Real}

length(locs_x_in) != length(locs_y_in) && error("Vectors must be same length")
N = nv(g)
Expand Down Expand Up @@ -227,6 +232,12 @@ function gplot(g::AbstractGraph{T},
end
end

if !isnothing(plot_size)
if length(plot_size) != 2 || !isa(plot_size[1], Compose.AbsoluteLength) || !isa(plot_size[2], Compose.AbsoluteLength)
error("`plot_size` must be a Tuple of lengths or `nothing`")
end
Compose.set_default_graphic_size(plot_size...)
end
compose(context(units=UnitBox(-1.2, -1.2, +2.4, +2.4)),
compose(context(), texts, fill(nodelabelc), stroke(nothing), fontsize(nodelabelsize)),
compose(context(), nodes, fill(nodefillc), stroke(nodestrokec), linewidth(nodestrokelw)),
Expand Down

0 comments on commit 4244133

Please sign in to comment.