@@ -20,6 +20,9 @@ Default: `spring_layout`
20
20
Locations of the nodes. Can be any units you want,
21
21
but will be normalized and centered anyway
22
22
23
+ `preserveratio`
24
+ True if the plot shall use the same scaling factor for x and y axes.
25
+
23
26
`NODESIZE`
24
27
Optional. Max size for the nodes. Default: `3.0/sqrt(N)`
25
28
@@ -90,6 +93,7 @@ Optional. Angular width in radians for the arrows. Default: `π/9 (20 degrees)`
90
93
"""
91
94
function gplot (g:: AbstractGraph{T} ,
92
95
locs_x_in:: Vector{R} , locs_y_in:: Vector{R} ;
96
+ preserveratio = false ,
93
97
nodelabel = nothing ,
94
98
nodelabelc = colorant " black" ,
95
99
nodelabelsize = 1.0 ,
@@ -132,15 +136,29 @@ function gplot(g::AbstractGraph{T},
132
136
# Scale data
133
137
min_x, max_x = extrema (locs_x)
134
138
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)
139
154
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)
142
155
143
156
# 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)
144
162
units = UnitBox (- 1.2 , - 1.2 , 2.4 , 2.4 )
145
163
146
164
# Determine sizes
0 commit comments