Skip to content

Commit

Permalink
Revert "Update plot.jl"
Browse files Browse the repository at this point in the history
This reverts commit 921d54d.
  • Loading branch information
davide-f committed Nov 1, 2020
1 parent 921d54d commit 40f1010
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions src/plot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)`
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 40f1010

Please sign in to comment.