Zabuzzman
Zabuzzman

Reputation: 194

Graphviz: edge to record label in Python (gv)

I'm having a hard time generating the following edge:

...
h1 -> "h2":f2;

as shown in this example: datastruct

Consider the following Python code:

#!/usr/bin/env python

import sys
import gv

gh = gv.digraph('g')

gv.setv(gh, 'rankdir', "LR")

node = gv.protonode(gh)
gv.setv(node, 'shape', 'record')

n1 = gv.node(gh, "h1")

n2 = gv.node(gh, "h2")
gv.setv(n2, "label", "<f1> s1 | <f2> s2")

e = gv.edge(n1, n2)

gv.write(gh, "out.dot")

Which after execution gives the following output:

digraph g {
    node [label="\N"];
    graph [rankdir=LR];
    h1 [shape=record];
    h2 [label="<f1> s1 | <f2> s2", shape=record];
    h1 -> h2;
}

Which leaves me with the question how to obtain the edge shown above so it points to the correct record entry.

Thanks in advance.

Upvotes: 2

Views: 961

Answers (1)

You need to set the headport to do that:

I've only done this in C but from what you show in python I assume that is something like this:

e = gv.edge(n1, n2)
gv.setv(e, "headport", "f1") # or another key from the records

This will create an edge like this:

h1 -> h2:f1;

You can also set the tailport if you need to point in the reverse direction.

Upvotes: 2

Related Questions