tortal
tortal

Reputation: 719

How can I connect graphviz nodes that are in records using pygraphviz for dot?

This is a problem I stumbled upon when interfacing with dot through pygraphviz. I am creating records through labels but I am wondering how to connect ports that are in the records rather than record nodes themselves.

In dot it should look something like this:

a00 [shape = "record" label="{{RecordThing1}|{<1>A|<2>B|<3>C|<4>D|<5>E|<6>F}}"];
a01 [shape = "record" label="{{RecordThing2}|{<1>A|<2>B|<3>C|<4>D|<5>E|<6>F}}"];
a00:1 -> a01:1

Upvotes: 1

Views: 788

Answers (2)

Syeda
Syeda

Reputation: 1

There is a small error in the code of the solution posted by tortal: add_edge needs to be used (instead of add_node).

Assuming two structures 'a00' and 'a01' with fields 'f0', 'f1' and 'f2', the 'tailport' and 'headport' edge attributes can indeed be used to link different fields

e.g., for linking a00:f1 with a01:f0

from pygraphviz import AGraph
g = AGraph()
g.add_node("a00", label="<f0> text | {<f1> text | <f2> text}", shape="record")
g.add_node("a01", label="<f0> text | {<f1> text | <f2> text}", shape="record")
g.add_edge('a00', 'a01', tailport='f1', headport='f0')

Upvotes: 0

tortal
tortal

Reputation: 719

Found a solution: The headport and tailport attributes of edges can be used. e.g.

agraph.add_node('a00', 'a01', tailport=1, headport=1)

Read more at: https://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:headport for instance.

Upvotes: 1

Related Questions