Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Graphviz: Is there a way to force a node to the bottom?

I'm building a CFG (Context-free grammar), and I'd like the exit node to always be at the bottom of the graph. Sometimes it happens naturally, sometimes it doesn't.

Example:

digraph G {
  0;
  1;
  4;
  5;
  7;
  8;
  0 -> 4;
  5 -> 7;
  7 -> 8;
  7 -> 1;
  8 -> 5;
  4 -> 7;
}

Draws (using dot):

alt text

Node 1 is my exit node, I'd like that to be at the bottom. Suggestions?

like image 334
Paul Biggar Avatar asked Sep 18 '09 19:09

Paul Biggar


People also ask

What is rank in Graphviz?

Ranks and Subgraphs To work out the layout, Graphviz uses a system it calls "ranks". Each node is assigned a higher rank than the highest ranked node that point to it. If your rank direction is set to left to right ( rankdir=LR ), then nodes with a higher rank are placed further to the right.

What is Graphviz Neato?

neato is a reasonable default tool to use for undirected graphs that aren't too large (about 100 nodes), when you don't know anything else about the graph. neato attempts to minimize a global energy function, which is equivalent to statistical multi-dimensional scaling.

What is the use of Graphviz?

Graphviz is an open-source python module that is used to create graph objects which can be completed using different nodes and edges. It is based on the DOT language of the Graphviz software and in python it allows us to download the source code of the graph in DOT language.


1 Answers

Use rank specification for the subgraph. In this case sink should make it at the bottom and max will make it on the same level as 5:

digraph G {
  0;
  { rank = sink; 1; }
  5;
  4;
  7;
  8;
  0 -> 4;
  5 -> 7;
  7 -> 8;
  7 -> 1;
  8 -> 5;
  4 -> 7;
}
like image 112
van Avatar answered Oct 02 '22 10:10

van