mirror of
https://github.com/gonum/gonum.git
synced 2025-10-06 23:52:47 +08:00
encoding/dot: fix ports on undirected graphs
This commit is contained in:
@@ -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 {
|
||||
|
Reference in New Issue
Block a user