graphvizdotneato

Set node direction on graphviz


Suppose this code using neato:

graph sample {
  layout=neato
  overlap=false
  splines=true
  tailclip=false
  headclip=false
  A -- I
  A -- J
  A -- B
  A -- H
  A -- E
  A -- K
  B -- D
  B -- C
  B -- L
  C -- M
  C -- N
  C -- O
  D -- P
  D -- Q
  E -- R
  F -- A
  G -- F
  H -- J
}

This gives us this diagram:

neato diagram

What I need is to place a node X, always fixed in a position south from his parent node. i.e. If I put another relation A -- X, X should be always placed south from A. And I don't really care where everything else ends up.

I've looked into the pos attribute, but it doesn't seems to be the solution since X is not really in a fixed position, but on a position relative to his relation.

Also tailport and headport, but they only define from where the edge will come out/in, but don't really affect the direction of the node.

Update

An additional image to make things clearer:

x should be south from his parent

I don't require neato, but I don't want the graph to look like a UD or LR dot tree, I don't want it to be linearly ordered. circo, fdp, sfdp, twopi are alright too.


Solution

  • The neato program supports multiple modes, one of which can probably give you what you want. In particular, if you set mode=ipsep, you can specify dot-like constraints that are honored during the layout. For example, I take your graph and use the graph attributes

    mode=ipsep
    diredgeconstraints=true
    levelsgap=0.5
    

    The first turns on ipsep mode, the second tells the model to support directed edges as in dot, and the last specifies how strong the separation should be. I then set the edge dir attribute to none

    edge[dir=none]
    

    and add an edge A -- X [dir=1]

    The dir=1 indicates this edge should induce a directional constraint. If I then run neato, I get the appended picture.

    neato layout

    The Graphviz attribute documentation http://www.graphviz.org/content/attrs provides more information about these attributes.