gorgonia.org/gorgonia@v0.9.17/encoding/dot/node.go (about) 1 package dot 2 3 import ( 4 "fmt" 5 "strings" 6 7 "gonum.org/v1/gonum/graph/encoding" 8 "gorgonia.org/gorgonia" 9 internalEncoding "gorgonia.org/gorgonia/internal/encoding" 10 ) 11 12 type node struct { 13 n *gorgonia.Node 14 } 15 16 func (n *node) ID() int64 { 17 return n.n.ID() 18 } 19 20 // DOTID is used for the graphviz output. It fulfils the gonum encoding interface 21 func (n *node) DOTID() string { 22 return fmt.Sprintf("Node_%p", n.n) 23 } 24 25 // Attributes is for graphviz output. It specifies the "label" of the node (a table) 26 func (n *node) Attributes() []encoding.Attribute { 27 var htmlEscaper = strings.NewReplacer( 28 `&`, "&", 29 `'`, "'", // "'" is shorter than "'" and apos was not in HTML until HTML5. 30 `<`, "<", 31 `>`, ">", 32 `{`, "{", 33 `}`, "}", 34 `"`, """, // """ is shorter than """. 35 `const`, "const|", // """ is shorter than """. 36 ) 37 attrs := []encoding.Attribute{ 38 { 39 Key: "id", 40 Value: fmt.Sprintf(`"%p"`, n.n), 41 }, 42 { 43 Key: "shape", 44 Value: "Mrecord", 45 }, 46 { 47 Key: "label", 48 Value: fmt.Sprintf(`"{{%s|%#x}|{Op|%s}|{Shape|%v}}"`, 49 htmlEscaper.Replace(n.n.Name()), 50 n.ID(), 51 htmlEscaper.Replace(fmt.Sprintf("%s", n.n.Op())), 52 n.n.Shape()), 53 }, 54 } 55 return attrs 56 } 57 58 func (n *node) Groups() internalEncoding.Groups { 59 return n.n.Groups() 60 }