Search code examples
graphvizdot

Is there a way to have different edge splines between nodes in the same cluster vs between nodes in different clusters using fdp layout in graphviz?


I am creating a graph with multiple clusters. There are edges between nodes belonging to the same cluster, and edges between nodes belonging to different clusters. I am using fdp layout. Is there a way to have one type of edge routing for nodes within a cluster, and another type of edge routing for nodes belonging to different clusters?

For example, I would like to use splines=ortho for the former, and splines=compound for the latter. I tried doing just that, but it appears that the generated graph just uses the splines value specified in the main graph.


Solution

  • I am pretty sure it can't be done with a single pass - splines is a graph-level attribute. However I think it could be done with a 5-pass technique:

    1. edit the input file
    • move all intra-cluster edges inside the cluster
    • add edge[keep=1] to the beginning of each cluster
    1. run fdp -Tdot -Gsplines=ortho (applies to all) to add node & edge routing
    2. run step 1 output through gvpr (or python?) to
    • pin all nodes node[pin=true] at the beginning of the graph
    • for every edge where keep==1, copy pos attribute to (new) keeppos attribute
    1. run step 2 output through fdp -s -Tdot -Gsplines=compound - this will overwrite all edge pos values
    2. run step 3 output through gvpr (or python?) to replace pos with keeppos (if keeppos!="")
    3. run step 4 output through neato -s -n2 -Tsvg/png/...

    Whew! Sounds gross, but it seems to work
    p.s. -s option is needed on steps 3 and 5 to fix scaling issues
    p.p.s. because pinning nodes is required, fdp and neato only (not dot)

    Here is a command line:

    f=multispline.gv;
    F=`basename $f .gv`
    fdp -Gsplines=true -Tdot $f | 
    gvpr -c 'N{pin="true"}E[keep=="1"]{keeppos=$.pos}'| 
    fdp -s -Gsplines=ortho -Tdot | 
    gvpr -c 'E[keeppos!=""]{pos=keeppos}' | 
    neato -s -n2 -Tsvg >oo.svg