Skip to content
This repository has been archived by the owner on Oct 21, 2021. It is now read-only.

Modify to_dot #206

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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/dot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function to_dot{G<:AbstractGraph}(graph::G, stream::IO,attrs::AttributeDict=Attr
write(stream,"$(vertex_index(vtx,graph))$attrs\n")
end
for edge in edges(graph)
write(stream,"$(vertex_index(source(edge), graph)) $(edge_op(graph)) $(vertex_index(target(edge), graph))\n")
write(stream,"$(vertex_index(source(edge), graph)) $(edge_op(graph)) $(vertex_index(target(edge), graph))$(has_edge_attrs ? string(" ", to_dot(attributes(edge, graph))) : "")\n")
Copy link
Contributor

Choose a reason for hiding this comment

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

Hi, I'm not sure we should be calling to_dot inside the string interpolation here. Could you maybe just explain a little more on why calling to_dot(attributes(edge, graph))) inside the string interpolation is the right thing to do? Sorry, but I am not the most knowledgeable on to_dot. Although, I would expect a lower level functio that unpacks the graph edge attributes into a string -- is to_dot really the best one?

end
elseif implements_vertex_list(graph) && (implements_incidence_list(graph) || implements_adjacency_list(graph))
for vertex in vertices(graph)
Expand Down
27 changes: 27 additions & 0 deletions test/dot2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
# 2) there are vertex attributes to be shown in .dot
# 3) the graph verifies implements_edge_list(.) == true
# and implements_vertex_map(.) == true
# 4) there are edges attributes to be shown in .dot
# and the graph verifies implements_edge_list(.) == true
# and implements_vertex_map(.) == true


# These functions help with dealing with the fact that in two equivalent
Expand Down Expand Up @@ -149,4 +152,28 @@ println(dot4)
@test Main.check_same_dot(dot4,"graph graphname {\n1\t[\"label\"=\"a\",\"color\"=\"bisque\"]\n2\t[\"label\"=\"b\",\"color\"=\"bisque\"]\n3\t[\"label\"=\"c\",\"color\"=\"bisque\"]\n4\t[\"label\"=\"d\",\"color\"=\"bisque\"]\n1 -- 3\n2 -- 3\n}\n"
)

### 5) undirected graph with node attributes and edge attributes and some disconnected vertices


agu = Graphs.graph( map( MyVtxType,[ "a", "b", "c","d"]), Graphs.ExEdge{MyVtxType}[],
is_directed=false)

vl = agu.vertices

add_edge!(agu, vl[1], vl[3] )
add_edge!(agu, vl[2], vl[3])

agu.edges[1].attributes["color"] = "red"
agu.edges[2].attributes["color"] = "blue"

dot5=to_dot(agu)
println(dot5)

@test @show implements_edge_list(agu)==true
@test @show implements_vertex_map(agu)==true

@test Main.check_same_dot(dot5,"graph graphname {\n1\t[\"label\"=\"a\",\"color\"=\"bisque\"]\n2\t[\"label\"=\"b\",\"color\"=\"bisque\"]\n3\t[\"label\"=\"c\",\"color\"=\"bisque\"]\n4\t[\"label\"=\"d\",\"color\"=\"bisque\"]\n1 -- 3 [\"color\"=\"red\"]\n2 -- 3 [\"color\"=\"blue\"]\n}\n"
)


end # module testDOT2