PkgDependencyGraph/main.jl
2024-09-09 22:46:54 +09:00

70 lines
1.9 KiB
Julia

using Pkg
using UUIDs
using Graphs
using MetaGraphsNext
using GLMakie
using GraphMakie
g = MetaGraph(
SimpleDiGraph(),
label_type = UUID,
vertex_data_type = Pkg.API.PackageInfo,
edge_data_type = Bool,
)
foreach(Pkg.dependencies()) do (k_pkguuid, v_pkginfo)
g[k_pkguuid] = v_pkginfo
end
foreach(Pkg.dependencies()) do (pkguuid, pkginfo)
foreach(pkginfo.dependencies) do (dep_pkgname, dep_pkguuid)
g[pkguuid, dep_pkguuid] = true
end
end
fig, ax, p = graphplot(
g;
node_color = fill((:black, 0.9), nv(g)),
node_size = fill(10, nv(g)),
edge_color = fill((:gray, 0.8), ne(g)),
nlabels = labels(g) .|> (k -> g[k].name),
)
deregister_interaction!(ax, :rectanglezoom)
register_interaction!(ax, :nodedrag, NodeDrag(p))
register_interaction!(
ax,
:nodehover,
NodeHoverHandler() do hoverstate, idx, event, axis
p.node_color[][idx] = hoverstate ? (:yellow, 0.9) : (:black, 0.9)
p.node_size[][idx] = hoverstate ? 20 : 10
foreach(inneighbors(g, idx)) do didx
edge_id = findfirst(==(Edge(didx, idx)), edges(g) |> collect)
p.edge_color[][edge_id] = hoverstate ? (:blue, 0.8) : (:gray, 0.8)
end
foreach(outneighbors(g, idx)) do sidx
edge_id = findfirst(==(Edge(idx, sidx)), edges(g) |> collect)
p.edge_color[][edge_id] = hoverstate ? (:red, 0.8) : (:gray, 0.8)
end
p.node_color[] = p.node_color[]
p.node_size[] = p.node_size[]
p.edge_color[] = p.edge_color[]
end,
)
tb1_pkgname = Textbox(fig[2, 1], tellwidth = false)
on(tb1_pkgname.stored_string) do s
pkgnames = labels(g) .|> (k -> g[k].name)
@info "textbox" s
if all(!=(s), pkgnames)
return nothing
end
idx = findfirst(==(s), pkgnames)
@info "match" idx
p.node_color[][idx] = (:green, 0.6)
p.node_size[][idx] = 20
p.node_color[] = p.node_color[]
p.node_size[] = p.node_size[]
end
fig