Skip to content
This repository has been archived by the owner on May 25, 2020. It is now read-only.

Commit

Permalink
Julia 0.4 only
Browse files Browse the repository at this point in the history
  • Loading branch information
IainNZ committed Dec 5, 2015
1 parent bcaf380 commit 3d0a422
Show file tree
Hide file tree
Showing 24 changed files with 3,462 additions and 2,493 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.DS_Store
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ language: julia
os:
- linux
julia:
- release
- 0.4
- nightly
notifications:
email: false
Expand All @@ -12,4 +12,4 @@ script:
- julia -e 'Pkg.clone(pwd()); Pkg.build("GraphLayout")'
- julia -e 'Pkg.test("GraphLayout"; coverage=true)'
after_success:
- julia -e 'cd(Pkg.dir("GraphLayout")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())'
- julia -e 'cd(Pkg.dir("GraphLayout")); Pkg.add("Coverage"); using Coverage; Codecov.submit(process_folder())'
4 changes: 2 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2014 Iain Dunning
Copyright (c) 2015 Iain Dunning

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
SOFTWARE.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ Graph layout and visualization algorithms, implemented in Julia.

[![GraphLayout](http://pkg.julialang.org/badges/GraphLayout_0.3.svg)](http://pkg.julialang.org/?pkg=GraphLayout&ver=0.3)
[![GraphLayout](http://pkg.julialang.org/badges/GraphLayout_0.4.svg)](http://pkg.julialang.org/?pkg=GraphLayout&ver=0.4)
[![GraphLayout](http://pkg.julialang.org/badges/GraphLayout_0.4.svg)](http://pkg.julialang.org/?pkg=GraphLayout&ver=0.5)

**Development version**:
[![Build Status](https://travis-ci.org/IainNZ/GraphLayout.jl.svg)](https://travis-ci.org/IainNZ/GraphLayout.jl)
[![Coverage Status](https://img.shields.io/coveralls/IainNZ/GraphLayout.jl.svg)](https://coveralls.io/r/IainNZ/GraphLayout.jl)
**Development version**:
[![Build Status](https://travis-ci.org/IainNZ/GraphLayout.jl.svg?branch=master)](https://travis-ci.org/IainNZ/GraphLayout.jl)
[![codecov.io](https://codecov.io/github/IainNZ/GraphLayout.jl/coverage.svg?branch=master)](https://codecov.io/github/IainNZ/GraphLayout.jl?branch=master)


The package currently implements the following layout methods:
Expand Down
6 changes: 2 additions & 4 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
julia 0.3
Docile
julia 0.4
Requires
Compose
Compat
Compose 0.4
11 changes: 3 additions & 8 deletions src/GraphLayout.jl
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@

VERSION >= v"0.4.0" && __precompile__(true)
__precompile__(true)

module GraphLayout
if VERSION < v"0.4.0"
using Docile
end
using Requires # to optionally load JuMP
using Compose # for plotting features
using Compat # for v0.3 compatibility
using Compose # for plotting features

typealias AdjList{T} Vector{Vector{T}}

Expand All @@ -26,7 +21,7 @@ module GraphLayout
include("tree_heur.jl")
# Optimal algorithms for tree layout, that require JuMP
# These methods will be loaded when JuMP is loaded
_ordering_ip(args...) =
_ordering_ip(args...) =
error("JuMP package must be loaded for optimization tree layout")
@require JuMP include("tree_opt.jl")

Expand Down
16 changes: 7 additions & 9 deletions src/draw.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using Compose
import Colors
@compat typealias ComposeColor Union{Colors.Color,
Colors.AlphaColor,
Colors.AbstractString}
typealias ComposeColor Union{Colors.Color,
Colors.AlphaColor,
Colors.AbstractString}

@doc """
"""
Given an adjacency matrix and two vectors of X and Y coordinates, returns
a Compose tree of the graph layout
Expand All @@ -22,7 +22,7 @@ Arguments:
Set to 0 for no arrows. Default: 0.1
angleoffset angular width in radians for the arrows. Default: π/9 (20 degrees).
""" ->
"""
function compose_layout_adj{S, T<:Real}(
adj_matrix::Array{S,2},
locs_x::Vector{T}, locs_y::Vector{T};
Expand Down Expand Up @@ -113,12 +113,10 @@ function lineij(locs_x, locs_y, i, j, NODESIZE, ARROWLENGTH, angleoffset)
return composenode
end

@doc """
"""
Given an adjacency matrix and two vectors of X and Y coordinates, returns
an SVG of the graph layout.
Requires Compose.jl
Arguments:
adj_matrix Adjacency matrix of some type. Non-zero of the eltype
of the matrix is used to determine if a link exists,
Expand All @@ -134,7 +132,7 @@ Arguments:
arrowlengthfrac Fraction of line length to use for arrows.
Set to 0 for no arrows. Default: 0.1
angleoffset angular width in radians for the arrows. Default: π/9 (20 degrees).
""" ->
"""
function draw_layout_adj{S, T<:Real}(
adj_matrix::Array{S,2},
locs_x::Vector{T}, locs_y::Vector{T};
Expand Down
4 changes: 2 additions & 2 deletions src/spring.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@doc """
"""
Use the spring/repulsion model of Fruchterman and Reingold (1991):
Attractive force: f_a(d) = d^2 / k
Repulsive force: f_r(d) = -k^2 / d
Expand All @@ -13,7 +13,7 @@
C Constant to fiddle with density of resulting layout
MAXITER Number of iterations we apply the forces
INITTEMP Initial "temperature", controls movement per iteration
""" ->
"""
function layout_spring_adj{T}(adj_matrix::Array{T,2}; C=2.0, MAXITER=100, INITTEMP=2.0)

size(adj_matrix, 1) != size(adj_matrix, 2) && error("Adj. matrix must be square.")
Expand Down
6 changes: 2 additions & 4 deletions src/stress.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@doc """
"""
Compute graph layout using stress majorization
Inputs:
Expand Down Expand Up @@ -51,7 +51,7 @@ Reference:
publisher={Springer Berlin Heidelberg},
pages={239--250},
}
""" ->
"""
function layout_stressmajorize_adj(δ, p::Int=2, w=nothing, X0=randn(size(δ, 1), p);
maxiter = 400size(X0, 1)^2, abstols=(eps(eltype(X0))),
reltols=(eps(eltype(X0))), abstolx=(eps(eltype(X0))),
Expand Down Expand Up @@ -162,5 +162,3 @@ function LZ(Z, d, w)
@assert all(isfinite(L))
L
end


19 changes: 5 additions & 14 deletions src/tree.jl
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
# Uses a macro to switch between .abs and .value depending on Compose version
macro raw_measure(m)
if Pkg.installed("Compose") > v"0.3.18"
return :($m.value)
else
return :($m.abs)
end
end

@doc """
"""
Hierachical drawing of directed graphs inspired by the Sugiyama framework.
In particular see Chapter 13 of 'Hierachical Drawing Algorithms' from
the 'Handbook of Graph Drawing and Visualization' and the article
Expand Down Expand Up @@ -44,7 +35,7 @@ end
labelpad Padding around text in vertices
background Defaults to nothing. If not-nothing, that value
will be used for the background color
""" ->
"""
function layout_tree{T}(adj_list::AdjList{T},
labels::Vector;
filename = "",
Expand Down Expand Up @@ -87,7 +78,7 @@ function layout_tree{T}(adj_list::AdjList{T},
elseif ordering == :optimal
layer_verts = _ordering_ip(adj_list, layers, layer_verts)
end


# 4 Vertex coordinates [to straighten edges]
# 4.1 Place y coordinates in layers
Expand All @@ -108,8 +99,8 @@ function layout_tree{T}(adj_list::AdjList{T},
if length(labels) == orig_n
extents = text_extents("sans",10pt,labels...)
for (i,(width,height)) in enumerate(extents)
widths[i] = @raw_measure width
heights[i] = @raw_measure height
widths[i] = width.value
heights[i] = height.value
end
end
locs_x = _coord_ip(adj_list, layers, layer_verts, orig_n, widths, xsep)
Expand Down
6 changes: 3 additions & 3 deletions src/tree_heur.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
@doc """
"""
Assigns layers using the longest path method.
Arguments:
adj_list Directed graph in adjacency list format
""" ->
"""
function _layer_assmt_longestpath{T}(adj_list::AdjList{T})
n = length(adj_list)
layers = fill(-1, n)
Expand Down Expand Up @@ -142,4 +142,4 @@ function _ordering_barycentric{T}(adj_list::AdjList{T}, layers, layer_verts)
end

return layer_verts
end
end
6 changes: 3 additions & 3 deletions src/tree_opt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ using JuMP
########################################################################


@doc """
"""
Given a layer assignment, decide a permutation for each layer
that minimizes edge crossings using integer programming.
Expand All @@ -28,7 +28,7 @@ using JuMP
Returns:
new_layer_verts An improved dictionary of layer => vertices (opt. perm.)
""" ->
"""
function _ordering_ip{T}(adj_list::AdjList{T}, layers, layer_verts)
num_layers = maximum(layers)

Expand Down Expand Up @@ -145,7 +145,7 @@ function _coord_ip{T}(adj_list::AdjList{T}, layers, layer_verts, orig_n, widths,
for i in 1:length(layer_verts[L])-1
a = layer_verts[L][i]
b = layer_verts[L][i+1]
@addConstraint(m, x[L,b] - x[L,a] >=
@addConstraint(m, x[L,b] - x[L,a] >=
(widths[a] + widths[b])/2 + xsep)
end
end
Expand Down
3 changes: 1 addition & 2 deletions test/REQUIRE
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
FactCheck
JuMP
Cbc
Clp
GLPKMathProgInterface
Loading

0 comments on commit 3d0a422

Please sign in to comment.