encoding/dot: fix ports on undirected graphs

This commit is contained in:
J. Holmes
2018-04-15 19:13:11 -06:00
committed by Dan Kortschak
parent 7b0fe8702c
commit b2e9df857d
5 changed files with 67 additions and 19 deletions

View File

@@ -41,7 +41,12 @@ type Attributers interface {
// to the the DOT node port to be used by the edge, compass corresponds
// to DOT compass point to which the edge will be aimed.
type Porter interface {
// FromPort returns the port and compass for the
// From node of a graph.Edge.
FromPort() (port, compass string)
// ToPort returns the port and compass for the
// To node of a graph.Edge.
ToPort() (port, compass string)
}
@@ -219,9 +224,14 @@ func (p *printer) print(g graph.Graph, name string, needsIndent, isSubgraph bool
} else {
p.writeNode(n)
}
e, edgeIsPorter := g.Edge(nid, tid).(Porter)
e := g.Edge(nid, tid)
porter, edgeIsPorter := e.(Porter)
if edgeIsPorter {
p.writePorts(e.FromPort())
if e.From().ID() == nid {
p.writePorts(porter.FromPort())
} else {
p.writePorts(porter.ToPort())
}
}
if isDirected {
@@ -241,7 +251,11 @@ func (p *printer) print(g graph.Graph, name string, needsIndent, isSubgraph bool
p.writeNode(t)
}
if edgeIsPorter {
p.writePorts(e.ToPort())
if e.From().ID() == nid {
p.writePorts(porter.ToPort())
} else {
p.writePorts(porter.FromPort())
}
}
if a, ok := g.Edge(nid, tid).(encoding.Attributer); ok {