@@ -23,7 +23,7 @@ Layout algorithm. Currently can be one of [`random_layout`,
23
23
`spectral_layout`].
24
24
Default: `spring_layout`
25
25
26
- `NODESIZE `
26
+ `max_nodesize `
27
27
Max size for the nodes. Default: `3.0/sqrt(N)`
28
28
29
29
`nodesize`
@@ -41,7 +41,7 @@ Distances for the node labels from center of nodes. Default: `0.0`
41
41
`nodelabelangleoffset`
42
42
Angle offset for the node labels. Default: `π/4.0`
43
43
44
- `NODELABELSIZE `
44
+ `max_nodelabelsize `
45
45
Largest fontsize for the vertex labels. Default: `4.0`
46
46
47
47
`nodelabelsize`
@@ -57,21 +57,21 @@ Color for the nodes stroke, can be a Vector. Default: `nothing`
57
57
Line width for the nodes stroke, can be a Vector. Default: `0.0`
58
58
59
59
`edgelabel`
60
- Labels for the edges, a Vector or nothing. Default: `[] `
60
+ Labels for the edges, a Vector or nothing. Default: `nothing `
61
61
62
62
`edgelabelc`
63
63
Color for the edge labels, can be a Vector. Default: `colorant"black"`
64
64
65
65
`edgelabeldistx, edgelabeldisty`
66
66
Distance for the edge label from center of edge. Default: `0.0`
67
67
68
- `EDGELABELSIZE `
68
+ `max_edgelabelsize `
69
69
Largest fontsize for the edge labels. Default: `4.0`
70
70
71
71
`edgelabelsize`
72
72
Relative fontsize for the edge labels, can be a Vector. Default: `1.0`
73
73
74
- `EDGELINEWIDTH `
74
+ `max_edgelinewidth `
75
75
Max line width for the edges. Default: `0.25/sqrt(N)`
76
76
77
77
`edgelinewidth`
@@ -88,7 +88,7 @@ Equal to 0 for undirected graphs. Default: `0.1` for the directed graphs
88
88
Angular width in radians for the arrows. Default: `π/9 (20 degrees)`
89
89
90
90
`linetype`
91
- Type of line used for edges (" straight", " curve" ). Default: " straight"
91
+ Type of line used for edges (: straight, : curve). Default: : straight
92
92
93
93
`outangle`
94
94
Angular width in radians for the edges (only used if `linetype = "curve`).
@@ -103,38 +103,32 @@ function gplot(g::AbstractGraph{T},
103
103
nodelabel = nothing ,
104
104
nodelabelc = colorant " black" ,
105
105
nodelabelsize = 1.0 ,
106
- NODELABELSIZE = 4.0 ,
106
+ max_nodelabelsize = 4.0 ,
107
107
nodelabeldist = 0.0 ,
108
108
nodelabelangleoffset = π / 4.0 ,
109
- edgelabel = [] ,
109
+ edgelabel = nothing ,
110
110
edgelabelc = colorant " black" ,
111
111
edgelabelsize = 1.0 ,
112
- EDGELABELSIZE = 4.0 ,
112
+ max_edgelabelsize = 4.0 ,
113
113
edgestrokec = colorant " lightgray" ,
114
114
edgelinewidth = 1.0 ,
115
- EDGELINEWIDTH = 3.0 / sqrt (nv (g)),
115
+ max_edgelinewidth = 3.0 / sqrt (nv (g)),
116
116
edgelabeldistx = 0.0 ,
117
117
edgelabeldisty = 0.0 ,
118
118
nodesize = 1.0 ,
119
- NODESIZE = 0.25 / sqrt (nv (g)),
119
+ max_nodesize = 0.25 / sqrt (nv (g)),
120
120
nodefillc = colorant " turquoise" ,
121
121
nodestrokec = nothing ,
122
122
nodestrokelw = 0.0 ,
123
123
arrowlengthfrac = is_directed (g) ? 0.1 : 0.0 ,
124
124
arrowangleoffset = π / 9 ,
125
- linetype = " straight" ,
125
+ linetype = : straight ,
126
126
outangle = π / 5 ,
127
127
backgroundc = nothing ) where {T <: Integer , R1 <: Real , R2 <: Real }
128
128
129
- length (locs_x_in) != length (locs_y_in) && error (" Vectors must be same length" )
130
- N = nv (g)
131
- NE = ne (g)
132
- if nodelabel != nothing && length (nodelabel) != N
133
- error (" Must have one label per node (or none)" )
134
- end
135
- if ! isempty (edgelabel) && length (edgelabel) != NE
136
- error (" Must have one label per edge (or none)" )
137
- end
129
+ @assert length (locs_x_in) == length (locs_y_in) == nv (g) " Position vectors must be of the same length as the number of nodes"
130
+ @assert isnothing (nodelabel) || length (nodelabel) == nv (g) " `nodelabel` must either be `nothing` or a vector of the same length as the number of nodes"
131
+ @assert isnothing (edgelabel) || length (edgelabel) == ne (g) " `edgelabel` must either be `nothing` or a vector of the same length as the number of edges"
138
132
139
133
locs_x = Float64 .(locs_x_in)
140
134
locs_y = Float64 .(locs_y_in)
@@ -152,35 +146,18 @@ function gplot(g::AbstractGraph{T},
152
146
map! (z -> scaler (z, min_x, max_x), locs_x, locs_x)
153
147
map! (z -> scaler (z, min_y, max_y), locs_y, locs_y)
154
148
155
- # Determine sizes
156
- # NODESIZE = 0.25/sqrt(N)
157
- # LINEWIDTH = 3.0/sqrt(N)
158
-
159
- max_nodesize = NODESIZE / maximum (nodesize)
160
- nodesize *= max_nodesize
161
- max_edgelinewidth = EDGELINEWIDTH / maximum (edgelinewidth)
162
- edgelinewidth *= max_edgelinewidth
163
- max_edgelabelsize = EDGELABELSIZE / maximum (edgelabelsize)
164
- edgelabelsize *= max_edgelabelsize
165
- max_nodelabelsize = NODELABELSIZE / maximum (nodelabelsize)
166
- nodelabelsize *= max_nodelabelsize
149
+ # Scale sizes
150
+ nodesize *= (max_nodesize / maximum (nodesize))
151
+ edgelinewidth *= (max_edgelinewidth / maximum (edgelinewidth))
152
+ edgelabelsize *= (max_edgelabelsize / maximum (edgelabelsize))
153
+ nodelabelsize *= (max_nodelabelsize / maximum (nodelabelsize))
167
154
max_nodestrokelw = maximum (nodestrokelw)
168
155
if max_nodestrokelw > 0.0
169
- max_nodestrokelw = EDGELINEWIDTH / max_nodestrokelw
170
- nodestrokelw *= max_nodestrokelw
156
+ nodestrokelw *= (max_edgelinewidth / max_nodestrokelw)
171
157
end
172
158
173
159
# Create nodes
174
- nodecircle = fill (0.4 Compose. w, length (locs_x))
175
- if isa (nodesize, Real)
176
- for i = 1 : length (locs_x)
177
- nodecircle[i] *= nodesize
178
- end
179
- else
180
- for i = 1 : length (locs_x)
181
- nodecircle[i] *= nodesize[i]
182
- end
183
- end
160
+ nodecircle = fill (0.4 Compose. w, nv (g)) .* nodesize
184
161
nodes = circle (locs_x, locs_y, nodecircle)
185
162
186
163
# Create node labels if provided
@@ -194,24 +171,23 @@ function gplot(g::AbstractGraph{T},
194
171
end
195
172
# Create edge labels if provided
196
173
edgetexts = nothing
197
- if ! isempty (edgelabel)
174
+ if ! isnothing (edgelabel)
198
175
edge_locs_x = zeros (R, NE)
199
176
edge_locs_y = zeros (R, NE)
200
177
for (e_idx, e) in enumerate (edges (g))
201
178
i = src (e)
202
179
j = dst (e)
203
180
mid_x = (locs_x[i]+ locs_x[j]) / 2.0
204
181
mid_y = (locs_y[i]+ locs_y[j]) / 2.0
205
- edge_locs_x[e_idx] = (is_directed (g) ? (mid_x+ locs_x[j]) / 2.0 : mid_x) + edgelabeldistx * NODESIZE
206
- edge_locs_y[e_idx] = (is_directed (g) ? (mid_y+ locs_y[j]) / 2.0 : mid_y) + edgelabeldisty * NODESIZE
207
-
182
+ edge_locs_x[e_idx] = (is_directed (g) ? (mid_x+ locs_x[j]) / 2.0 : mid_x) + edgelabeldistx * max_nodesize
183
+ edge_locs_y[e_idx] = (is_directed (g) ? (mid_y+ locs_y[j]) / 2.0 : mid_y) + edgelabeldisty * max_nodesize
208
184
end
209
185
edgetexts = text (edge_locs_x, edge_locs_y, map (string, edgelabel), [hcenter], [vcenter])
210
186
end
211
187
212
188
# Create lines and arrow heads
213
189
lines, arrows = nothing , nothing
214
- if linetype == " curve"
190
+ if linetype == : curve
215
191
if arrowlengthfrac > 0.0
216
192
curves_cord, arrows_cord = graphcurve (g, locs_x, locs_y, nodesize, arrowlengthfrac, arrowangleoffset, outangle)
217
193
lines = curve (curves_cord[:,1 ], curves_cord[:,2 ], curves_cord[:,3 ], curves_cord[:,4 ])
0 commit comments