|
1 | 1 | # NetworkLayout.jl
|
2 | 2 | Layout algorithms for graphs and trees in pure Julia.
|
3 | 3 |
|
4 |
| -<!-- [](https://juliagraphs.org/NetworkLayout.jl/stable) --> |
5 |
| -<!-- [](https://juliagraphs.org/NetworkLayout.jl/dev/) --> |
| 4 | +[](https://juliagraphs.org/NetworkLayout.jl/stable) |
6 | 5 | [](https://github.com/JuliaGraphs/NetworkLayout.jl/actions)
|
7 | 6 | [](https://codecov.io/gh/JuliaGraphs/NetworkLayout.jl)
|
8 | 7 |
|
9 |
| -## Algorithms |
10 |
| - |
11 |
| -### Scalable Force Directed Placement |
12 |
| - |
13 |
| -Spring-Electric Force Directed Placement algorithm as explained in [Efficient and High Quality Force-Directed Graph Drawing](http://yifanhu.net/PUB/graph_draw_small.pdf) by Yifan Hu. |
14 |
| - |
15 |
| -Module Name : `SFDP` |
16 |
| - |
17 |
| -#### Usage |
18 |
| - |
19 |
| -```julia |
20 |
| -layout(adjacency_matrix,dimension;startpostitions,tol,C,K,iterations) |
21 |
| -``` |
22 |
| -##### arguments |
23 |
| - * `adjacency_matrix` - sparse/full adjacency matrix that represents the graph |
24 |
| - * `dimension` - dimension in which the layouting code has to be generated. `dimension` can be an integer specifying |
25 |
| - the dimension or a `Point` type, eg. `Point3f0` which denotes 3D. |
26 |
| - * `startpositions` - co-ordinates of the layout to start with. By default, a random layout is used (kwarg) |
27 |
| - * `tol` - permitted distance between current and calculated co-ordinate. Lower the tolerance, more the number of iterations (kwarg) |
28 |
| - * `C, K` - used to scale the layout (kwarg) |
29 |
| - * `iterations` - Number of iterations we apply the forces (kwarg) |
30 |
| - |
31 |
| -##### returns |
32 |
| - `positions` - co-ordinates of nodes in the layout |
33 |
| - |
34 |
| -##### iterator |
35 |
| - |
36 |
| -A user can move between iterations using a `Layout` object. |
37 |
| - |
38 |
| - |
39 |
| -#### Example |
40 |
| - |
41 |
| -```julia |
42 |
| -using LightGraphs |
43 |
| -using NetworkLayout:SFDP |
44 |
| -g = WheelGraph(10) |
45 |
| -a = adjacency_matrix(g) # generates a sparse adjacency matrix |
46 |
| -network = layout(a,Point2f0,tol=0.1,C=1,K=1,iterations=10) # generate 2D layout |
47 |
| -``` |
48 |
| -Using Iterator : |
49 |
| - |
50 |
| -```julia |
51 |
| -g = WheelGraph(10) |
52 |
| -a = adjacency_matrix(g) |
53 |
| -tol = 0.1 |
54 |
| -C = 0.2 |
55 |
| -K = 1 |
56 |
| -iterations = 100 |
57 |
| -network = Layout(a,locs,tol,C,K,iterations) |
58 |
| -state = start(network) |
59 |
| -while !done(network,state) |
60 |
| - network, state = next(network,state) |
61 |
| -end |
62 |
| -return network.positions |
63 |
| -``` |
64 |
| - |
65 |
| - |
66 |
| -The image shows a `LightGraphs.WheelGraph(10)` object layout generated by SFDP Algorithm. |
67 |
| - |
68 |
| -### Buchheim Tree Drawing |
69 |
| - |
70 |
| -Buchheim Tree Drawing as explained in [Improving Walker's Algorithm to Run in Linear Time](http://dirk.jivas.de/papers/buchheim02improving.pdf) by Christoph Buchheim, Michael Junger and Sebastian Leipert. |
71 |
| - |
72 |
| -Module Name : `Buchheim` |
73 |
| - |
74 |
| -#### Usage |
75 |
| - |
76 |
| -```julia |
77 |
| -layout(adjacency_list; nodesize) |
78 |
| -``` |
79 |
| - |
80 |
| -##### arguments |
81 |
| - * `adjacency_list` - adjacency list that represents the tree |
82 |
| - * `nodesize` - sizes of nodes (used to position the nodes) (kwarg) |
83 |
| - |
84 |
| -##### returns |
85 |
| - * `positions` - co-ordinates of the layout |
86 |
| - |
87 |
| -#### Example |
88 |
| - |
89 |
| -```julia |
90 |
| -using NetworkLayout:Buchheim |
91 |
| -adj_list = Vector{Int}[ # adjacency list |
92 |
| - [2,3,4], |
93 |
| - [5,6], |
94 |
| - [7], |
95 |
| - [], |
96 |
| - [], |
97 |
| - [], |
98 |
| - [] |
99 |
| - ] |
100 |
| - nodesize = [1,2.3,1.2,2,3,1.4,0.8] |
101 |
| - locs = layout(adj_list,nodesize=nodesize) # generating the layout for the tree |
102 |
| - ``` |
103 |
| -  |
104 |
| - |
105 |
| -The image shows a `LightGraphs.BinaryTree(4)` object layout by Buchheim Algorithm. |
106 |
| - |
107 |
| -### Spring/Repulsion Model |
108 |
| - |
109 |
| -Spring/Repulsion model of Fruchterman and Reingold (1991). Original code taken from [GraphLayout.jl](https://github.com/IainNZ/GraphLayout.jl) |
110 |
| - |
111 |
| -Module Name : `Spring` |
112 |
| - |
113 |
| -#### Usage |
114 |
| - |
115 |
| -```julia |
116 |
| -layout(adjacency_matrix,dimension;startpositions,C,iterations,initialtemp) |
117 |
| -``` |
118 |
| -##### arguments |
119 |
| - * `adjacency_matrix` - sparse/full adjacency matrix that represents the graph |
120 |
| - * `dimension` - dimension in which the layouting code has to be generated. `dimension` can be an integer specifying |
121 |
| - the dimension or a `Point` type, eg. `Point3f0` which denotes 3D. |
122 |
| - * `startpositions` - co-ordinates of the layout to start with. By default, a random layout is used (kwarg) |
123 |
| - * `iterations` - Number of iterations we apply the forces (kwarg) |
124 |
| - * `C` - Constant to fiddle with density of resulting layout (kwarg) |
125 |
| - * `initialtemp` - Initial "temperature", controls movement per iteration (kwarg) |
126 |
| - |
127 |
| -##### returns |
128 |
| - `positions` - co-ordinates of nodes in the layout |
129 |
| - |
130 |
| -##### iterator |
131 |
| - |
132 |
| -A user can move between iterations using a `Layout` object. |
133 |
| - |
134 |
| - |
135 |
| -#### Example |
136 |
| - |
137 |
| -```julia |
138 |
| -using LightGraphs |
139 |
| -using NetworkLayout:Spring |
140 |
| -g = WheelGraph(30) |
141 |
| -a = adjacency_matrix(g) # generates a sparse adjacency matrix |
142 |
| -network = layout(a,Point2f0,C=2.0,iterations=100,K=2.0) # generate 2D layout |
143 |
| -``` |
144 |
| -Using Iterator : |
145 |
| - |
146 |
| -```julia |
147 |
| -g = WheelGraph(30) |
148 |
| -a = adjacency_matrix(g) |
149 |
| -iterations = 200 |
150 |
| -C = 2.0 |
151 |
| -initialtemp = 2.0 |
152 |
| -network = Layout(a,locs,C,iterations,initialtemp) |
153 |
| -state = start(network) |
154 |
| -while !done(network,state) |
155 |
| - network, state = next(network,state) |
156 |
| -end |
157 |
| -return network.positions |
158 |
| -``` |
159 |
| - |
160 |
| - |
161 |
| -The image shows a `LightGraphs.WheelGraph(10)` object layout generated by Spring Algorithm. |
162 |
| - |
163 |
| -### Stress Majorization |
164 |
| - |
165 |
| -Based on the algorithm explained in "Graph Drawing by Stress Majorization" by Emden R Gansner, Yehuda Koren and Stephen North. Original code taken from [GraphLayout.jl](https://github.com/IainNZ/GraphLayout.jl) |
166 |
| - |
167 |
| -Module Name : `Stress` |
168 |
| - |
169 |
| -#### Usage |
170 |
| - |
171 |
| -```julia |
172 |
| -layout(δ,dimension;startpositions,weights,iterations,abstols,reltols,abstolx) |
173 |
| -``` |
174 |
| -##### arguments |
175 |
| - * `δ` - Matrix of pairwise distances (Adjacency Matrix can be used) |
176 |
| - * `dimension` - dimension in which the layouting code has to be generated. `dimension` can be an integer specifying |
177 |
| - the dimension or a `Point` type, eg. `Point3f0` which denotes 3D. |
178 |
| - * `weights` - Matrix of weights (kwarg) |
179 |
| - * `startpositions` - co-ordinates of the layout to start with. By default, a random layout is used (kwarg) |
180 |
| - * `iterations` - Number of iterations we apply the forces (kwarg) |
181 |
| - * `abstols` - Absolute tolerance for convergence of stress (kwarg) |
182 |
| - * `reltols` - Relative tolerance for convergence of stress (kwarg) |
183 |
| - * `abstolx` - Absolute tolerance for convergence of layout (kwarg) |
184 |
| - |
185 |
| -##### returns |
186 |
| - `positions` - co-ordinates of nodes in the layout |
187 |
| - |
188 |
| -##### iterator |
189 |
| - |
190 |
| -A user can move between iterations using a `Layout` object. |
191 |
| - |
192 |
| - |
193 |
| -#### Example |
194 |
| - |
195 |
| -```julia |
196 |
| -using LightGraphs |
197 |
| -using NetworkLayout:Stress |
198 |
| -g = CompleteGraph(10) |
199 |
| -a = adjacency_matrix(g) # generates a sparse adjacency matrix |
200 |
| -network = layout(a,2) # generate 2D layout |
201 |
| -``` |
202 |
| -Using Iterator : |
203 |
| - |
204 |
| -```julia |
205 |
| -g = CompleteGraph(10) |
206 |
| -δ = adjacency_matrix(g) |
207 |
| -startpositions=rand(Point{3, Float64}, size(δ,1)) |
208 |
| -iter = Layout(δ, Point{3,Float64}; startpositions=startpositions) |
209 |
| -state = start(iter) |
210 |
| -while !done(iter, state) |
211 |
| - iter, state = next(iter, state) |
212 |
| -end |
213 |
| -iter.positions |
214 |
| -``` |
215 |
| - |
216 |
| - |
217 |
| - |
218 |
| -The image shows a `LightGraphs.CompleteGraph(10)` object layout using Stress Algorithm. |
219 |
| - |
220 |
| -### Spectral Layout Algorithm |
221 |
| - |
222 |
| -Uses the technique of Spectral Graph Drawing, which is an under-appreciated method of graph layouts; easier, simpler, and faster than the more common spring-based methods. Original code taken from [PlotRecipes.jl](https://github.com/JuliaPlots/PlotRecipes.jl) |
223 |
| - |
224 |
| -Module Name : `Spectral` |
225 |
| - |
226 |
| -#### Usage |
227 |
| - |
228 |
| -```julia |
229 |
| -layout(adjacency_matrix; node_weights, kw...) |
230 |
| -``` |
231 |
| -##### arguments |
232 |
| - * `adjacency_matrix` - Adjacency Matrix in dense/sparse format |
233 |
| - * `node_weights` - weights for different nodes (kwarg) |
234 |
| - |
235 |
| -##### returns |
236 |
| - `positions` - co-ordinates of nodes in the layout |
237 |
| - |
238 |
| -#### Example |
239 |
| - |
240 |
| -```julia |
241 |
| -using LightGraphs |
242 |
| -using NetworkLayout:Spectral |
243 |
| -g = CompleteGraph(10) |
244 |
| -a = adjacency_matrix(g) # generates a sparse adjacency matrix |
245 |
| -network = layout(a) # generate 3D layout |
246 |
| -``` |
247 |
| - |
248 |
| - |
249 |
| -The image shows a `LightGraphs.CompleteGraph(10)` object layout by Spectral Algorithm. |
250 |
| - |
251 |
| -### Circular Layout Algorithm |
252 |
| - |
253 |
| -Position nodes on a circle. Original code taken from [GraphPlot.jl](https://github.com/afternone/GraphPlot.jl) |
254 |
| - |
255 |
| -Module Name : `Circular` |
256 |
| - |
257 |
| -#### Usage |
258 |
| - |
259 |
| -```julia |
260 |
| -layout(adjacency_matrix) |
| 8 | +## Installation |
| 9 | +``` julia |
| 10 | +pkg> add NetworkLayout.jl |
261 | 11 | ```
|
262 |
| -##### arguments |
263 |
| - * `adjacency_matrix` - Adjacency Matrix in dense/sparse format |
| 12 | +## Algorithms |
| 13 | +The available algorithms and their parameters can be found in the |
| 14 | +[docs](https://juliagraphs.org/NetworkLayout.jl/stable). |
264 | 15 |
|
265 |
| -##### returns |
266 |
| - `positions` - co-ordinates of nodes in the layout |
267 | 16 |
|
268 |
| -#### Example |
| 17 | +All of the algorithms represent mappings `adjacency matrix ↦ vector of |
| 18 | +positions` where the positions are represented by the `Point` datatype from |
| 19 | +[`GeometryBasics.jl](https://github.com/JuliaGeometry/GeometryBasics.jl) |
269 | 20 |
|
270 |
| -```julia |
| 21 | +``` julia |
| 22 | +using NetworkLayout |
271 | 23 | using LightGraphs
|
272 |
| -using NetworkLayout:Circular |
273 |
| -g = CompleteGraph(30) |
274 |
| -a = adjacency_matrix(g) # generates a sparse adjacency matrix |
275 |
| -network = layout(a) # generate 2D layout |
276 |
| -``` |
277 |
| - |
278 |
| - |
279 |
| - |
280 |
| -The image shows a `LightGraphs.CompleteGraph(10)` object layout using Circular Algorithm. |
281 |
| - |
282 |
| -### Shell Layout Algorithm |
283 |
| - |
284 |
| -Position nodes in concentric circles. Original code taken from [GraphPlot.jl](https://github.com/afternone/GraphPlot.jl) |
285 |
| - |
286 |
| -Module Name : `Shell` |
287 | 24 |
|
288 |
| -#### Usage |
| 25 | +adj_matrix = adjacency_matrix(wheel_graph(10)) |
289 | 26 |
|
290 |
| -```julia |
291 |
| -layout(adjacency_matrix;nlist) |
| 27 | +algorithm = NetworkLayout.Spring(; iterations=20) |
| 28 | +pos = algorithm(adj_matrix) |
292 | 29 | ```
|
293 |
| -##### arguments |
294 |
| - * `adjacency_matrix` - Adjacency Matrix in dense/sparse format |
295 |
| - * `nlist` - Shell-wise separation of nodes (kwarg) |
296 |
| - |
297 |
| -##### returns |
298 |
| - `positions` - co-ordinates of nodes in the layout |
299 |
| - |
300 |
| -#### Example |
301 |
| - |
302 |
| -```julia |
303 |
| -using LightGraphs |
304 |
| -using NetworkLayout:Shell |
305 |
| -g = CompleteGraph(30) |
306 |
| -n = Array(Vector{Int},2) |
307 |
| -n[1] = [1:15] |
308 |
| -n[2] = [16:30] |
309 |
| -a = adjacency_matrix(g) # generates a sparse adjacency matrix |
310 |
| -network = layout(a,nlist=n) # generate 2D layout |
311 |
| -``` |
312 |
| - |
313 |
| - |
314 |
| -This figure shows a `LightGraphs.CompleteGraph(30)` object in 2 shells. |
315 |
| - |
316 |
| -## Benchmarks |
317 |
| - |
318 |
| -The iterative algorithms have been benchmarked using 3 different graphs: `LightGraphs.WheelGraph(10)`, `LightGraphs.WheelGraph(100)` and `jagmesh1`. The number of iterations is fixed on 100. The following graph is obtained which shows SFDP to be the fastest in a general scenario, but Stress Algorithm is faster when the number of edges per graph is comparatively less, as in `jagmesh1`. |
319 |
| - |
320 |
| - |
321 |
| - |
322 |
| - |
323 |
| - |
324 |
| -*NOTE* : All screenshots are generated using [NetworkViz.jl](https://github.com/abhijithanilkumar/NetworkViz.jl), [ThreeJS.jl](https://github.com/rohitvarkey/ThreeJS.jl) and [Escher.jl](https://github.com/shashi/Escher.jlhttps://github.com/rohitvarkey/ThreeJS.jl). The plot used is generated using [Gadfly.jl](https://github.com/dcjones/Gadfly.jl) |
0 commit comments