graphviz: direction of edges in terms of color

Puneet picture Puneet · Nov 23, 2010 · Viewed 8.9k times · Source

Hi
Can I get graphviz to color the edges in a way that identifies the direction? For example, the part of the edge near its source node might be blue and then it gradually shades away to red as it nears the target node. Or are there any other graphing tools (like graphviz) that can do this?

Any help in this regard would be much appreciated.

Answer

doug picture doug · Dec 5, 2010

Well, i don't know anything about your current dot file, so i'll have to make a couple of assumptions. To deal with the easy case first, distinguishing the the direction of an edge is the job of the arrowhead (points to) and arrowtail (points from). Your graph is only going to render those if your graph type is a directed graph, which you set at the top of your dot file, e.g.,

digraph G {
    node[style=filled, color=cornflowerblue, fontcolor=white, fontsize=10, 
          fontname='Helvetica']
    edge[arrowhead=vee, arrowtail=inv, arrowsize=.7, color=maroon, fontsize=10,
          fontcolor=navy]

    a1 -> a2;
    a2 -> a4 [taillabel="TL     "];
    a2 -> a5 [headlabel="       HL"];
    a4 -> a6 [label="  ordinary edge label"]
}

If you've already crated a directed graph but for some reason you want an additional indicator to show edge direction, then the only relevant edge attributes i can think of are the headlabel and taillabel attributes, which allows you to specify which end of an edge a label is placed. The small dot file above will render this graph:

alt text