-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathedgeData.go
97 lines (77 loc) · 2.44 KB
/
edgeData.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package dot
import (
"bytes"
"fmt"
"io"
"github.com/wwmoraes/dot/attributes"
"github.com/wwmoraes/dot/constants"
)
type edgeData struct {
*attributes.Attributes
graph Graph
from, to Node
}
// String returns the graph transformed into string dot notation
func (thisEdge *edgeData) String() (string, error) {
var b bytes.Buffer
_, err := thisEdge.WriteTo(&b)
return b.String(), err
}
func (thisEdge *edgeData) From() Node {
return thisEdge.from
}
func (thisEdge *edgeData) To() Node {
return thisEdge.to
}
// Solid sets the edge attribute "style" to "solid"
// Default style
func (thisEdge *edgeData) Solid() Edge {
thisEdge.SetAttribute(constants.KeyStyle, attributes.NewString("solid"))
return thisEdge
}
// Bold sets the edge attribute "style" to "bold"
func (thisEdge *edgeData) Bold() Edge {
thisEdge.SetAttribute(constants.KeyStyle, attributes.NewString("bold"))
return thisEdge
}
// Dashed sets the edge attribute "style" to "dashed"
func (thisEdge *edgeData) Dashed() Edge {
thisEdge.SetAttribute(constants.KeyStyle, attributes.NewString("dashed"))
return thisEdge
}
// Dotted sets the edge attribute "style" to "dotted"
func (thisEdge *edgeData) Dotted() Edge {
thisEdge.SetAttribute(constants.KeyStyle, attributes.NewString("dotted"))
return thisEdge
}
// Edge returns a new Edge between the "to" node of this Edge and the argument Node
func (thisEdge *edgeData) Edge(to Node) Edge {
return thisEdge.EdgeWithAttributes(to, nil)
}
// EdgeWithAttributes returns a new Edge between the "to" node of this Edge and the argument Node
func (thisEdge *edgeData) EdgeWithAttributes(to Node, attributes attributes.Reader) Edge {
return thisEdge.graph.EdgeWithAttributes(thisEdge.to, to, attributes)
}
// EdgesTo returns all existing edges between the "to" Node of this Edge and the argument Node.
func (thisEdge *edgeData) EdgesTo(to Node) []Edge {
return thisEdge.graph.FindEdges(thisEdge.to, to)
}
func (thisEdge *edgeData) WriteTo(device io.Writer) (n int64, err error) {
denoteEdge := constants.EdgeTypeUndirected
if thisEdge.graph.Root().Type() == GraphTypeDirected {
denoteEdge = constants.EdgeTypeDirected
}
written32, err := fmt.Fprintf(device, `"%s"%s"%s"`, thisEdge.From().ID(), denoteEdge, thisEdge.To().ID())
n += int64(written32)
if err != nil {
return
}
written64, err := thisEdge.Attributes.WriteTo(device)
n += written64
if err != nil {
return
}
written32, err = fmt.Fprint(device, ";")
n += int64(written32)
return
}