@@ -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
@@ -77,6 +80,9 @@ Optional. Relative line width for the edges, can be a Vector. Default: `1.0`
77
80
`edgestrokec`
78
81
Optional. Color for the edge strokes, can be a Vector. Default: `colorant"lightgray"`
79
82
83
+ `edgedashstyle`
84
+ Optional. Dash style for the edge. Default: no dashed line.
85
+
80
86
`arrowlengthfrac`
81
87
Optional. Fraction of line length to use for arrows.
82
88
Equal to 0 for undirected graphs. Default: `0.1` for the directed graphs
@@ -87,6 +93,7 @@ Optional. Angular width in radians for the arrows. Default: `π/9 (20 degrees)`
87
93
"""
88
94
function gplot (g:: AbstractGraph{T} ,
89
95
locs_x_in:: Vector{R} , locs_y_in:: Vector{R} ;
96
+ preserveratio = false ,
90
97
nodelabel = nothing ,
91
98
nodelabelc = colorant " black" ,
92
99
nodelabelsize = 1.0 ,
@@ -96,6 +103,7 @@ function gplot(g::AbstractGraph{T},
96
103
edgelabel = [],
97
104
edgelabelc = colorant " black" ,
98
105
edgelabelsize = 1.0 ,
106
+ edgedashstyle = [],
99
107
EDGELABELSIZE = 4.0 ,
100
108
edgestrokec = colorant " lightgray" ,
101
109
edgelinewidth = 1.0 ,
@@ -125,18 +133,33 @@ function gplot(g::AbstractGraph{T},
125
133
locs_x = Float64 .(locs_x_in)
126
134
locs_y = Float64 .(locs_y_in)
127
135
128
- # Scale to unit square
136
+ # Scale data
129
137
min_x, max_x = extrema (locs_x)
130
138
min_y, max_y = extrema (locs_y)
131
- function scaler (z, a, b)
132
- if (a - b) == 0.0
133
- return 0.5
134
- else
135
- return 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
136
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)
137
154
end
138
- map! (z -> scaler (z, min_x, max_x), locs_x, locs_x)
139
- map! (z -> scaler (z, min_y, max_y), locs_y, locs_y)
155
+
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)
162
+ units = UnitBox (- 1.2 , - 1.2 , 2.4 , 2.4 )
140
163
141
164
# Determine sizes
142
165
# NODESIZE = 0.25/sqrt(N)
@@ -217,12 +240,12 @@ function gplot(g::AbstractGraph{T},
217
240
end
218
241
end
219
242
220
- compose (context (units= UnitBox ( - 1.2 , - 1.2 , + 2.4 , + 2.4 ) ),
243
+ compose (context (units= units ),
221
244
compose (context (), texts, fill (nodelabelc), stroke (nothing ), fontsize (nodelabelsize)),
222
245
compose (context (), nodes, fill (nodefillc), stroke (nodestrokec), linewidth (nodestrokelw)),
223
246
compose (context (), edgetexts, fill (edgelabelc), stroke (nothing ), fontsize (edgelabelsize)),
224
247
compose (context (), arrows, stroke (edgestrokec), linewidth (edgelinewidth)),
225
- compose (context (), lines, stroke (edgestrokec), fill (nothing ), linewidth (edgelinewidth)))
248
+ compose (context (), lines, stroke (edgestrokec), strokedash (edgedashstyle), fill (nothing ), linewidth (edgelinewidth)))
226
249
end
227
250
228
251
function gplot (g; layout:: Function = spring_layout, keyargs... )
0 commit comments