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

einpoklum
  • 118,144
  • 57
  • 340
  • 684
user2957945
  • 2,353
  • 2
  • 21
  • 40
  • 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 '17 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. – user2957945 Sep 22 '17 at 13:44
  • Ah, I see... Maybe you can use the [ranksep](http://www.graphviz.org/doc/info/attrs.html#d:ranksep) attribute with "equally" to influence the spacing. – PaulR Sep 22 '17 at 14:02
  • thanks @PaulR, I'll give that a go. – user2957945 Sep 22 '17 at 14:17

1 Answers1

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

vaettchen
  • 7,299
  • 22
  • 41