Skip to content

Commit 43e1df9

Browse files
committed
use Requires.jl to define layout for AbstractGraph
1 parent 0fa0209 commit 43e1df9

File tree

6 files changed

+19
-6
lines changed

6 files changed

+19
-6
lines changed

Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ version = "0.4.0"
55
[deps]
66
GeometryBasics = "5c1252a2-5f33-56bf-86c9-59e7332b4326"
77
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
8+
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
89
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
910

1011
[compat]

src/NetworkLayout.jl

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
module NetworkLayout
22

3-
export LayoutIterator, layout
4-
53
using GeometryBasics
4+
using Requires
65
using LinearAlgebra: norm
76

7+
export LayoutIterator, layout
8+
89
"""
910
AbstractLayout{Dim,Ptype}
1011
@@ -66,7 +67,7 @@ struct LayoutIterator{T<:IterativeLayout,M<:AbstractMatrix}
6667
adj_matrix::M
6768
end
6869

69-
function layout(alg::IterativeLayout, adj_matrix)
70+
function layout(alg::IterativeLayout, adj_matrix::AbstractMatrix)
7071
iter = LayoutIterator(alg, adj_matrix)
7172
next = Base.iterate(iter)
7273
pos = next[1]
@@ -78,6 +79,10 @@ function layout(alg::IterativeLayout, adj_matrix)
7879
return pos
7980
end
8081

82+
function __init__()
83+
@require LightGraphs="093fc24a-ae57-5d10-9952-331d41423f4d" layout(l::AbstractLayout, g::LightGraphs.AbstractGraph) = layout(l, LightGraphs.adjacency_matrix(g))
84+
end
85+
8186
include("sfdp.jl")
8287
include("buchheim.jl")
8388
include("spring.jl")

src/circular.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ struct Circular{Ptype} <: AbstractLayout{2,Ptype} end
1616

1717
Circular(; Ptype=Float64) = Circular{Ptype}()
1818

19-
function layout(::Circular{Ptype}, adj_matrix) where {Ptype}
19+
function layout(::Circular{Ptype}, adj_matrix::AbstractMatrix) where {Ptype}
2020
if size(adj_matrix, 1) == 1
2121
return Point{2,Ptype}[Point(0.0, 0.0)]
2222
else

src/shell.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ end
2525

2626
Shell(; Ptype=Float64, nlist=Vector{Int}[]) = Shell{Ptype}(nlist)
2727

28-
function layout(algo::Shell{Ptype}, adj_matrix) where {Ptype}
28+
function layout(algo::Shell{Ptype}, adj_matrix::AbstractMatrix) where {Ptype}
2929
if size(adj_matrix, 1) == 1
3030
return Point{2,Float64}[Point(0.0, 0.0)]
3131
end

src/spectral.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ function compute_laplacian(adj_matrix, node_weights)
5555
return L, D
5656
end
5757

58-
function layout(algo::Spectral{Ptype,FT}, adj_matrix) where {Ptype,FT}
58+
function layout(algo::Spectral{Ptype,FT}, adj_matrix::AbstractMatrix) where {Ptype,FT}
5959
# try to use user provided nodeweights
6060
nodeweights = if length(algo.nodeweights) == size(adj_matrix, 1)
6161
algo.nodeweights

test/runtests.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,4 +274,11 @@ jagmesh_adj = jagmesh()
274274
@test positions == Point2.([(1, 0), (2, 0), (0, -1), (2, -1)])
275275
end
276276
end
277+
278+
@testset "test LightGraphs glue code" begin
279+
println("Test LightGraphs glue code")
280+
g = complete_graph(10)
281+
pos = Spring()(g)
282+
@test pos isa Vector{Point{2,Float64}}
283+
end
277284
end

0 commit comments

Comments
 (0)