-
Notifications
You must be signed in to change notification settings - Fork 5
/
GraphPPLPlottingExt.jl
34 lines (29 loc) · 1.12 KB
/
GraphPPLPlottingExt.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
module GraphPPLPlottingExt
using GraphPPL, GraphPlot, Cairo, GraphPlot.Compose
function GraphPlot.gplot(model::GraphPPL.Model; file_name = "tmp.png")
g = model.graph
node_labels =
[label[2].name for label in sort(collect(g.vertex_labels), by = x -> x[1])]
plt = gplot(g, nodelabel = node_labels)
draw(PNG(file_name, 16cm, 16cm), plt)
return plt
end
function GraphPlot.gplot(model::GraphPPL.Model, around::AbstractArray{GraphPPL.NodeLabel}; depth=1, file_name = "tmp.png")
nodes = around
while depth > 0
depth -= 1
for node in nodes
nodes = unique([nodes; GraphPPL.neighbors(model, node)...])
end
end
nodes = unique(GraphPPL.code_for.(Ref(model.graph), nodes))
g = first(GraphPPL.induced_subgraph(model.graph, nodes))
node_labels =
[label[2].name for label in sort(collect(g.vertex_labels), by = x -> x[1])]
plt = gplot(g, nodelabel = node_labels)
draw(PNG(file_name, 16cm, 16cm), plt)
return plt
end
GraphPlot.gplot(model::GraphPPL.Model, around::GraphPPL.NodeLabel; kwargs...) =
GraphPlot.gplot(model, [around]; kwargs...)
end