"d" "b"->"e" "b"->"" /> "d" "b"->"e" "b"->"" /> "d" "b"->"e" "b"->""/>

Graphviz dot: How to distribute elements evenly?

62 Views Asked by At

I prepared this minimal example (you can try it at http://magjac.com/graphviz-visual-editor/ - not okay):

digraph mydigraph {
  "a"->"d"
  "b"->"e"
  "b"->"f"
  "c"->"g"
}

How can I have the elements in the first row (a, b, c) be distributed evenly? ... and the ones in the second row (d, e, f, g) of course as well?

I tried changing the order of the elements: It is fine, if the two-node elements follow each other (for example http://magjac.com/graphviz-visual-editor/ - okay).

My assumption: The uneven distribution seems to happen only when the three-node element is in the middle. (Yes, I cannot work around the problem by changing the order ...)

2

There are 2 best solutions below

1
sroush On

There is no guarantee of symmetry except by explicitly positioning nodes (https://graphviz.org/faq/#FaqDotWithNodeCoords).

However, putting the three troublesome nodes in a cluster produces this for your minimal example

digraph mydigraph {
  "a"->"d"
  "b"->"e"
  "b"->"f"
  "c"->"g"
  subgraph clusterX{
    peripheries=0  // do not draw box around cluster
    a b c 
  }
}

Giving:
enter image description here

1
sroush On

For a more complex graph, "rotate" the clusters (go vertical)

digraph mydigraph {
  a->d
  b->e
  b->f
  r->s
  r->t
  r->u
  r->v
  c->g
  subgraph clusterXa {
    peripheries=0  // do not draw box around cluster
    a d
  }
  subgraph clusterXb {
    peripheries=0  // do not draw box around cluster
    b e f
  }
  subgraph clusterXr {
    peripheries=0  // do not draw box around cluster
    c g
  }
  subgraph clusterXc {
    peripheries=0  // do not draw box around cluster
    r s t u v
  }
}

Giving:
enter image description here