forked from gorgonia/gorgonia
/
operatorsubgraph.go
73 lines (66 loc) · 1.58 KB
/
operatorsubgraph.go
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
package dot
import (
"strconv"
internalEncoding "github.com/m8u/gorgonia/internal/encoding"
"gonum.org/v1/gonum/graph"
"gonum.org/v1/gonum/graph/encoding"
gonumDot "gonum.org/v1/gonum/graph/encoding/dot"
)
type operatorSubGraph struct {
name string
id int
graph.DirectedBuilder
subs map[internalEncoding.Group]operatorSubGraph
}
func (g operatorSubGraph) DOTID() string {
return "cluster_" + g.name + strconv.Itoa(g.id)
}
// DOTAttributers to specify the top-level graph attributes for the graphviz generation
func (g operatorSubGraph) DOTAttributers() (graph, node, edge encoding.Attributer) {
// Create a special attribute "rank" to place the input at the same level in the graph
graphAttributes := attributer{
encoding.Attribute{
Key: "label",
Value: g.name,
},
encoding.Attribute{
Key: "color",
Value: "coral",
},
encoding.Attribute{
Key: "style",
Value: "filled",
},
encoding.Attribute{
Key: "nodeset",
Value: "0.5",
},
encoding.Attribute{
Key: "ranksep",
Value: `"1.2 equally"`,
},
}
nodeAttributes := attributer{
encoding.Attribute{
Key: "style",
Value: `"rounded,filled"`,
},
encoding.Attribute{
Key: "fillcolor",
Value: "white",
},
encoding.Attribute{
Key: "shape",
Value: "Mrecord",
},
}
return graphAttributes, nodeAttributes, attributer{}
}
// Structure fulfils the dot.Structurer interface.
func (g operatorSubGraph) Structure() []gonumDot.Graph {
output := make([]gonumDot.Graph, 0, len(g.subs))
for _, subg := range g.subs {
output = append(output, subg)
}
return output
}