Repository navigation
Expand file tree
/
Copy pathedge.go
More file actions
70 lines (61 loc) · 2.03 KB
/
Copy pathedge.go
File metadata and controls
70 lines (61 loc) · 2.03 KB
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
package layout
// Edge connects two nodes. Layout leaves it unchanged; the computed path
// is in Layout.Edges.
type Edge struct {
Directed bool
From, To *Node
Weight float64
// MinLen is the minimum number of ranks the edge must span in a
// hierarchical layout; 0 uses the default of 1.
MinLen int
// FromPort and ToPort pin the edge ends to compass points on the nodes
FromPort, ToPort Compass
// FromField and ToField attach the edge ends to fields of record
// nodes, by the names of their ports, such as f1 for "<f1> text":
// an end goes on the side of the node facing the other end, across
// from the middle of the field. A field the node doesn't have, or a
// node that isn't a record, leaves the end free.
FromField, ToField string
// ArrowHead and ArrowTail select the markers at the To and From ends
ArrowHead, ArrowTail Arrow
Tooltip string
Label string
FontName string
FontSize Length
FontColor Color
// HeadLabel and TailLabel are drawn beside the To and From ends, just
// past the nodes, in the font of Label, like Graphviz headlabel and
// taillabel
HeadLabel, TailLabel string
LineWidth Length
LineColor Color
LineStyle LineStyle
// Invisible keeps the edge in the layout but leaves it out of the
// drawing, like Graphviz style=invis.
Invisible bool
// Pos and LabelPos are the path and label center an edge keeps in a
// pinned graph, see Node.Pos.
Pos Path
LabelPos *Vector
}
// NewEdge creates an edge from one node to another with default styling.
func NewEdge(from, to *Node) *Edge {
edge := &Edge{}
edge.From = from
edge.To = to
edge.Weight = 1.0
edge.LineWidth = Point
return edge
}
// HeadMarker returns the marker at the head of the edge: ArrowHead, or
// ArrowNormal for a directed edge that leaves it unset.
func (edge *Edge) HeadMarker() Arrow {
if edge.ArrowHead == ArrowDefault && edge.Directed {
return ArrowNormal
}
return edge.ArrowHead
}
// String returns the edge as "from->to".
func (edge *Edge) String() string {
return edge.From.String() + "->" + edge.To.String()
}