Skip to content

Commit

Permalink
Merge pull request #850 from slwu89/graphviz-diagram
Browse files Browse the repository at this point in the history
Bug fix and tests for `to_graphviz` with `Diagram` objects
  • Loading branch information
epatters authored Oct 3, 2023
2 parents 8c466af + ca50d2d commit 8563949
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/graphics/GraphvizCategories.jl
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ function to_graphviz_property_graph(d::Diagram; kw...)
pg = to_graphviz_property_graph(g; kw...)
for v in vertices(g)
tᵥ = ob_map(d, v)
labels = has_vertex_names(g) ? [tᵥ] : [vertex_name(g,v), tᵥ]
labels = has_vertex_names(g) ? [vertex_name(g,v), tᵥ] : [tᵥ]
set_vprop!(pg, v, :label, join(labels, ":"))
end
for e in edges(g)
Expand Down
35 changes: 35 additions & 0 deletions test/graphics/GraphvizCategories.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,39 @@ gv = to_graphviz(f)
@test length(stmts(gv, Graphviz.Subgraph)) == 2
@test length(stmts(gv, Graphviz.Edge)) == 4

# Diagrams
##########

# Diagram with anonymous objects in J
C = FinCat(@acset Graph begin
V = 3
E = 2
src = [1,2]
tgt = [3,3]
end)
D = FinDomFunctor([:E,:E,:V], [:tgt,:src], C, FinCat(SchSymmetricGraph))
d = Diagram{id}(D)

gv = to_graphviz(d, node_labels=true)

@test stmts(gv, Graphviz.Node, :label) == ["E","E","V"]
@test stmts(gv, Graphviz.Edge, :label) == ["tgt","src"]

# Diagram with named objects in J
C = FinCat(@acset NamedGraph{Symbol,Symbol} begin
V = 3
E = 2
src = [1,2]
tgt = [3,3]
vname = [:e1,:e2,:v]
ename = [:t,:s]
end)
D = FinDomFunctor([:E,:E,:V], [:tgt,:src], C, FinCat(SchSymmetricGraph))
d = Diagram{id}(D)

gv = to_graphviz(d, node_labels=true)

@test stmts(gv, Graphviz.Node, :label) == ["e1:E","e2:E","v:V"]
@test stmts(gv, Graphviz.Edge, :label) == ["tgt","src"]

end

0 comments on commit 8563949

Please sign in to comment.