Add Bytes method to dot.Graph

This way we can feed the buffer output directly to an io.Writer
This commit is contained in:
James Bardin 2016-11-04 11:30:51 -04:00
parent 07ec946e7e
commit 8d3e6f445f
1 changed files with 13 additions and 0 deletions

View File

@ -132,6 +132,19 @@ func (g *Graph) String() string {
return w.String()
}
// Returns the DOT representation of this Graph.
func (g *Graph) Bytes() []byte {
w := newGraphWriter()
g.drawHeader(w)
w.Indent()
g.drawBody(w)
w.Unindent()
g.drawFooter(w)
return w.Bytes()
}
func (g *Graph) drawHeader(w *graphWriter) {
if g.Directed {
w.Printf("digraph {\n")