Skip to content

Instantly share code, notes, and snippets.

@mkborregaard
Created March 2, 2017 20:49
Show Gist options
  • Save mkborregaard/6a97365594bc333cb01da1d95ad36543 to your computer and use it in GitHub Desktop.
Save mkborregaard/6a97365594bc333cb01da1d95ad36543 to your computer and use it in GitHub Desktop.
A Plots recipe for the dependency structure of julia packages
type MyGraph
source::AbstractVector{Int}
destiny::AbstractVector{Int}
end
type DepsGraph
g::MyGraph
d::Int
names::Vector{String}
end
function do_depsgraph(pkg)
dependencies(pkg) = collect(keys(Pkg.Reqs.parse(joinpath(Pkg.dir(), Pkg.Read.requires_path(pkg)))))
dependents(pkg) = Pkg.dependents(pkg)
function add_edge!(g::MyGraph, m, n)
for i in eachindex(g.source)
g.source[i] == m && g.destiny[i] == n && return
end
push!(g.source, m)
push!(g.destiny, n)
end
add_edge2!(g::MyGraph, m, n) = add_edge!(g, n, m)
function add_deps!(GET, ADD!, pkg, vtnum)
deps = GET(pkg)
for dep in deps
if in(dep, dones)
vt = findfirst(dones, dep)
ADD!(g, vtnum, vt)
else
j[1] += 1
push!(dones, dep)
ADD!(g, vtnum, j[1])
add_deps!(GET, ADD!, dep, j[1])
end
end
end
dones = String[pkg]
g = MyGraph(Int[], Int[])
const j = [1]
add_deps!(dependents, add_edge!, pkg, 1)
d = j[1]
add_deps!(dependencies, add_edge2!, pkg, 1)
g.source, g.destiny, dones, d
end
using PlotRecipes
@userplot DepsPlot
@recipe function f(g::DepsPlot)
source, destiny, names, numd = do_depsgraph(g.args[1])
colors = Vector{Symbol}(maximum([destiny; source]))
colors[1] = :red
colors[2:numd] = :green
colors[(numd + 1):end] = :blue
seriescolor := colors
names --> names
markersize --> 0.8
markeralpha --> 0.3
method --> :stress
PlotRecipes.GraphPlot((source, destiny))
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment