开发者

How to add ports to nodes in an Agraph_t?

I'm trying to add ports to nodes, but apparently I'm missing something.

aginit();
Agraph_t *g = agopen("g", AGFLAG_DIRECTED);

Agsym_t *symRankdir = agraphattr(g, "rankdir", "LR");
Agsym_t *symShape = agnodeattr(g, "shape", "Mrecord");
Agsym_t *symLabel = agnodeattr(g, "label", "");

Agnode_t *n1 = agnode(g, "n1");
n1->attr[1] = "n1|<p1>p1|<p2>p2";
Agnode_t *n2 = agnode(g, "n2");
n2->attr[1] = "n2|<p1>p1|<p2>p2";
Agedge_t *e = agedge(g, n1, n2);
e->u.tail_port.defined = true;
e->u.tail_port.name = "p1";
e->u.head_po开发者_开发百科rt.defined = true;
e->u.head_port.name = "p2";

FILE *fp = fopen(argv[1], "w");
agwrite(g, fp);

Output:

digraph g {
    graph [rankdir=LR];
    node [shape=Mrecord];
    n1 [label="n1|<p1>p1|<p2>p2"];
    n2 [label="n2|<p1>p1|<p2>p2"];
    n1 -> n2;
}

The edge in the output should be n1:p1 -> n2:p2. What needs to be set in the code to make that happen?


Replace this --

e->u.tail_port.defined = true;
e->u.tail_port.name = "p1";
e->u.head_port.defined = true;
e->u.head_port.name = "p2";

-- with this --

#define TAILX               1
#define HEADX               2
agxset(e, TAILX, "p1");
agxset(e, HEADX, "p2");

(I figured it out from looking at the Graphviz source code -- lib/graph/parser.y and lib/graph/libgraph.h.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜