Arrow doesn't point to :n

I’m using this code to draw a (part of a) decision diagram. But the arrow to the nodes 3 and 4 doesn’t point to the top. What am I doing wrong?

digraph {
    rankdir="TB"
    splines=ortho

    mehrst [label="2" shape=diamond]
    ohneZ [label="3" shape=diamond]
    mitZ [label="4" shape=diamond]

    mRFegal [label="b" shape=box]
    mRFwichtig [label="c" shape=box]
    oRFegal [label="d" shape=box]
    oRFwichtig [label="e" shape=box]

    {
        rank=same

        mitZ2 [label="" width=0 height=0]
        ohneZ2 [label="" width=0 height=0]

        ohneZ2 -> mehrst [headlabel="ohne Zurücklegen" arrowhead=none minlen=7]
        mehrst -> mitZ2 [taillabel="mit Zurücklegen" arrowhead=none minlen=7]
    }

    ohneZ2 -> ohneZ:n
    mitZ2 -> mitZ:n
    {
        rank=same
        oRFwichtig2 [label="" width=0 height=0]
        oRFegal2 [label="" width=0 height=0]
        mRFwichtig2 [label="" width=0 height=0]
        mRFegal2 [label="" width=0 height=0]

        oRFegal2 -> ohneZ [headlabel="Reihenfolge egal" arrowhead=none minlen=3]
        ohneZ -> oRFwichtig2 [taillabel="Rf. wichtig" arrowhead=none]

        oRFwichtig2 -> mRFegal2 [style=invis]

        mRFegal2 -> mitZ [headlabel="Rf. egal" arrowhead=none]
        mitZ -> mRFwichtig2 [taillabel="Reihenfolge wichtig" arrowhead=none minlen=3]
    }

    mRFwichtig2 -> mRFwichtig
    mRFegal2 -> mRFegal

    oRFwichtig2 -> oRFwichtig
    oRFegal2 -> oRFegal
}

I use dot - graphviz version 2.43.0 (0) and run dot -Tsvg -o /tmp/baum.svg.

[This network graph should be trivial, but none of the Graphviz engines are really designed for flowcharts (or trees). This took some effort]
What did you do wrong: nothing really

  • minlen (minlen | Graphviz) should not apply to nodes in the same rank, it should be a noop.
  • splines=ortho should also be a noop, because all your edges are (supposed to be) straight line segments (more at the bottom)

“Improved” version:

  • changed splines to false
  • tweaked your pseudo-ortho nodes to points. Probably no real change
  • added nodesep attribute (nodesep | Graphviz) to spread the nodes out. Optional
  • used the group attribute (group | Graphviz) to cause vertical edges
  • rearranged the program to make it easier (for me) to read. (I barely read my native language)

(sorry, cut&paste messed up some characters)


digraph {
    rankdir="TB"
    //splines=ortho
    splines=false  // not really using ortho, just straight line segments
    nodesep=.5 // optional
    // added group attributes to try to force vertical lines

    {
        rank=same
        mehrst [label="2" shape=diamond]
        node   [shape=point width=.02 label=""]
        ohneZ2 [group=G1] 
        mitZ2  [group=G2] 
        // why does minlen have an impact here??????
	// minlen is supposed to set distance in units of delta rank
        ohneZ2 -> mehrst [headlabel="ohne Zur??cklegen" arrowhead=none]// minlen=7]
        mehrst -> mitZ2 [taillabel="mit Zur??cklegen" arrowhead=none]// minlen=7]
    }

    {
        rank=same
        ohneZ  [label="3" shape=diamond  group=G1]
        mitZ   [label="4" shape=diamond  group=G2]
	
        node [shape=point width=.02 label=""]
        oRFwichtig2   [group=G6]
        oRFegal2      [group=G5]
        mRFwichtig2   [group=G4]
        mRFegal2      [group=G3]

        oRFegal2 -> ohneZ [headlabel="Reihenfolge egal" arrowhead=none] // minlen=3]
        ohneZ -> oRFwichtig2 [taillabel="Rf. wichtig" arrowhead=none]

        oRFwichtig2 -> mRFegal2 [style=invis]
        mRFegal2 -> mitZ [headlabel="Rf. egal" arrowhead=none]
        mitZ -> mRFwichtig2 [taillabel="Reihenfolge wichtig" arrowhead=none] // minlen=3]
    }
 
    {rank=same
    mRFegal    [label="b" shape=box group=G3]
    mRFwichtig [label="c" shape=box group=G4]
    oRFegal    [label="d" shape=box group=G5]
    oRFwichtig [label="e" shape=box group=G6]
    }

    ohneZ2 -> ohneZ:n 
    mitZ2 -> mitZ:n   

    mRFwichtig2 -> mRFwichtig  
    mRFegal2 -> mRFegal       

    oRFwichtig2 -> oRFwichtig 
    oRFegal2 -> oRFegal       
}

Giving :
edgetoNorth2

p.s. Here is a “true” ortho version & an ugly result:

digraph {
    rankdir="TB"
    splines=ortho

    mehrst [label="2" shape=diamond]
    {
        rank=same
        ohneZ  [label="3" shape=diamond  XXXgroup=G1]
        mitZ   [label="4" shape=diamond  XXXgroup=G2]

        ohneZ -> mitZ  [style=invis]
    }
 
    {rank=same
    mRFegal    [label="b" shape=box XXXgroup=G3]
    mRFwichtig [label="c" shape=box XXXgroup=G4]
    oRFegal    [label="d" shape=box XXXgroup=G5]
    oRFwichtig [label="e" shape=box XXXgroup=G6]
    }

  mehrst:w-> ohneZ:n
  mehrst:e-> mitZ:n

  ohneZ:w-> oRFegal:n
  ohneZ:e-> oRFwichtig:n

  mitZ:w->mRFegal:n
  mitZ:e->mRFwichtig:n

}

Giving:
edgetoNorth3

1 Like