开发者

Grouping output edges from graphviz

开发者 https://www.devze.com 2023-02-20 09:34 出处:网络
I\'m trying to draw a graph with two kinds of edges, and I want the two kinds of edges to link to each node from opposite sides, as much as possible.I.e. if an edge of type A enters from the left, I w

I'm trying to draw a graph with two kinds of edges, and I want the two kinds of edges to link to each node from opposite sides, as much as possible. I.e. if an edge of type A enters from the left, I want all edges of开发者_开发知识库 type B to exit to the right. I know I could specify compass directions, but I'd like graphviz to be able to switch this around to minimize graph clutter.

Is it this, or something similar, possible?


If you don't want to specify compass points, you'll probably not want to use HTML like labels and ports either.

If you're using dot, you still can achieve something similar by using the samehead and the sametail attributes. From the reference:

Edges with the same head and the same samehead value are aimed at the same point on the head

This lets you group outgoing and incoming edges. Here's a simple example:

digraph g{
    rankdir=LR;
    edge[samehead=h1, sametail=t1];
    a1->b->c1;
    a2->b->c2;
    edge[samehead=h2, sametail=t2];
    a3->b->c3;
    a4->b->c4;
}

Grouping output edges from graphviz

This of course is only about grouping heads and tails of edges, and does not guarantee opposite sides for edges of different types.


My current solution is to replace my old nodes with edges, thus creating two nodes - one for each "port" in the graph. I can then my edges between these "port nodes". Eg. instead of

node1 -> node2 [ sametail="b", samehead = "a" ]

I write

node1_a -> node1_b [ dir=none, style=bold ]
node2_a -> node2_b [ dir=none, style=bold ]

node1_a -> node2_b // if I got head and tail right :-)

Although I don't get boxes for my "nodes", this works okay for my purposes.

0

精彩评论

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