encoding/dot: make all simple graph marshalling strict

Also fix bug in order of emitting strict keyword.
This commit is contained in:
Dan Kortschak
2018-10-27 17:42:20 +10:30
committed by Dan Kortschak
parent cc0c958a30
commit 609b9d63e8
6 changed files with 56 additions and 58 deletions

View File

@@ -76,14 +76,11 @@ type Subgrapher interface {
// however, advanced GraphViz DOT features provided by Marshal depend on
// implementation of the Node, Attributer, Porter, Attributers, Structurer,
// Subgrapher and Graph interfaces.
func Marshal(g graph.Graph, name, prefix, indent string, strict bool) ([]byte, error) {
func Marshal(g graph.Graph, name, prefix, indent string) ([]byte, error) {
var p printer
p.indent = indent
p.prefix = prefix
p.visited = make(map[edge]bool)
if strict {
p.buf.WriteString("strict ")
}
err := p.print(g, name, false, false)
if err != nil {
return nil, err
@@ -118,6 +115,9 @@ func (p *printer) print(g graph.Graph, name string, needsIndent, isSubgraph bool
p.buf.WriteString(p.indent)
}
}
if !isSubgraph {
p.buf.WriteString("strict ")
}
_, isDirected := g.(graph.Directed)
if isSubgraph {
p.buf.WriteString("sub")