gonum.org/v1/gonum@v0.14.0/graph/encoding/dot/example_test.go (about) 1 // Copyright ©2018 The Gonum Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package dot_test 6 7 import ( 8 "fmt" 9 10 "gonum.org/v1/gonum/graph" 11 "gonum.org/v1/gonum/graph/encoding/dot" 12 "gonum.org/v1/gonum/graph/simple" 13 ) 14 15 type edgeWithPorts struct { 16 simple.Edge 17 fromPort, toPort string 18 } 19 20 func (e edgeWithPorts) ReversedEdge() graph.Edge { 21 e.F, e.T = e.T, e.F 22 e.fromPort, e.toPort = e.toPort, e.fromPort 23 return e 24 } 25 26 func (e edgeWithPorts) FromPort() (string, string) { 27 return e.fromPort, "" 28 } 29 30 func (e edgeWithPorts) ToPort() (string, string) { 31 return e.toPort, "" 32 } 33 34 func ExamplePorter() { 35 g := simple.NewUndirectedGraph() 36 g.SetEdge(edgeWithPorts{ 37 Edge: simple.Edge{F: simple.Node(1), T: simple.Node(0)}, 38 fromPort: "p1", 39 toPort: "p2", 40 }) 41 42 result, _ := dot.Marshal(g, "", "", " ") 43 fmt.Print(string(result)) 44 45 // Output: 46 // strict graph { 47 // // Node definitions. 48 // 0; 49 // 1; 50 // 51 // // Edge definitions. 52 // 0:p2 -- 1:p1; 53 // } 54 }