You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For a project I'm working on, I use pydot to handle directed graphs as trees, and it is vital for me that the order of "children" of a node (speaking in the language of trees) is respected. I know that for dot, and therefore pydot, there's no such a thing as a tree as I mean it. Therefore the order of "children" of a node depends on how edges are internally represented by pydot.
Does this library make any guarantees on the order of its nodes? I'm building some programmatically, as pictured below
and so far, the nodes order reflected the order of insertion, which is what I expected and wanted. However, there's no statement in the documentation nor elsewhere that assures this is always the case. As far as I know, it could just depend by my own setup.
The text was updated successfully, but these errors were encountered:
I know it's three years later, but for the record (meaning, more for anyone else who comes across this issue in the future): Yes, Pydot does guarantee that nodes — and all other entities — will be output in the order they were inserted into a graph with add_node(), add_edge(), add_subgraph(), etc.
A monotonically-increasing sequence number is attached to each element at the time of insertion. When the graph source is generated, all elements are output in that sequence order. Deleted nodes are simply left as gaps in the sequence. If the same element is added twice, or deleted and re-added, the second addition will be placed at the end of the sequence.
(The reason those guarantees are made is, the ordering is critical for the creation of proper graphviz source code. For example, default attribute statements — node, edge, or graph nodes — will only affect the elements that come after them in the source.)
So, there's a big difference between this:
graph G {
node [shape=box];
edge [color=red];
A -- B;
edge [color=green];
B -- C;
}
and, say, this:
graph G {
A -- B;
B -- C;
edge [color=green];
node [shape=box];
edge [color=red];
}
For a project I'm working on, I use
pydot
to handle directed graphs as trees, and it is vital for me that the order of "children" of a node (speaking in the language of trees) is respected. I know that for dot, and thereforepydot
, there's no such a thing as a tree as I mean it. Therefore the order of "children" of a node depends on how edges are internally represented bypydot
.Does this library make any guarantees on the order of its nodes? I'm building some programmatically, as pictured below
and so far, the nodes order reflected the order of insertion, which is what I expected and wanted. However, there's no statement in the documentation nor elsewhere that assures this is always the case. As far as I know, it could just depend by my own setup.
The text was updated successfully, but these errors were encountered: