Skip to content

Commit 3cfeeef

Browse files
authored
Merge pull request #27 from JuliaGraphs/interface
type-based interface
2 parents 00491f9 + 26ce7d3 commit 3cfeeef

19 files changed

+989
-695
lines changed

.JuliaFormatter.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
always_for_in = true
2-
always_use_return = true
2+
always_use_return = false
33
import_to_using = true
44
margin = 110
55
pipe_to_function_call = true

.github/workflows/CI.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ jobs:
4848
- run: |
4949
julia --project=docs -e '
5050
using Pkg
51+
# XXX: temp solution to resolve deps
52+
Pkg.add(url="https://github.com/JuliaPlots/GraphMakie.jl", rev="f9b8c18")
5153
Pkg.develop(PackageSpec(path=pwd()))
5254
Pkg.instantiate()'
5355
- run: |

.travis.yml

Lines changed: 0 additions & 15 deletions
This file was deleted.

Project.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
name = "NetworkLayout"
22
uuid = "46757867-2c16-5918-afeb-47bfcb05e46a"
3-
version = "0.3.0"
3+
version = "0.4.0"
44

55
[deps]
66
GeometryBasics = "5c1252a2-5f33-56bf-86c9-59e7332b4326"
77
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
8+
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
9+
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
810
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
911

1012
[compat]
11-
julia = "1"
1213
GeometryBasics = "0.3"
14+
julia = "1"
1315

1416
[extras]
1517
DelimitedFiles = "8bb1440f-4735-579b-a4ab-409b98df4dab"

README.md

Lines changed: 15 additions & 310 deletions
Original file line numberDiff line numberDiff line change
@@ -1,324 +1,29 @@
11
# NetworkLayout.jl
22
Layout algorithms for graphs and trees in pure Julia.
33

4-
<!-- [![Stable](https://img.shields.io/badge/docs-stable-blue.svg)](https://juliagraphs.org/NetworkLayout.jl/stable) -->
5-
<!-- [![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://juliagraphs.org/NetworkLayout.jl/dev/) -->
4+
[![Stable](https://img.shields.io/badge/docs-stable-blue.svg)](https://juliagraphs.org/NetworkLayout.jl/stable)
65
[![Build Status](https://github.com/JuliaGraphs/NetworkLayout.jl/workflows/CI/badge.svg)](https://github.com/JuliaGraphs/NetworkLayout.jl/actions)
76
[![Coverage](https://codecov.io/gh/JuliaGraphs/NetworkLayout.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/JuliaGraphs/NetworkLayout.jl)
87

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-
![sfdp](https://cloud.githubusercontent.com/assets/8404278/17638280/a9671850-6106-11e6-912f-be94477f5ecd.png)
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-
![tree](https://cloud.githubusercontent.com/assets/8404278/17638844/afd280a4-610a-11e6-8fea-5c99808bd740.png)
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-
![spring](https://cloud.githubusercontent.com/assets/8404278/17638354/1c20cc56-6107-11e6-82ed-8873431d8d33.png)
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-
![stress](https://cloud.githubusercontent.com/assets/8404278/17638554/5e65e26c-6108-11e6-9522-30e6fa044d26.png)
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-
![spectral](https://cloud.githubusercontent.com/assets/8404278/17638718/a0b451ca-6109-11e6-9a66-fd22332b8541.png)
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
26111
```
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).
26415

265-
##### returns
266-
`positions` - co-ordinates of nodes in the layout
26716

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)
26920

270-
```julia
21+
``` julia
22+
using NetworkLayout
27123
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-
![circular](https://cloud.githubusercontent.com/assets/8404278/17638609/d8eb4428-6108-11e6-934b-f326f07cf044.png)
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`
28724

288-
#### Usage
25+
adj_matrix = adjacency_matrix(wheel_graph(10))
28926

290-
```julia
291-
layout(adjacency_matrix;nlist)
27+
algorithm = NetworkLayout.Spring(; iterations=20)
28+
pos = algorithm(adj_matrix)
29229
```
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-
![shell](https://cloud.githubusercontent.com/assets/8404278/17638171/efac921e-6105-11e6-9e48-33471bf3b27e.png)
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-
![bench](https://cloud.githubusercontent.com/assets/8404278/17642254/fd6f1718-615b-11e6-9a30-8c1a362aead7.png)
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)

docs/Project.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
[deps]
2+
CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
23
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
4+
GraphMakie = "1ecd5474-83a3-4783-bb4f-06765db800d2"
5+
LightGraphs = "093fc24a-ae57-5d10-9952-331d41423f4d"
36
NetworkLayout = "46757867-2c16-5918-afeb-47bfcb05e46a"
7+
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"

0 commit comments

Comments
 (0)