Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fix and tests for to_graphviz with Diagram objects #850

Merged
merged 4 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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ᵥ]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha, this is why it's good to have tests. Thanks!

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