github.com/mapuri/terraform@v0.7.6-0.20161012203214-7e0408293f97/digraph/graphviz.go (about) 1 package digraph 2 3 import ( 4 "fmt" 5 "io" 6 ) 7 8 // WriteDot is used to emit a GraphViz compatible definition 9 // for a directed graph. It can be used to dump a .dot file. 10 func WriteDot(w io.Writer, nodes []Node) error { 11 w.Write([]byte("digraph {\n")) 12 defer w.Write([]byte("}\n")) 13 14 for _, n := range nodes { 15 nodeLine := fmt.Sprintf("\t\"%s\";\n", n) 16 17 w.Write([]byte(nodeLine)) 18 19 for _, edge := range n.Edges() { 20 target := edge.Tail() 21 line := fmt.Sprintf("\t\"%s\" -> \"%s\" [label=\"%s\"];\n", 22 n, target, edge) 23 w.Write([]byte(line)) 24 } 25 } 26 27 return nil 28 }