@@ -92,23 +92,23 @@ function gplot(g::AbstractGraph{T},
9292 nodelabelsize = 1.0 ,
9393 NODELABELSIZE = 4.0 ,
9494 nodelabeldist = 0.0 ,
95- nodelabelangleoffset = π/ 4.0 ,
95+ nodelabelangleoffset = π / 4.0 ,
9696 edgelabel = [],
9797 edgelabelc = colorant " black" ,
9898 edgelabelsize = 1.0 ,
9999 EDGELABELSIZE = 4.0 ,
100100 edgestrokec = colorant " lightgray" ,
101101 edgelinewidth = 1.0 ,
102- EDGELINEWIDTH = 3.0 / sqrt (nv (g)),
102+ EDGELINEWIDTH = 3.0 / sqrt (nv (g)),
103103 edgelabeldistx = 0.0 ,
104104 edgelabeldisty = 0.0 ,
105105 nodesize = 1.0 ,
106- NODESIZE = 0.25 / sqrt (nv (g)),
106+ NODESIZE = 0.25 / sqrt (nv (g)),
107107 nodefillc = colorant " turquoise" ,
108108 nodestrokec = nothing ,
109109 nodestrokelw = 0.0 ,
110110 arrowlengthfrac = is_directed (g) ? 0.1 : 0.0 ,
111- arrowangleoffset = π/ 9.0 ,
111+ arrowangleoffset = π / 9.0 ,
112112 linetype = " straight" ,
113113 outangle = pi / 5 ) where {T <: Integer , R <: Real }
114114
@@ -122,14 +122,14 @@ function gplot(g::AbstractGraph{T},
122122 error (" Must have one label per edge (or none)" )
123123 end
124124
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)
127127
128128 # 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)
131131 function scaler (z, a, b)
132- 2.0 * ((z - a)/ (b - a)) - 1.0
132+ 2.0 * ((z - a) / (b - a)) - 1.0
133133 end
134134 map! (z -> scaler (z, min_x, max_x), locs_x, locs_x)
135135 map! (z -> scaler (z, min_y, max_y), locs_y, locs_y)
@@ -138,40 +138,40 @@ function gplot(g::AbstractGraph{T},
138138 # NODESIZE = 0.25/sqrt(N)
139139 # LINEWIDTH = 3.0/sqrt(N)
140140
141- max_nodesize = NODESIZE/ maximum (nodesize)
141+ max_nodesize = NODESIZE / maximum (nodesize)
142142 nodesize *= max_nodesize
143- max_edgelinewidth = EDGELINEWIDTH/ maximum (edgelinewidth)
143+ max_edgelinewidth = EDGELINEWIDTH / maximum (edgelinewidth)
144144 edgelinewidth *= max_edgelinewidth
145- max_edgelabelsize = EDGELABELSIZE/ maximum (edgelabelsize)
145+ max_edgelabelsize = EDGELABELSIZE / maximum (edgelabelsize)
146146 edgelabelsize *= max_edgelabelsize
147- max_nodelabelsize = NODELABELSIZE/ maximum (nodelabelsize)
147+ max_nodelabelsize = NODELABELSIZE / maximum (nodelabelsize)
148148 nodelabelsize *= max_nodelabelsize
149149 max_nodestrokelw = maximum (nodestrokelw)
150150 if max_nodestrokelw > 0.0
151- max_nodestrokelw = EDGELINEWIDTH/ max_nodestrokelw
151+ max_nodestrokelw = EDGELINEWIDTH / max_nodestrokelw
152152 nodestrokelw *= max_nodestrokelw
153153 end
154154
155155 # Create nodes
156156 nodecircle = fill (0.4 Compose. w, length (locs_x))
157157 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
166166 nodes = circle (locs_x, locs_y, nodecircle)
167167
168168 # Create node labels if provided
169169 texts = nothing
170170 if nodelabel != nothing
171171 text_locs_x = deepcopy (locs_x)
172172 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)),
175175 map (string, nodelabel), [hcenter], [vcenter])
176176 end
177177 # Create edge labels if provided
@@ -182,17 +182,18 @@ function gplot(g::AbstractGraph{T},
182182 for (e_idx, e) in enumerate (edges (g))
183183 i = src (e)
184184 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+
189190 end
190191 edgetexts = text (edge_locs_x, edge_locs_y, map (string, edgelabel), [hcenter], [vcenter])
191192 end
192193
193194 # Create lines and arrow heads
194195 lines, arrows = nothing , nothing
195- if linetype== " curve"
196+ if linetype == " curve"
196197 if arrowlengthfrac > 0.0
197198 lines_cord, arrows_cord = graphcurve (g, locs_x, locs_y, nodesize, arrowlengthfrac, arrowangleoffset, outangle)
198199 lines = path (lines_cord)
@@ -212,7 +213,7 @@ function gplot(g::AbstractGraph{T},
212213 end
213214 end
214215
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 )),
216217 compose (context (), texts, fill (nodelabelc), stroke (nothing ), fontsize (nodelabelsize)),
217218 compose (context (), nodes, fill (nodefillc), stroke (nodestrokec), linewidth (nodestrokelw)),
218219 compose (context (), edgetexts, fill (edgelabelc), stroke (nothing ), fontsize (edgelabelsize)),
@@ -237,9 +238,9 @@ function open_file(filename)
237238 end
238239end
239240
240- # take from [Gadfly.jl](https://github.com/dcjones/Gadfly.jl)
241+ # taken from [Gadfly.jl](https://github.com/dcjones/Gadfly.jl)
241242function gplothtml (g; layout:: Function = spring_layout, keyargs... )
242- filename = string (tempname (), " .html" )
243+ filename = string (tempname (), " .html" )
243244 output = open (filename, " w" )
244245
245246 plot_output = IOBuffer ()
0 commit comments