9

I am trying to create a flowchart with nodes in set positions. I am using invisible nodes to try and force the direction of edges. My diagram is below. Its not quite right as I am wanting the lines coming out from node d , and around to the edge from c to d to be continuous (and straight).

How can I make it so that the lines all join? Thanks

enter image description here

My code to reproduce

digraph g1 {

  graph [splines=false];

  // invisible nodes
  node[fontsize=15, shape = box, width=3, height=0] ;
  i1 [ style="invis"];
  i2 [ style="invis"];
  i3 [ style="invis"];
  i4 [ style="invis"];

  node[fontsize=15, color = black, shape = box, width=3, height=1] ;
  a[color=blue, label="a"];
  b[color=green, label="b"];
  c[color=orange, label="c"]; 
  d[color=red, label="d"] ;       

  {rank=same; a -> b -> c};

  {rankdir = TB;    c -> i1[arrowhead=none];
        i1 -> d[label="  FOR EACH\n\n"]; 
        d -> i2[arrowhead=none];
  };

  {rank=same; i3 -> i2[arrowhead=none] };

  {rankdir = TB; 
    b -> i4[style="invis"];
    i4 -> i3[arrowhead=none];
  };

  {rank=same; i4 -> i1};

}

Following Paul's comment I tried using node[fontsize=15, shape = box, label="", width=0, height=0, fixedsize=true] which resulted in

enter image description here

4
  • It looks like the invisible nodes' size is causing the arrows to start in "mid-air". I would try something like node[shape = box, width=0, height=0 fixedsize=true] ; for the invisible nodes, but I cannot try it out right now.
    – PaulR
    Sep 22, 2017 at 13:35
  • Thanks @PaulR ; I have edited the question with your suggestion. It seems by setting width and height to zero changes how the nodes are positioned. Sep 22, 2017 at 13:44
  • Ah, I see... Maybe you can use the ranksep attribute with "equally" to influence the spacing.
    – PaulR
    Sep 22, 2017 at 14:02
  • thanks @PaulR, I'll give that a go. Sep 22, 2017 at 14:17

1 Answer 1

15

Using shape = points and minlen comes to the rescue:

digraph g1 {

  graph [splines=false];

  // invisible nodes
  node[ shape = point, width=0, height=0] ;
  i1 [ style="invis"];
  i2 [ style="invis"];
  i3 [ style="invis"];
  i4 [ style="invis"];

  node[fontsize=15, color = black, shape = box, width=3, height=1] ;
  a[color=blue, label="a"];
  b[color=green, label="b"];
  c[color=orange, label="c"]; 
  d[color=red, label="d"] ;       

  {rank=same; a -> b -> c};

  c -> i1[arrowhead=none];
  i1 -> d[label="  FOR EACH\n\n"]; 
  d -> i2[arrowhead=none];

  {rank=same; i3 -> i2[arrowhead=none, minlen = 7 ] };

  b -> i4[style="invis"];
  i4 -> i3[arrowhead=none];

  {rank=same; i4 -> i1};

}

yields

enter image description here

2
  • Thanks vaettchen, looks good. was minlen=7 trail and error please? Sep 22, 2017 at 14:17
  • 1
    Yes it was. It happens to be 3 + 3 + 1 (width of your box times 2, plus 1 space) but not sure whether that's coincidence...
    – vaettchen
    Sep 22, 2017 at 14:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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