Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a very simple graph:

digraph G {
  "for" -> "initial assignment"
  "initial assignment" -> "condition"
  "condition" -> "code" [color=red]
  "condition" -> "end" [color=red]
  "code" -> "final assignment" [color=red]
  "final assignment" -> "condition" [color=red]
}

See output

However, the nodes must be drawn in a specific order, from top to bottom. (The red arrows would be red because they defy this specific order.)

One way to do so is:

digraph G {

  {rank = same; "$1"; "for"}
  {rank = same; "$2"; "initial assignment"}
  {rank = same; "$3"; "condition"}
  {rank = same; "$4"; "final assignment"}
  {rank = same; "$5"; "code"}
  {rank = same; "$6"; "end"}

  "$1" -> "$2" -> "$3" -> "$4" -> "$5" -> "$6"    

  "for" -> "initial assignment"
  "initial assignment" -> "condition"
  "condition" -> "code" [color=red]
  "condition" -> "end" [color=red]
  "code" -> "final assignment" [color=red]
  "final assignment" -> "condition" [color=red]

}

See output

However, this displays those extra nodes on the graph, and I'd rather not have that. How can I define nodes and edges without having them drawn?

(I could define the edges to be white, the node text to be white, etc., but graphviz would still allocate space for them and this wouldn't work on transparent png images. Also, layers don't work for all output formats such as .png and the space required for these nodes is still allocated. Let's not consider these solutions.)

share|improve this question

2 Answers 2

Why not using the nodes themselves for suggesting a specific ordering?

digraph G
{
  {
    edge[style=invis]

    a[label="for"]
    b[label="initial assignment"]
    c[label="condition"]
    d[label="final assignment"]
    e[label="code"]
    f[label="end"]

    a -> b -> c -> d -> e -> f
  }

  a -> b -> c
  c -> e [color=red]
  c -> f [color=red]
  e -> d -> c [color=red]
}
share|improve this answer
    
This does do the trick in this simple case. :) –  badp Feb 26 '12 at 12:44

Stephen North, author of Graphviz, suggests using [style=invis]:

digraph G {

  {
    node [style=invis]
    edge [style=invis]
    "$1" -> "$2" -> "$3" -> "$4" -> "$5" -> "$6"    
  }

  {rank = same; "$1"; "for"}
  {rank = same; "$2"; "initial assignment"}
................................................................................

output

This doesn't fully solve the problem as space is still allocated for those bits and pieces, but I have to guess it's as good as it gets.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.