Graphviz : Ordering node in a cluster

2.4k views Asked by At

I'm working on an auto-generated Graphviz (so it need to be a general solution, not for this particular example). It draws the topology of a network. but the results inside the cluster don't look organised.

Here is the topology:

enter image description here

Here is the associed code :

digraph G {

splines=polyline;

subgraph cluster_sh5sl8 {
    style=filled;
    color=lightgrey;
    node [style=filled,color=white];
    sh5sl8_L1 [label = "L1"];
    label = "5/8";
}
subgraph cluster_sh5sl10 {
    style=filled;
    color=lightgrey;
    node [style=filled,color=white];
    sh5sl10_L1 [label = "L1"];
    label = "5/10";
}
subgraph cluster_sh5sl12 {
    style=filled;
    color=lightgrey;
    node [style=filled,color=white];
    sh5sl12_L1 [label = "L1"];
    label = "5/12";
}
subgraph cluster_sh5sl14 {
    style=filled;
    color=lightgrey;
    node [style=filled,color=white];
    sh5sl14_L1 [label = "L1"];
    label = "5/14";
}
subgraph cluster_sh5sl16 {
    style=filled;
    color=lightgrey;
    node [style=filled,color=white];
    sh5sl16_L1 [label = "L1"];
    label = "5/16";
}
subgraph cluster_sh6sl3 {
    style=filled;
    color=lightgrey;
    node [style=filled,color=white];
    sh6sl3_L1 [label = "L1"];
    label = "6/3";
}
subgraph cluster_sh6sl8 {
    style=filled;
    color=lightgrey;
    node [style=filled,color=white];
    sh6sl8_L1 [label = "L1"];
    label = "6/8";
}
subgraph cluster_sh6sl10 {
    style=filled;
    color=lightgrey;
    node [style=filled,color=white];
    sh6sl10_L1 [label = "L1"];
    label = "6/10";
}
subgraph cluster_sh6sl12 {
    style=filled;
    color=lightgrey;
    node [style=filled,color=white];
    sh6sl12_L1 [label = "L1"];
    label = "6/12";
}
subgraph cluster_sh6sl14 {
    style=filled;
    color=lightgrey;
    node [style=filled,color=white];
    sh6sl14_L1 [label = "L1"];
    label = "6/14";
}
subgraph cluster_sh6sl16 {
    style=filled;
    color=lightgrey;
    node [style=filled,color=white];
    sh6sl16_L1 [label = "L1"];
    label = "6/16";
}
subgraph cluster_sh30sl1 {
    rank=same;
    style=filled;
    color=lightgrey;
    node [style=filled,color=white];
    sh30sl1_9600 [label = "9600"]; sh30sl1_9590 [label = "9590"]; sh30sl1_9580 [label = "9580"]; sh30sl1_9570 [label = "9570"]; sh30sl1_9560 [label = "9560"]; sh30sl1_9280 [label = "9280"]; sh30sl1_9270 [label = "9270"]; sh30sl1_9260 [label = "9260"]; sh30sl1_9250 [label = "9250"]; sh30sl1_9220 [label = "9220"]; sh30sl1_9190 [label = "9190"]; sh30sl1_OMD [label = "OMD"];
    label = "30/1";
}

sh30sl1_9570 -> sh5sl8_L1;
sh30sl1_9560 -> sh5sl10_L1;
sh30sl1_9280 -> sh5sl12_L1;
sh30sl1_9270 -> sh5sl14_L1;
sh30sl1_9260 -> sh5sl16_L1;
sh30sl1_9220 -> sh6sl3_L1;
sh30sl1_9250 -> sh6sl8_L1;
sh30sl1_9190 -> sh6sl10_L1;
sh30sl1_9600 -> sh6sl12_L1;
sh30sl1_9590 -> sh6sl14_L1;
sh30sl1_9580 -> sh6sl16_L1;
sh6sl12_L1 -> sh30sl1_9600;
sh6sl14_L1 -> sh30sl1_9590;
sh6sl16_L1 -> sh30sl1_9580;
sh5sl8_L1 -> sh30sl1_9570;
sh5sl10_L1 -> sh30sl1_9560;
sh5sl12_L1 -> sh30sl1_9280;
sh5sl14_L1 -> sh30sl1_9270;
sh5sl16_L1 -> sh30sl1_9260;
sh6sl8_L1 -> sh30sl1_9250;
sh6sl3_L1 -> sh30sl1_9220;
}

Note that I'm using FDP, but I can use anything else if it works. Currently, FDP gives me the best results.

How can I order this?

I already tried with clusterrank, ranksep, nodesep, constraint=false, or call them in another order, etc. I tried create un inivible node and link every other node inside a cluster to make them equidistant, but it didn't work.

1

There are 1 answers

1
Wolfgang Fahl On BEST ANSWER

I do not have an answer yet that would work with generated results- I have a similar issue where I can modify the graphviz file myself:

with

<graphviz>
  digraph hierachy {
    rankdir="LR"
    graph [ordering="out"];
    subgraph cluster_Hierachie {
      label="Hierachie"
      n0 
      n10000 
      n20000 
      n30000 
      n40000 
      n50000 
      n0->n10000
      n0->n20000
      n0->n30000
      n0->n40000
      n0->n50000
   }
  }
</graphviz>

which is rendered as: enter image description here

and so far found the following links:

please note the different suggestions on how to specify "ordering=out"

digraph g {
  ordering=out ;

or

digraph bt {
  graph [ordering="out"];

none of these work for me although https://stackoverflow.com/a/9169194/1497139 got 1 upvote and https://stackoverflow.com/a/9168680/1497139 has 2 upvotes

http://www.graphviz.org/content/ordering-edges suggests to use

rank=same

so I tried:

<graphviz>
  digraph hierachy {
    rankdir="LR"
    graph [ordering="out"];

    subgraph cluster_Hierachie {
      label="Hierachie"
      n0 
      n10000 
      n20000 
      n30000 
      n40000 
      n50000 
      n0->n10000
      n0->n20000
      n0->n30000
      n0->n40000
      n0->n50000
      {
        rank=same;n0;n10000;n20000;n30000;n40000;n50000
      }
   }

  }
</graphviz>

which renders as: enter image description here

http://www.graphviz.org/content/cluster-changes-nodes-order

suggests to add

style=invis
{  rank=same  0 -- 1 [style=invis]
}

nodes. I tried that to no avail and ended up doing

<graphviz>
  digraph hierachy {
    rankdir="LR"
    graph [ordering="out"];

    subgraph cluster_Hierachie {
      label="Hierachie"
      n0 
      n10000 
      n20000 
      n30000 
      n40000 
      n50000 
      n0->n50000
      n0->n40000
      n0->n30000
      n0->n20000
      n0->n10000
   }
  }
</graphviz>

which renders as: enter image description here

which I consider to be a valid work-around given the strange behavior of reverse ordering in clusters.