# How to prevent Graphviz from moving nodes to accomodate an edge

**URL:** <https://forum.graphviz.org/t/how-to-prevent-graphviz-from-moving-nodes-to-accomodate-an-edge/1435>\
**Category:** Help\
**Created:** [January 17, 2023, 10:32pm UTC](https://forum.graphviz.org/t/how-to-prevent-graphviz-from-moving-nodes-to-accomodate-an-edge/1435 "2023-01-17T22:32:28Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![awa5114](https://avatars.discourse-cdn.com/v4/letter/a/d07c76/32.png) [@awa5114](https://forum.graphviz.org/u/awa5114)\
**Post date:** [January 17, 2023, 10:32pm UTC](https://forum.graphviz.org/t/how-to-prevent-graphviz-from-moving-nodes-to-accomodate-an-edge/1435/1 "2023-01-17T22:32:28Z")

</div>

I’m trying to reproduce the following figure using Graphviz:

[![enter image description here](https://global.discourse-cdn.com/graphviz/original/1X/7ee8f8174484730e3564d9ed0eb998e781258267.png)](https://i.stack.imgur.com/aHqsC.png)

Here’s what I came up with so far:

```auto
digraph
{
  rankdir="LR";
  splines=polyline;

  b [shape=circle, label="", style=filled, color=gray, width=0.2, height=0.2];
  c [shape=box, label="C(s)", style=filled, color=gray, xlabel=controller];
  d [shape=box, label="P(s)", style=filled, color=gray, xlabel=plant];
  a [shape=point, color=transparent, label="a"];
  e [shape=point, color=transparent, label="e"];
  f [shape=point, color=transparent, label="f"];

  c -> d [label="u"]
  b -> c [label="e"]
  a -> b [label="r"]
  d -> e [dir=none]
  e -> f [label="y"]
  e -> b
}

```

This gets me close but not quite there yet, as `dot` seems to move the nodes to accomodate the edge from `e` to `b` and not the other way round:

[![enter image description here](https://global.discourse-cdn.com/graphviz/original/1X/6c44fe2fb48fe09a1c58e5bf550d4a7bb8d909da.png)](https://i.stack.imgur.com/N92e3.png)

How do I get it so that the edge from `e` to `b` bends _around_ the nodes rather than displacing them?

---

<div class="post-metadata">

**Author:** ![mark](https://sea2.discourse-cdn.com/graphviz/user_avatar/forum.graphviz.org/mark/32/84_2.png) [@mark](https://forum.graphviz.org/u/mark)\
**Post date:** [January 17, 2023, 11:12pm UTC](https://forum.graphviz.org/t/how-to-prevent-graphviz-from-moving-nodes-to-accomodate-an-edge/1435/2 "2023-01-17T23:12:33Z")

</div>

I think you might be better off trying to use an SVG editor than Graphviz here; Graphviz is really good for when you have a graph and you need a computer to tell you how it should look. If you know how it should look and want the computer to replicate that look, you’re probably better off with the higher control given by SVG.

---

<div class="post-metadata">

**Author:** ![steveroush](https://avatars.discourse-cdn.com/v4/letter/s/a9adbd/32.png) [@steveroush](https://forum.graphviz.org/u/steveroush)\
**Post date:** [January 18, 2023, 12:22am UTC](https://forum.graphviz.org/t/how-to-prevent-graphviz-from-moving-nodes-to-accomodate-an-edge/1435/3 "2023-01-18T00:22:53Z")

</div>

It would help if you explained the isses with the two answers you got from stackoverflow.

---

<div class="post-metadata">

**Author:** ![jjlong](https://sea2.discourse-cdn.com/graphviz/user_avatar/forum.graphviz.org/jjlong/32/887_2.png) [@jjlong](https://forum.graphviz.org/u/jjlong)\
**Post date:** [January 18, 2023, 12:53am UTC](https://forum.graphviz.org/t/how-to-prevent-graphviz-from-moving-nodes-to-accomodate-an-edge/1435/4 "2023-01-18T00:53:16Z")

</div>

You got pretty close. Here is what I came up with.

![graph](https://global.discourse-cdn.com/graphviz/original/1X/7ddc6529561b19f03e81ec44a66e185c6205d18d.png)

With the following source

```plaintext
strict digraph "main"
{
    layout="dot";
    splines="ortho";
    rankdir="TB";
    
    {rank="same"; "b"; "c"; "d"; "a"; "e"; "f";}
    "b"[shape="circle" style="filled" fillcolor="gray" width="0.2" height="0.2" label=""];
    "c"[shape="box" fillcolor="Gray" style="filled" label="C(s)" xlabel="controller"];
    "d"[shape="box" fillcolor="Gray" style="filled" label="P(s)" xlabel="plant"];
    "a"[shape="point" color="transparent" label="a"];
    "e"[shape="point" height="0" width="0" fixedsize="true" label="e"];
    "f"[shape="point" color="transparent" label="f"];
    "c" -> "d"[fontname="italic" label="u"];
    "b" -> "c"[fontname="italic" label="e"];
    "a" -> "b"[fontname="italic" labelfontname="Courier" label="r" headlabel="+"];
    "d" -> "e"[dir="none"];
    "e" -> "f"[fontname="italic" label="y"];
    "e" -> "b"[labeldistance=1.75 labelfontname="Courier" headlabel="-"];
}

```

The main changes are:

1. Changed the direction from `rankdir="LR"` to `rankdir="TB"`
2. Put all the nodes on the same rank using a subgraph.
3. Used `splines="ortho"` instead of `splines="polyline"`
4. Used `headlabel` attributes for the + and - beside the arrowheads, and `labelfontname=Courier"` to make them show up better
5. Used the `labeldistance` attribute to push the - head label away from the arrowhead.

It’s still not completely identical. If you want identical you would have to draw it. In that case I recommend [diagrams.net (aka ‘DrawIO’)](https://app.diagrams.net) which is free, runs in a browser, and lets you save files locally.

Hope this helps

---

<div class="post-metadata">

**Author:** ![scnorth](https://sea2.discourse-cdn.com/graphviz/user_avatar/forum.graphviz.org/scnorth/32/89_2.png) [@scnorth](https://forum.graphviz.org/u/scnorth)\
**Post date:** [January 18, 2023, 4:39pm UTC](https://forum.graphviz.org/t/how-to-prevent-graphviz-from-moving-nodes-to-accomodate-an-edge/1435/5 "2023-01-18T16:39:05Z")

</div>

Interesting. If others agree, we should probably provide this advice in our website. We should probably have an article discussing this situation.

As mentioned, Graphviz was not intended for much fine-tuning. It would be nice if we could at least understand the attachment points in the annotated SVG that can be loaded by inkscape (and probably Illustrator) but someone would have to track down exactly what code should be emitted.
