-
Notifications
You must be signed in to change notification settings - Fork 0
/
subgraph.go
56 lines (47 loc) · 1.04 KB
/
subgraph.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
package godot
import "strings"
type group struct {
nodes []Node
opts map[string]string
name string
}
// NewGroup creates a node group
func NewSubgraph(nodes ...string) Subgraph {
ret := make([]Node, len(nodes))
for k, v := range nodes {
ret[k] = node(v)
}
return &group{nodes: ret}
}
func (g *group) setOptions(opts map[string]string) {
g.opts = opts
}
func (g *group) setName(name string) {
g.name = name
}
func (g *group) Name() string {
return ""
}
func (g *group) Nodes() []Node {
return g.nodes
}
func (g *group) AsNode() string {
nodes := make([]string, len(g.nodes))
for k, v := range g.nodes {
nodes[k] = v.AsNode()
}
return `{` + strings.Join(nodes, " ") + `}`
}
func (g *group) AsGroup() string {
ret := make([]string, 1, len(g.nodes)+3)
ret[0] = " subgraph " + g.name + " {"
indent := " "
if opt := Options(g.opts).AsBlock(indent); opt != "" {
ret = append(ret, opt)
}
for _, node := range g.nodes {
ret = append(ret, indent+node.AsNode()+";")
}
ret = append(ret, " }")
return strings.Join(ret, "\n")
}