/
GraphvizGraphs.jl
553 lines (478 loc) · 20.3 KB
/
GraphvizGraphs.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
""" Graphviz support for Catlab's graph types.
"""
module GraphvizGraphs
export parse_graphviz, to_graphviz, to_graphviz_property_graph
using StaticArrays: StaticVector, SVector
using Colors: Colorant, @colorant_str, hex, distinguishable_colors
using ...Theories
using ...Graphs, ...CategoricalAlgebra.Subobjects, ...CategoricalAlgebra.CSets, ...CategoricalAlgebra.FinSets
import ..Graphviz
# Property graphs
#################
""" Parse Graphviz output in JSON format.
Returns a property graph with graph layout and other metadata. Each node has a
position and size.
All units are in points. Note that Graphviz has 72 points per inch.
"""
function parse_graphviz(doc::AbstractDict)::AbstractPropertyGraph
graph = doc["directed"] ? PropertyGraph{Any}() : SymmetricPropertyGraph{Any}()
nsubgraphs = doc["_subgraph_cnt"] # Subgraphs are ignored.
# Graph-level layout: bounds and padding.
# It seems, but is not documented, that the first two numbers in the Graphviz
# bounding box are always zero.
set_gprops!(graph,
bounds = SVector{2}(parse_vector(doc["bb"])[3:4]),
pad = 72*parse_point(get(doc, "pad", "0,0")),
rankdir = get(doc, "rankdir", "TB"),
)
# Add vertex for each Graphviz node.
node_keys = ("id", "name", "comment", "label", "shape", "style")
for node in doc["objects"][nsubgraphs+1:end]
props = Dict{Symbol,Any}(
Symbol(k) => node[k] for k in node_keys if haskey(node, k))
props[:position] = parse_point(node["pos"])
props[:size] = 72*SVector(parse(Float64, node["width"]),
parse(Float64, node["height"]))
add_vertex!(graph, props)
end
# Add edge for each Graphviz edge.
edge_keys = ("id", "comment", "label", "xlabel", "headlabel", "taillabel",
"headport", "tailport")
for edge in get(doc, "edges", ())
if get(edge, "style", nothing) == "invis"
# Omit invisible edges, which are used to tweak the layout in Graphviz.
continue
end
props = Dict{Symbol,Any}(
Symbol(k) => edge[k] for k in edge_keys if haskey(edge, k))
props[:spline] = parse_spline(edge["pos"])
src = Int(edge["tail"] - nsubgraphs + 1)
tgt = Int(edge["head"] - nsubgraphs + 1)
add_edge!(graph, src, tgt, props)
end
graph
end
""" Parse an array of floats in Graphviz's comma-separated format.
"""
parse_vector(s::AbstractString) = [ parse(Float64, x) for x in split(s, ",") ]
""" Parse Graphviz point.
http://www.graphviz.org/doc/info/attrs.html#k:point
"""
parse_point(s::AbstractString) = SVector{2}(parse_vector(s))
""" Parse Graphviz spline.
In Graphviz, a "spline" is a cubic B-spline of overlapping cubic Bezier curves.
It consists of 3n+1 points, where n is the number of Bezier curves.
http://www.graphviz.org/doc/info/attrs.html#k:splineType
https://web.archive.org/web/20170418034924/http://www.graphviz.org/content/how-convert-b-spline-bezier
"""
function parse_spline(spline::AbstractString)
points = StaticVector{2,Float64}[]
start, stop = nothing, nothing
for s in split(spline, " ")
if startswith(s, "s,"); start = parse_point(s[3:end])
elseif startswith(s, "e,"); stop = parse_point(s[3:end])
else push!(points, parse_point(s)) end
end
# Prefer explicit start or end points to the spline start and end points.
# Thus, endpoints may pass into the node shape but should not fall short.
if !isnothing(start); points[0] = start end
if !isnothing(stop); points[end] = stop end
points
end
""" Convert a property graph to a Graphviz graph.
This method is usually more convenient than direct AST manipulation for creating
simple Graphviz graphs. For more advanced features, like nested subgraphs, you
must use the Graphviz AST.
"""
function to_graphviz(g::AbstractPropertyGraph)::Graphviz.Graph
gv_name(v::Int) = "n$v"
gv_path(e::Int) = [gv_name(src(g,e)), gv_name(tgt(g,e))]
# Add Graphviz node for each vertex in property graph.
stmts = Graphviz.Statement[]
for v in vertices(g)
push!(stmts, Graphviz.Node(gv_name(v), vprops(g, v)))
end
# Add Graphviz edge for each edge in property graph.
is_directed = !(g isa SymmetricPropertyGraph)
for e in edges(g)
# In undirected case, only include one edge from each pair.
if is_directed || (e <= inv(g,e))
push!(stmts, Graphviz.Edge(gv_path(e), eprops(g, e)))
end
end
attrs = gprops(g)
Graphviz.Graph(
name = get(attrs, :name, "G"),
directed = is_directed,
prog = get(attrs, :prog, is_directed ? "dot" : "neato"),
stmts = stmts,
graph_attrs = get(attrs, :graph, Dict()),
node_attrs = get(attrs, :node, Dict()),
edge_attrs = get(attrs, :edge, Dict()),
)
end
# Graphs
########
""" Convert a graph to a Graphviz graph.
A simple default style is applied. For more control over the visual appearance,
first convert the graph to a property graph, define the Graphviz attributes as
needed, and finally convert the property graph to a Graphviz graph.
"""
function to_graphviz(g::HasGraph; kw...)
to_graphviz(to_graphviz_property_graph(g; kw...))
end
""" Convert graph or other structure to a property graph suitable for Graphviz.
This function is an intermediate step in many methods of the generic function
[`to_graphviz`](@ref), but can be useful in its own right for customizing the
Graphviz graph beyond whatever options are supported by [`to_graphviz`](@ref).
"""
function to_graphviz_property_graph(g::AbstractGraph;
prog::AbstractString="dot", graph_attrs::AbstractDict=Dict(),
node_attrs::AbstractDict=Dict(), edge_attrs::AbstractDict=Dict(),
node_labels::Union{Symbol,Bool}=false, edge_labels::Union{Symbol,Bool}=false)
PropertyGraph{Any}(g, v -> node_label(g, node_labels, v),
e -> edge_label(g, edge_labels, e);
prog = prog,
graph = merge!(default_graph_attrs(prog), graph_attrs),
node = merge!(default_node_attrs(node_labels), node_attrs),
edge = merge!(default_edge_attrs(prog), edge_attrs),
)
end
node_label(g, name::Symbol, v::Int) = Dict(:label => label_to_string(g[v, name]))
node_label(g::HasVertices, labels::Bool, v::Int) =
Dict(:label => labels ? label_to_string(vertex_name(g, v)) : "")
edge_label(g, name::Symbol, e::Int) = Dict(:label => label_to_string(g[e, name]))
edge_label(g::HasGraph, labels::Bool, e::Int) =
labels ? Dict(:label => label_to_string(edge_name(g, e))) : Dict{Symbol,String}()
label_to_string(label) = string(label)
label_to_string(label::Tuple) = join(string.(label), ',')
function default_graph_attrs(prog::AbstractString)
attrs = Dict{Symbol,String}()
prog == "dot" && (attrs[:rankdir] = "LR")
attrs
end
function default_node_attrs(labels)
Dict(:shape => default_node_shape(labels),
:width => "0.05", :height => "0.05", :margin => "0")
end
default_node_shape(labels::Bool) = labels ? "circle" : "point"
default_node_shape(::Symbol) = "ellipse"
function default_edge_attrs(prog::AbstractString)
attrs = Dict(:arrowsize => "0.5")
prog ∈ ("neato", "fdp") && (attrs[:len] = "0.5")
attrs
end
# Symmetric graphs
##################
function to_graphviz_property_graph(g::AbstractSymmetricGraph;
prog::AbstractString="neato", graph_attrs::AbstractDict=Dict(),
node_attrs::AbstractDict=Dict(), edge_attrs::AbstractDict=Dict(),
node_labels::Union{Symbol,Bool}=false, edge_labels::Union{Symbol,Bool}=false)
SymmetricPropertyGraph{Any}(g, v -> node_label(g, node_labels, v),
e -> symmetric_edge_label(g, edge_labels, e);
prog = prog,
graph = merge!(default_graph_attrs(prog), graph_attrs),
node = merge!(default_node_attrs(node_labels), node_attrs),
edge = merge!(default_edge_attrs(prog), edge_attrs),
)
end
symmetric_edge_label(g, name::Symbol, e::Int) = edge_label(g, name, e)
function symmetric_edge_label(g, labels::Bool, e::Int)
if labels
e′ = inv(g,e)
Dict(:label => (e == e′ ? string(e) : "($(min(e,e′)),$(max(e,e′)))"))
else
Dict{Symbol,String}()
end
end
# Reflexive graphs
##################
function to_graphviz_property_graph(g::AbstractReflexiveGraph;
prog::AbstractString="dot", graph_attrs::AbstractDict=Dict(),
node_attrs::AbstractDict=Dict(), edge_attrs::AbstractDict=Dict(),
node_labels::Union{Symbol,Bool}=false, edge_labels::Union{Symbol,Bool}=false,
show_reflexive::Bool=false)
pg = PropertyGraph{Any}(; prog = prog,
graph = merge!(default_graph_attrs(prog), graph_attrs),
node = merge!(default_node_attrs(node_labels), node_attrs),
edge = merge!(default_edge_attrs(prog), edge_attrs),
)
add_vertices!(pg, nv(g))
for v in vertices(g)
set_vprops!(pg, v, node_label(g, node_labels, v))
end
reflexive_edges = Set(refl(g))
for e in edges(g)
is_reflexive = e ∈ reflexive_edges
if show_reflexive || !is_reflexive
e′ = add_edge!(pg, src(g,e), tgt(g,e))
is_reflexive && set_eprop!(pg, e′, :style, "dashed")
set_eprops!(pg, e′, edge_label(g, edge_labels, e))
end
end
pg
end
# Symmetric reflexive graphs
############################
function to_graphviz_property_graph(g::AbstractSymmetricReflexiveGraph;
prog::AbstractString="neato", graph_attrs::AbstractDict=Dict(),
node_attrs::AbstractDict=Dict(), edge_attrs::AbstractDict=Dict(),
node_labels::Union{Symbol,Bool}=false, edge_labels::Union{Symbol,Bool}=false,
show_reflexive::Bool=false)
pg = SymmetricPropertyGraph{Any}(; prog = prog,
graph = merge!(default_graph_attrs(prog), graph_attrs),
node = merge!(default_node_attrs(node_labels), node_attrs),
edge = merge!(default_edge_attrs(prog), edge_attrs),
)
add_vertices!(pg, nv(g))
for v in vertices(g)
set_vprops!(pg, v, node_label(g, node_labels, v))
end
reflexive_edges = Set(refl(g))
for e in edges(g)
is_reflexive = e ∈ reflexive_edges
if (is_reflexive ? show_reflexive : e <= inv(g,e))
e′ = first(add_edge!(pg, src(g,e), tgt(g,e)))
is_reflexive && set_eprop!(pg, e′, :style, "dashed")
set_eprops!(pg, e′, symmetric_edge_label(g, edge_labels, e))
end
end
pg
end
# Half-edge graphs
##################
to_graphviz(g::AbstractHalfEdgeGraph; kw...) =
to_graphviz(to_graphviz_property_graph(g; kw...))
function to_graphviz_property_graph(g::AbstractHalfEdgeGraph;
prog::AbstractString="neato", graph_attrs::AbstractDict=Dict(),
node_attrs::AbstractDict=Dict(), edge_attrs::AbstractDict=Dict(),
node_labels::Union{Symbol,Bool}=false, edge_labels::Union{Symbol,Bool}=false)
pg = SymmetricPropertyGraph{Any}(; prog = prog,
graph = merge!(default_graph_attrs(prog), graph_attrs),
node = merge!(default_node_attrs(node_labels), node_attrs),
edge = merge!(default_edge_attrs(prog), edge_attrs),
)
for v in vertices(g)
add_vertex!(pg, label=node_labels ? string(v) : "")
end
for e in half_edges(g)
if e == inv(g,e)
# Dangling half-edge: add an invisible vertex.
v = add_vertex!(pg, style="invis", shape="none", label="")
e′ = first(add_edge!(pg, vertex(g,e), v))
set_eprops!(pg, e′, symmetric_edge_label(g, edge_labels, e))
elseif e < inv(g,e)
# Pair of distict half-edges: add a standard edge.
e′ = first(add_edge!(pg, vertex(g,e), vertex(g,inv(g,e))))
set_eprops!(pg, e′, symmetric_edge_label(g, edge_labels, e))
end
end
pg
end
# Subgraphs
###########
to_graphviz(subgraph::Subobject{<:HasGraph}; kw...) =
to_graphviz(to_graphviz_property_graph(subgraph; kw...))
function to_graphviz_property_graph(
subgraph::Subobject{<:Union{AbstractGraph,AbstractSymmetricGraph}};
subgraph_node_attrs::AbstractDict=default_subgraph_node_attrs,
subgraph_edge_attrs::AbstractDict=default_subgraph_edge_attrs, kw...)
pg = to_graphviz_property_graph(ob(subgraph); kw...)
f = hom(subgraph)
for v in vertices(dom(f))
set_vprops!(pg, f[:V](v), subgraph_node_attrs)
end
for e in edges(dom(f))
set_eprops!(pg, f[:E](e), subgraph_edge_attrs)
end
pg
end
const default_subgraph_node_attrs = Dict(:color => "cornflowerblue")
const default_subgraph_edge_attrs = Dict(:color => "cornflowerblue")
# Bipartite graphs
##################
""" Visualize a bipartite graph using Graphviz.
Works for both directed and undirected bipartite graphs. Both types of vertices
in the bipartite graph become nodes in the Graphviz graph.
# Arguments
- `prog="dot"`: Graphviz program to use
- `graph_attrs`: Graph-level Graphviz attributes
- `node_attrs`: Node-level Graphviz attributes
- `edge_attrs`: Edge-level Graphviz attributes
- `node_labels=false`: whether to label nodes and if so, which pair of
data attributes to use
- `edge_labels=false`: whether to label edges and if so, which data attribute
(undirected case) or pair of attributes (directed case) to use
- `invis_edge=true`: whether to add invisible edges between vertices of same
type, which ensures that the order of the nodes is preserved.
"""
function to_graphviz(g::AbstractUndirectedBipartiteGraph;
prog::AbstractString="dot", graph_attrs::AbstractDict=Dict(),
node_attrs::AbstractDict=Dict(), edge_attrs::AbstractDict=Dict(),
node_labels::Union{Tuple{Symbol,Symbol},Bool}=false,
edge_labels::Union{Symbol,Bool}=false, kw...)
stmts, nodes1, nodes2 = bipartite_graphviz_nodes(g;
node_labels=node_labels, kw...)
for e in edges(g)
attrs = merge!(Dict(:constraint => "false"), edge_label(g, edge_labels, e))
push!(stmts, Graphviz.Edge([nodes1[src(g,e)], nodes2[tgt(g,e)]], attrs))
end
Graphviz.Digraph("bipartite_graph", stmts, prog=prog,
graph_attrs = merge!(default_graph_attrs(prog), graph_attrs),
node_attrs = merge!(default_node_attrs(node_labels), node_attrs),
edge_attrs = merge!(default_edge_attrs(prog), edge_attrs))
end
function to_graphviz(g::AbstractBipartiteGraph;
prog::AbstractString="dot", graph_attrs::AbstractDict=Dict(),
node_attrs::AbstractDict=Dict(), edge_attrs::AbstractDict=Dict(),
node_labels::Union{Tuple{Symbol,Symbol},Bool}=false,
edge_labels::Union{Tuple{Symbol,Symbol},Bool}=false, kw...)
stmts, nodes1, nodes2 = bipartite_graphviz_nodes(g;
node_labels=node_labels, kw...)
edge12_labels, edge21_labels = edge_labels isa Tuple ? edge_labels :
(edge_labels, edge_labels)
for e in edges₁₂(g)
attrs = merge!(Dict(:constraint => "false"), edge_label(g, edge12_labels, e))
push!(stmts, Graphviz.Edge([nodes1[src₁(g,e)], nodes2[tgt₂(g,e)]], attrs))
end
for e in edges₂₁(g)
attrs = merge!(Dict(:constraint => "false"), edge_label(g, edge21_labels, e))
push!(stmts, Graphviz.Edge([nodes2[src₂(g,e)], nodes1[tgt₁(g,e)]], attrs))
end
Graphviz.Digraph("bipartite_graph", stmts, prog=prog,
graph_attrs = merge!(default_graph_attrs(prog), graph_attrs),
node_attrs = merge!(default_node_attrs(node_labels), node_attrs),
edge_attrs = merge!(default_edge_attrs(prog), edge_attrs))
end
function bipartite_graphviz_nodes(g::HasBipartiteVertices;
node_labels::Union{Tuple{Symbol,Symbol},Bool}=false,
invis_edges::Bool=true)
V₁, V₂ = vertices₁(g), vertices₂(g)
node1_labels, node2_labels = node_labels isa Tuple ? node_labels :
(node_labels, node_labels)
# Vertices of type 1.
nodes1 = map(V₁) do v
Graphviz.Node("n1_$v", node_label(g, node1_labels, v))
end
edges1 = Graphviz.Edge[]
if invis_edges
for (u, v) in zip(V₁[1:end-1], V₁[2:end])
push!(edges1, Graphviz.Edge("n1_$u", "n1_$v"; style="invis"))
end
end
cluster1 = Graphviz.Subgraph("cluster_nodes1", [nodes1; edges1];
graph_attrs=Graphviz.Attributes(:rank => "same"))
# Vertices of type 2.
nodes2 = map(V₂) do v
Graphviz.Node("n2_$v", node_label(g, node2_labels, v))
end
edges2 = Graphviz.Edge[]
if invis_edges
for (u, v) in zip(V₂[1:end-1], V₂[2:end])
push!(edges2, Graphviz.Edge("n2_$u", "n2_$v"; style="invis"))
end
end
cluster2 = Graphviz.Subgraph("cluster_nodes2", [nodes2; edges2];
graph_attrs=Graphviz.Attributes(:rank => "same"))
stmts = Graphviz.Statement[cluster1, cluster2]
(stmts, map(n -> n.name, nodes1), map(n -> n.name, nodes2))
end
default_node_shape(::Tuple{Symbol,Symbol}) = "ellipse"
node_label(g::HasBipartiteVertices, labels::Bool, v::Int) =
Dict(:label => labels ? string(v) : "")
edge_label(g::HasBipartiteVertices, labels::Bool, e::Int) =
labels ? Dict(:label => string(e)) : Dict{Symbol,String}()
# Graph homomorphisms
#####################
""" Visualize a graph homomorphism using Graphviz.
Visualize a homomorphism (`ACSetTransformation`) between two graphs (instances
of `AbstractGraph`). By default, the domain and codomain are drawn as subgraphs
and the vertex mapping is drawn using dotted edges, whereas the edge map is
suppressed. The vertex and edge mapping can also be shown using colors, via the
`node_colors` and `edge_colors` keyword arguments.
# Arguments
- `draw_codom=true`: whether to draw the codomain graph
- `draw_mapping=true`: whether to draw the vertex mapping using edges
- `prog="dot"`: Graphviz program to use
- `graph_attrs`: Graph-level Graphviz attributes
- `node_attrs`: Node-level Graphviz attributes
- `edge_attrs`: Edge-level Graphviz attributes
- `node_labels=false`: whether to draw node labels and which vertex attribute to use
- `edge_labels=false`: whether to draw edge labels and which edge attribute to use
- `node_colors=!draw_codom`: whether and how to color nodes based on vertex map
- `edge_colors=!draw_codom`: whether and how to color edges based on edge map
"""
function to_graphviz(f::StructACSetTransformation{S,Comp,<:AbstractGraph,<:AbstractGraph};
draw_codom::Bool=true, draw_mapping::Bool=true,
prog::AbstractString="dot", graph_attrs::AbstractDict=Dict(),
node_attrs::AbstractDict=Dict(), edge_attrs::AbstractDict=Dict(),
node_labels::Union{Symbol,Bool}=false, edge_labels::Union{Symbol,Bool}=false,
node_colors::Union{Nothing,Bool}=nothing,
edge_colors::Union{Nothing,Bool}=nothing) where {S,Comp}
stmts = Graphviz.Statement[]
g, h = dom(f), codom(f)
# mapping between edges and between vertices given by colors
isnothing(node_colors) && (node_colors = !draw_codom)
isnothing(edge_colors) && (edge_colors = !draw_codom)
node_colors == true && (node_colors = default_node_colors)
edge_colors == true && (edge_colors = default_edge_colors)
vcolors = node_colors != false ? node_colors(nv(h)) : nothing
ecolors = edge_colors != false ? edge_colors(ne(h)) : nothing
# subgraph for g = dom(f)
dom_nodes = map(vertices(g)) do v
Graphviz.Node("dom_$v", merge!(node_color(vcolors, f[:V](v)),
node_label(g, node_labels, v)))
end
dom_edges = map(edges(g)) do e
Graphviz.Edge(["dom_$(src(g,e))", "dom_$(tgt(g,e))"],
merge!(edge_color(ecolors, f[:E](e)),
edge_label(g, edge_labels, e)))
end
dom_stmts = vcat(dom_nodes, dom_edges)
if draw_codom && nv(g) > 0
push!(stmts, Graphviz.Subgraph("cluster_dom", dom_stmts))
else
append!(stmts, dom_stmts)
end
# subgraph for h = codom(f)
if draw_codom
codom_nodes = map(vertices(h)) do v
Graphviz.Node("cod_$v", merge!(node_color(vcolors, v),
node_label(h, node_labels, v)))
end
codom_edges = map(edges(h)) do e
Graphviz.Edge(["cod_$(src(h,e))", "cod_$(tgt(h,e))"],
merge!(edge_color(ecolors, e),
edge_label(h, edge_labels, e)))
end
codom_stmts = vcat(codom_nodes, codom_edges)
push!(stmts, Graphviz.Subgraph("cluster_cod", codom_stmts))
end
# mapping between vertices
if draw_codom && draw_mapping
map_stmts = map(vertices(g)) do v
Graphviz.Edge(["\"dom_$v\"", "\"cod_$(f[:V](v))\""], Graphviz.Attributes(
:constraint => "false", :style => "dotted"))
end
append!(stmts, map_stmts)
end
Graphviz.Digraph("hom_graph", stmts, prog=prog,
graph_attrs = merge!(default_graph_attrs(prog), graph_attrs),
node_attrs = merge!(default_node_attrs(node_labels), node_attrs),
edge_attrs = merge!(default_edge_attrs(prog), edge_attrs))
end
function node_color(colors::AbstractVector{<:Colorant}, v::Int)
Dict(:color => string("#", hex(colors[v])))
end
node_color(::Nothing, v::Int) = Dict{Symbol,String}()
function edge_color(colors::AbstractVector{<:Colorant}, e::Int)
Dict(:color => string("#", hex(colors[e])))
end
edge_color(::Nothing, e::Int) = Dict{Symbol,String}()
function default_node_colors(n)
distinguishable_colors(n, [colorant"white", colorant"black"], dropseed=true)
end
function default_edge_colors(n)
distinguishable_colors(n, colorant"#F8766D", lchoices=[65], cchoices=[100])
end
end