Skip to content

Commit

Permalink
Merge pull request #17 from simonschoelly/fixes_for_v1.0
Browse files Browse the repository at this point in the history
Fixes for Julia version 0.7 and 1.0
  • Loading branch information
abhijithanilkumar authored Sep 7, 2018
2 parents 07f3960 + 06df354 commit 728e58e
Show file tree
Hide file tree
Showing 12 changed files with 231 additions and 202 deletions.
15 changes: 12 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,22 @@ language: julia
os:
- linux
- osx

julia:
- 0.6
- 0.7
- 1.0
- nightly

matrix:
allow_failures:
- julia: nightly

notifications:
email: false

# uncomment the following lines to override the default test script
script:
- if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
- julia -e 'Pkg.clone(pwd()); Pkg.build("NetworkLayout"); Pkg.checkout("GeometryTypes"); Pkg.clone("LightGraphs"); Pkg.test("NetworkLayout"; coverage=true)'
- julia -e 'using Pkg; Pkg.clone(pwd()); Pkg.build("NetworkLayout"); Pkg.clone("LightGraphs"); Pkg.test("NetworkLayout"; coverage=true)'
after_success:
- julia -e 'cd(Pkg.dir("NetworkLayout")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(process_folder()); Codecov.submit(process_folder())'
- julia -e 'using Pkg; cd(Pkg.dir("NetworkLayout")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(process_folder()); Codecov.submit(process_folder())'
4 changes: 1 addition & 3 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
julia 0.6-
julia 0.7
GeometryTypes
Compat 0.8.6
StaticArrays
37 changes: 23 additions & 14 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
environment:
matrix:
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.6/julia-0.6-latest-win32.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.6/julia-0.6-latest-win64.exe"
#- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe"
#- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"
- julia_version: 0.7
- julia_version: 1
- julia_version: nightly

platform:
- x86 # 32-bit
- x64 # 64-bit

# # Uncomment the following lines to allow failures on nightly julia
# # (tests will run but not make your overall status red)
#matrix:
# allow_failures:
# - julia_version: nightly

branches:
only:
Expand All @@ -17,19 +26,19 @@ notifications:
on_build_status_changed: false

install:
- ps: "[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12"
# Download most recent Julia Windows binary
- ps: (new-object net.webclient).DownloadFile(
$env:JULIA_URL,
"C:\projects\julia-binary.exe")
# Run installer silently, output to C:\projects\julia
- C:\projects\julia-binary.exe /S /D=C:\projects\julia
- ps: iex ((new-object net.webclient).DownloadString("https://raw.githubusercontent.com/JuliaCI/Appveyor.jl/version-1/bin/install.ps1"))

build_script:
# Need to convert from shallow to complete for Pkg.clone to work
- IF EXIST .git\shallow (git fetch --unshallow)
- C:\projects\julia\bin\julia -e "versioninfo();
Pkg.clone(pwd(), \"NetworkLayout\"); Pkg.build(\"NetworkLayout\"); Pkg.checkout(\"GeometryTypes\")"
- C:\julia\bin\julia -e "using InteractiveUtils, Pkg; versioninfo();
Pkg.clone(pwd(), \"NetworkLayout\"); Pkg.build(\"NetworkLayout\")"

test_script:
- C:\projects\julia\bin\julia --check-bounds=yes -e "Pkg.test(\"NetworkLayout\")"
- C:\julia\bin\julia -e "using Pkg; Pkg.test(\"NetworkLayout\")"

# # Uncomment to support code coverage upload. Should only be enabled for packages
# # which would have coverage gaps without running on Windows
# on_success:
# - echo "%JL_CODECOV_SCRIPT%"
# - C:\julia\bin\julia -e "%JL_CODECOV_SCRIPT%"
108 changes: 54 additions & 54 deletions src/buchheim.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ tree Adjacency List that represents the given tree
Returns
positions co-ordinates of the layout
"""

module Buchheim

using GeometryTypes

immutable Tree{A<:AbstractVector,P<:AbstractVector,F}
struct Tree{A<:AbstractVector,P<:AbstractVector,F}
nodes::A
mod::F
thread::Vector{Int}
Expand All @@ -27,49 +26,50 @@ immutable Tree{A<:AbstractVector,P<:AbstractVector,F}
nodesize::F
end

function Tree{T}(tree::AbstractVector{T}, nodesize)
mod = zeros(length(tree))
thread = zeros(Int,length(tree))
prelim = zeros(length(tree))
shift = zeros(length(tree))
change = zeros(length(tree))
ancestor = [i for i in 1:length(tree)]
function Tree(tree::AbstractVector, nodesize)
len = length(tree)
mod = zeros(len)
thread = zeros(Int, len)
prelim = zeros(len)
shift = zeros(len)
change = zeros(len)
ancestor = collect(1:len)
nodes = copy(tree)
positions = zeros(Point{2,Float64},length(tree))
t = Tree(nodes,mod,thread,ancestor,prelim,shift,change,positions,nodesize)
positions = zeros(Point{2,Float64}, len)
t = Tree(nodes, mod, thread, ancestor, prelim, shift, change, positions, nodesize)
return t
end

function layout{T}(t::AbstractVector{T}; nodesize=ones(length(t)))
layout!(t,nodesize)
function layout(t::AbstractVector; nodesize=ones(length(t)))
layout!(t, nodesize)
end

function layout!{T}(t::AbstractVector{T}, nodesize)
tree = Tree(t,nodesize)
first_walk(1,tree)
second_walk(1,-tree.prelim[1],0.0,tree)
function layout!(t::AbstractVector, nodesize)
tree = Tree(t, nodesize)
first_walk(1, tree)
second_walk(1, -tree.prelim[1], 0.0, tree)
return tree.positions
end

function parent{T}(v::T,t::Tree)
function parent(v, t::Tree)
tree = t.nodes
for i in 1:length(tree)
y = find(x->(x==v),tree[i])
if length(y)!=0
y = findall(x -> (x==v), tree[i])
if length(y) != 0
return i
end
end
return nothing
end

function first_walk{T}(v::T,t::Tree)
function first_walk(v, t::Tree)
prelim = t.prelim
mod = t.mod
tree = t.nodes
nodesize = t.nodesize
p = parent(v,t)
if p != nothing
index = find(x->(x==v),tree[p])[1]
index = findall(x -> (x==v), tree[p])[1]
else
index = 1
end
Expand All @@ -83,51 +83,51 @@ function first_walk{T}(v::T,t::Tree)
defaultAncestor = tree[v][1]
for w in tree[v]
first_walk(w,t)
defaultAncestor = apportion(w,defaultAncestor,t)
defaultAncestor = apportion(w, defaultAncestor, t)
end
execute_shifts(v,t)
execute_shifts(v, t)
midpoint = (prelim[tree[v][1]] + prelim[tree[v][end]]) / 2
if index > 1
w = tree[p][index-1]
prelim[v] = prelim[w] + (nodesize[w]+1.0)
prelim[v] = prelim[w] + (nodesize[w] + 1.0)
mod[v] = prelim[v] - midpoint
else
prelim[v] = midpoint
end
end
end

function apportion{T}(v::T,defaultAncestor::T,t::Tree)
function apportion(v::T, defaultAncestor::T, t::Tree) where {T}
tree = t.nodes
ancestor = t.ancestor
prelim = t.prelim
mod = t.mod
thread = t.thread
p = parent(v,t)
p = parent(v, t)
nodesize = t.nodesize
if p != nothing
index = find(x->(x==v),tree[p])[1]
index = findall(x-> (x==v), tree[p])[1]
else
index = 1
end
if index > 1
w = tree[p][index-1]
v_in_right = v_out_right = v
v_in_left = w
v_out_left = tree[parent(v_in_right,t)][1]
v_out_left = tree[parent(v_in_right, t)][1]
s_in_right = mod[v_in_right]
s_out_right = mod[v_out_right]
s_in_left = mod[v_in_left]
s_out_left = mod[v_out_left]
while next_right(v_in_left,t)!=0 && next_left(v_in_right,t)!=0
v_in_left = next_right(v_in_left,t)
v_in_right = next_left(v_in_right,t)
v_out_left = next_left(v_out_left,t)
v_out_right = next_right(v_out_right,t)
while next_right(v_in_left, t)!=0 && next_left(v_in_right, t)!=0
v_in_left = next_right(v_in_left, t)
v_in_right = next_left(v_in_right, t)
v_out_left = next_left(v_out_left, t)
v_out_right = next_right(v_out_right, t)
ancestor[v_out_right] = v
shift = (prelim[v_in_left] + s_in_left) - (prelim[v_in_right] + s_in_right) + (nodesize[v_in_left])
if shift > 0
move_subtree(find_ancestor(v_in_left,v,defaultAncestor,t),v,shift,t)
move_subtree(find_ancestor(v_in_left, v, defaultAncestor,t), v,shift, t)
s_in_right += shift
s_out_right += shift
end
Expand All @@ -136,12 +136,12 @@ function apportion{T}(v::T,defaultAncestor::T,t::Tree)
s_out_left += mod[v_out_left]
s_out_right += mod[v_out_right]
end
if next_right(v_in_left,t)!=0 && next_right(v_out_right,t)==0
thread[v_out_right] = next_right(v_in_left,t)
if next_right(v_in_left, t) != 0 && next_right(v_out_right, t) == 0
thread[v_out_right] = next_right(v_in_left, t)
mod[v_out_right] += s_in_left - s_out_right
else
if next_left(v_in_right,t)!=0 next_left(v_out_left,t)==0
thread[v_out_left] = next_left(v_in_right,t)
if next_left(v_in_right,t) != 0 && next_left(v_out_left,t) == 0
thread[v_out_left] = next_left(v_in_right, t)
mod[v_out_left] += s_in_right - s_out_left
defaultAncestor = v
end
Expand All @@ -150,20 +150,20 @@ function apportion{T}(v::T,defaultAncestor::T,t::Tree)
return defaultAncestor
end

function number{T}(v::T,t::Tree)
p = parent(v,t)
index = find(x->(x==v),t.nodes[p])[1]
function number(v, t::Tree)
p = parent(v, t)
index = findall(x -> (x==v), t.nodes[p])[1]
return index
end

function move_subtree{T}(w_left::T,w_right::T,shift::Float64,t::Tree)
function move_subtree(w_left::T, w_right::T, shift::Float64, t::Tree) where {T}
change = t.change
prelim = t.prelim
tree = t.nodes
shifttree = t.shift
mod = t.mod
n_wl = number(w_left,t)
n_wr = number(w_right,t)
n_wl = number(w_left, t)
n_wr = number(w_right, t)
subtrees = n_wr - n_wl
change[w_right] -= shift / subtrees
shifttree[w_right] += shift
Expand All @@ -172,32 +172,32 @@ function move_subtree{T}(w_left::T,w_right::T,shift::Float64,t::Tree)
mod[w_right] += shift
end

function second_walk{T}(v::T,m::Float64,depth::Float64,t::Tree)
function second_walk(v, m::Float64, depth::Float64, t::Tree)
prelim = t.prelim
mod = t.mod
positions = t.positions
nodesize = t.nodesize
positions[v] = Point(prelim[v]+m,-depth)
if length(t.nodes[v])!=0
positions[v] = Point(prelim[v]+m, -depth)
if length(t.nodes[v]) != 0
maxdist = maximum([nodesize[i] for i in t.nodes[v]])
else
maxdist = 0
end
for w in t.nodes[v]
second_walk(w,m+mod[v],Float64(depth+1+maxdist),t)
second_walk(w, m+mod[v], Float64(depth + 1 + maxdist), t)
end
end

function find_ancestor{T}(w::T,v::T,defaultAncestor::T,tree::Tree)
function find_ancestor(w::T, v::T, defaultAncestor::T, tree::Tree) where {T}
ancestor = tree.ancestor
if ancestor[w] in tree.nodes[parent(v,tree)]
if ancestor[w] in tree.nodes[parent(v, tree)]
return ancestor[w]
else
return defaultAncestor
end
end

function execute_shifts{T}(v::T,t::Tree)
function execute_shifts(v, t::Tree)
tree = t.nodes
shift = t.shift
change = t.change
Expand All @@ -213,7 +213,7 @@ function execute_shifts{T}(v::T,t::Tree)
end
end

function next_left{T}(v::T,t::Tree)
function next_left(v, t::Tree)
tree = t.nodes
thread = t.thread
if length(tree[v]) != 0
Expand All @@ -223,7 +223,7 @@ function next_left{T}(v::T,t::Tree)
end
end

function next_right{T}(v::T,t::Tree)
function next_right(v, t::Tree)
tree = t.nodes
thread = t.thread
if length(tree[v]) != 0
Expand Down
9 changes: 4 additions & 5 deletions src/circular.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,20 @@ julia> g = simple_house_graph()
julia> locs_x, locs_y = circular_layout(g)
```
"""

module Circular

using GeometryTypes

function layout{M<:AbstractMatrix}(adj_matrix::M)
function layout(adj_matrix::AbstractMatrix)
layout!(adj_matrix)
end

function layout!{M<:AbstractMatrix}(adj_matrix::M)
function layout!(adj_matrix::AbstractMatrix)
if size(adj_matrix,1) == 1
return Point{2,Float64}[Point(0.0,0.0)]
return Point{2,Float64}[Point(0.0, 0.0)]
else
# Discard the extra angle since it matches 0 radians.
θ = linspace(0, 2pi, size(adj_matrix,1) + 1)[1:end-1]
θ = range(0, stop=2pi, length=size(adj_matrix,1) + 1)[1:end-1]
return Point{2,Float64}[(cos(o), sin(o)) for o in θ]
end
end
Expand Down
Loading

0 comments on commit 728e58e

Please sign in to comment.