Skip to content

Commit 40f1010

Browse files
committed
Revert "Update plot.jl"
This reverts commit 921d54d.
1 parent 921d54d commit 40f1010

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

src/plot.jl

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ Default: `spring_layout`
2020
Locations of the nodes. Can be any units you want,
2121
but will be normalized and centered anyway
2222
23+
`preserveratio`
24+
True if the plot shall use the same scaling factor for x and y axes.
25+
2326
`NODESIZE`
2427
Optional. Max size for the nodes. Default: `3.0/sqrt(N)`
2528
@@ -90,6 +93,7 @@ Optional. Angular width in radians for the arrows. Default: `π/9 (20 degrees)`
9093
"""
9194
function gplot(g::AbstractGraph{T},
9295
locs_x_in::Vector{R}, locs_y_in::Vector{R};
96+
preserveratio = false,
9397
nodelabel = nothing,
9498
nodelabelc = colorant"black",
9599
nodelabelsize = 1.0,
@@ -132,15 +136,29 @@ function gplot(g::AbstractGraph{T},
132136
# Scale data
133137
min_x, max_x = extrema(locs_x)
134138
min_y, max_y = extrema(locs_y)
135-
136-
# Scale to unit square
137-
function scalerunitsquare(z, a, b)
138-
2.0 * ((z - a) / (b - a)) - 1.0
139+
if preserveratio
140+
# Uniform scale
141+
function scaler(z, min, ratio)
142+
2 * (z - min) * ratio - 1
143+
end
144+
min_ratio = min(1/(max_x - min_x), 1/(max_y - min_y))
145+
map!(z -> scaler(z, min_x, min_ratio), locs_x, locs_x)
146+
map!(z -> scaler(z, min_y, min_ratio), locs_y, locs_y)
147+
else
148+
# Scale to unit square
149+
function scalerunitsquare(z, a, b)
150+
2.0 * ((z - a) / (b - a)) - 1.0
151+
end
152+
map!(z -> scalerunitsquare(z, min_x, max_x), locs_x, locs_x)
153+
map!(z -> scalerunitsquare(z, min_y, max_y), locs_y, locs_y)
139154
end
140-
map!(z -> scalerunitsquare(z, min_x, max_x), locs_x, locs_x)
141-
map!(z -> scalerunitsquare(z, min_y, max_y), locs_y, locs_y)
142155

143156
# Calculate the size of the box
157+
min_x, max_x = extrema(locs_x)
158+
min_y, max_y = extrema(locs_y)
159+
bound = 0.2
160+
units = UnitBox(min_x - bound, min_y - bound,
161+
max_x - min_x + 2*bound, max_y - min_y + 2*bound)
144162
units = UnitBox(-1.2, -1.2, 2.4, 2.4)
145163

146164
# Determine sizes

0 commit comments

Comments
 (0)