@@ -92,23 +92,23 @@ function gplot(g::AbstractGraph{T},
92
92
nodelabelsize = 1.0 ,
93
93
NODELABELSIZE = 4.0 ,
94
94
nodelabeldist = 0.0 ,
95
- nodelabelangleoffset = π/ 4.0 ,
95
+ nodelabelangleoffset = π / 4.0 ,
96
96
edgelabel = [],
97
97
edgelabelc = colorant " black" ,
98
98
edgelabelsize = 1.0 ,
99
99
EDGELABELSIZE = 4.0 ,
100
100
edgestrokec = colorant " lightgray" ,
101
101
edgelinewidth = 1.0 ,
102
- EDGELINEWIDTH = 3.0 / sqrt (nv (g)),
102
+ EDGELINEWIDTH = 3.0 / sqrt (nv (g)),
103
103
edgelabeldistx = 0.0 ,
104
104
edgelabeldisty = 0.0 ,
105
105
nodesize = 1.0 ,
106
- NODESIZE = 0.25 / sqrt (nv (g)),
106
+ NODESIZE = 0.25 / sqrt (nv (g)),
107
107
nodefillc = colorant " turquoise" ,
108
108
nodestrokec = nothing ,
109
109
nodestrokelw = 0.0 ,
110
110
arrowlengthfrac = is_directed (g) ? 0.1 : 0.0 ,
111
- arrowangleoffset = π/ 9.0 ,
111
+ arrowangleoffset = π / 9.0 ,
112
112
linetype = " straight" ,
113
113
outangle = pi / 5 ) where {T <: Integer , R <: Real }
114
114
@@ -122,14 +122,14 @@ function gplot(g::AbstractGraph{T},
122
122
error (" Must have one label per edge (or none)" )
123
123
end
124
124
125
- locs_x = deepcopy (locs_x_in)
126
- locs_y = deepcopy (locs_y_in)
125
+ locs_x = Float64 . (locs_x_in)
126
+ locs_y = Float64 . (locs_y_in)
127
127
128
128
# Scale to unit square
129
- min_x, max_x = minimum (locs_x), maximum (locs_x)
130
- min_y, max_y = minimum (locs_y), maximum (locs_y)
129
+ min_x, max_x = extrema (locs_x)
130
+ min_y, max_y = extrema (locs_y)
131
131
function scaler (z, a, b)
132
- 2.0 * ((z - a)/ (b - a)) - 1.0
132
+ 2.0 * ((z - a) / (b - a)) - 1.0
133
133
end
134
134
map! (z -> scaler (z, min_x, max_x), locs_x, locs_x)
135
135
map! (z -> scaler (z, min_y, max_y), locs_y, locs_y)
@@ -138,40 +138,40 @@ function gplot(g::AbstractGraph{T},
138
138
# NODESIZE = 0.25/sqrt(N)
139
139
# LINEWIDTH = 3.0/sqrt(N)
140
140
141
- max_nodesize = NODESIZE/ maximum (nodesize)
141
+ max_nodesize = NODESIZE / maximum (nodesize)
142
142
nodesize *= max_nodesize
143
- max_edgelinewidth = EDGELINEWIDTH/ maximum (edgelinewidth)
143
+ max_edgelinewidth = EDGELINEWIDTH / maximum (edgelinewidth)
144
144
edgelinewidth *= max_edgelinewidth
145
- max_edgelabelsize = EDGELABELSIZE/ maximum (edgelabelsize)
145
+ max_edgelabelsize = EDGELABELSIZE / maximum (edgelabelsize)
146
146
edgelabelsize *= max_edgelabelsize
147
- max_nodelabelsize = NODELABELSIZE/ maximum (nodelabelsize)
147
+ max_nodelabelsize = NODELABELSIZE / maximum (nodelabelsize)
148
148
nodelabelsize *= max_nodelabelsize
149
149
max_nodestrokelw = maximum (nodestrokelw)
150
150
if max_nodestrokelw > 0.0
151
- max_nodestrokelw = EDGELINEWIDTH/ max_nodestrokelw
151
+ max_nodestrokelw = EDGELINEWIDTH / max_nodestrokelw
152
152
nodestrokelw *= max_nodestrokelw
153
153
end
154
154
155
155
# Create nodes
156
156
nodecircle = fill (0.4 Compose. w, length (locs_x))
157
157
if isa (nodesize, Real)
158
- for i= 1 : length (locs_x)
159
- nodecircle[i] *= nodesize
160
- end
161
- else
162
- for i= 1 : length (locs_x)
163
- nodecircle[i] *= nodesize[i]
164
- end
165
- end
158
+ for i = 1 : length (locs_x)
159
+ nodecircle[i] *= nodesize
160
+ end
161
+ else
162
+ for i = 1 : length (locs_x)
163
+ nodecircle[i] *= nodesize[i]
164
+ end
165
+ end
166
166
nodes = circle (locs_x, locs_y, nodecircle)
167
167
168
168
# Create node labels if provided
169
169
texts = nothing
170
170
if nodelabel != nothing
171
171
text_locs_x = deepcopy (locs_x)
172
172
text_locs_y = deepcopy (locs_y)
173
- texts = text (text_locs_x .+ nodesize .* (nodelabeldist* cos (nodelabelangleoffset)),
174
- text_locs_y .- nodesize .* (nodelabeldist* sin (nodelabelangleoffset)),
173
+ texts = text (text_locs_x .+ nodesize .* (nodelabeldist * cos (nodelabelangleoffset)),
174
+ text_locs_y .- nodesize .* (nodelabeldist * sin (nodelabelangleoffset)),
175
175
map (string, nodelabel), [hcenter], [vcenter])
176
176
end
177
177
# Create edge labels if provided
@@ -182,17 +182,18 @@ function gplot(g::AbstractGraph{T},
182
182
for (e_idx, e) in enumerate (edges (g))
183
183
i = src (e)
184
184
j = dst (e)
185
- mid_x = (locs_x[i]+ locs_x[j])/ 2.0
186
- mid_y = (locs_y[i]+ locs_y[j])/ 2.0
187
- edge_locs_x[e_idx] = (is_directed (g) ? (mid_x+ locs_x[j])/ 2.0 : mid_x) + edgelabeldistx* NODESIZE
188
- edge_locs_y[e_idx] = (is_directed (g) ? (mid_y+ locs_y[j])/ 2.0 : mid_y) + edgelabeldisty* NODESIZE
185
+ mid_x = (locs_x[i]+ locs_x[j]) / 2.0
186
+ mid_y = (locs_y[i]+ locs_y[j]) / 2.0
187
+ edge_locs_x[e_idx] = (is_directed (g) ? (mid_x+ locs_x[j]) / 2.0 : mid_x) + edgelabeldistx * NODESIZE
188
+ edge_locs_y[e_idx] = (is_directed (g) ? (mid_y+ locs_y[j]) / 2.0 : mid_y) + edgelabeldisty * NODESIZE
189
+
189
190
end
190
191
edgetexts = text (edge_locs_x, edge_locs_y, map (string, edgelabel), [hcenter], [vcenter])
191
192
end
192
193
193
194
# Create lines and arrow heads
194
195
lines, arrows = nothing , nothing
195
- if linetype== " curve"
196
+ if linetype == " curve"
196
197
if arrowlengthfrac > 0.0
197
198
lines_cord, arrows_cord = graphcurve (g, locs_x, locs_y, nodesize, arrowlengthfrac, arrowangleoffset, outangle)
198
199
lines = path (lines_cord)
@@ -212,7 +213,7 @@ function gplot(g::AbstractGraph{T},
212
213
end
213
214
end
214
215
215
- compose (context (units= UnitBox (- 1.2 ,- 1.2 ,+ 2.4 ,+ 2.4 )),
216
+ compose (context (units= UnitBox (- 1.2 , - 1.2 , + 2.4 , + 2.4 )),
216
217
compose (context (), texts, fill (nodelabelc), stroke (nothing ), fontsize (nodelabelsize)),
217
218
compose (context (), nodes, fill (nodefillc), stroke (nodestrokec), linewidth (nodestrokelw)),
218
219
compose (context (), edgetexts, fill (edgelabelc), stroke (nothing ), fontsize (edgelabelsize)),
@@ -237,9 +238,9 @@ function open_file(filename)
237
238
end
238
239
end
239
240
240
- # take from [Gadfly.jl](https://github.com/dcjones/Gadfly.jl)
241
+ # taken from [Gadfly.jl](https://github.com/dcjones/Gadfly.jl)
241
242
function gplothtml (g; layout:: Function = spring_layout, keyargs... )
242
- filename = string (tempname (), " .html" )
243
+ filename = string (tempname (), " .html" )
243
244
output = open (filename, " w" )
244
245
245
246
plot_output = IOBuffer ()
0 commit comments