-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnodeData.go
64 lines (50 loc) · 1.41 KB
/
nodeData.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
package dot
import (
"bytes"
"fmt"
"io"
"github.com/wwmoraes/dot/attributes"
)
// nodeData represents a dot nodeData.
type nodeData struct {
*attributes.Attributes
graph Graph
id string
}
// ID returns the immutable id
func (thisNode *nodeData) ID() string {
return thisNode.id
}
// String returns the graph transformed into string dot notation
func (thisNode *nodeData) String() (string, error) {
var b bytes.Buffer
_, err := thisNode.WriteTo(&b)
return b.String(), err
}
// Edge creates an Edge to a node
func (thisNode *nodeData) Edge(toNode Node) Edge {
return thisNode.graph.EdgeWithAttributes(thisNode, toNode, nil)
}
// EdgeWithAttributes creates an Edge with the provided attributes to the a node
func (thisNode *nodeData) EdgeWithAttributes(toNode Node, attributes attributes.Reader) Edge {
return thisNode.graph.EdgeWithAttributes(thisNode, toNode, attributes)
}
// EdgesTo returns all edges between this Node and the target Node
func (thisNode *nodeData) EdgesTo(toNode Node) []Edge {
return thisNode.graph.FindEdges(thisNode, toNode)
}
func (thisNode *nodeData) WriteTo(device io.Writer) (n int64, err error) {
written32, err := fmt.Fprintf(device, `"%s"`, thisNode.ID())
n += int64(written32)
if err != nil {
return
}
written64, err := thisNode.Attributes.WriteTo(device)
n += written64
if err != nil {
return
}
written32, err = fmt.Fprintf(device, ";")
n += int64(written32)
return
}