# Graph layout and label spacing for edges

**URL:** https://forum.graphviz.org/t/graph-layout-and-label-spacing-for-edges/1744
**Category:** Help
**Created:** [August 21, 2023, 7:26am UTC](https://forum.graphviz.org/t/graph-layout-and-label-spacing-for-edges/1744 "2023-08-21T07:26:52Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![NandaKumar](https://avatars.discourse-cdn.com/v4/letter/n/58956e/32.png) [@NandaKumar](https://forum.graphviz.org/u/NandaKumar)
#### Post date: [August 21, 2023, 7:26am UTC](https://forum.graphviz.org/t/graph-layout-and-label-spacing-for-edges/1744/1 "2023-08-21T07:26:52Z")

</div>

Hi,

I was working on some graph related work with python modules and i was trying to make some changes to output graph(dot engine) with some layout properties.  
Am getting the following dot graph

 ![image](https://global.discourse-cdn.com/graphviz/original/2X/7/7f8f416971e69bd955247f2e592f34e8b739e96b.jpeg)

I have tried for changing the layout and other programmatically by passing some of these properties:

- overlap = false
- splines = ortho
- rankdir = TB

and my final output as bellow, how can i make it look batter with proper alignment and readable as not able to notice respective edge labels.

 ![image](https://global.discourse-cdn.com/graphviz/original/2X/4/4059c6be5aefbcc31fdaff37b41e6543b5b32c27.png)

---

<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: [August 21, 2023, 8:20am UTC](https://forum.graphviz.org/t/graph-layout-and-label-spacing-for-edges/1744/2 "2023-08-21T08:20:41Z")

</div>

I think you’ve got so many overlapping edges that you’re probably going to struggle in two dimensions. Maybe you could divide your graph up and make graphs of a few different subsets of your graph in separate pictures?

---

<div class="post-metadata">

### Author: ![NandaKumar](https://avatars.discourse-cdn.com/v4/letter/n/58956e/32.png) [@NandaKumar](https://forum.graphviz.org/u/NandaKumar)
#### Post date: [August 21, 2023, 9:05am UTC](https://forum.graphviz.org/t/graph-layout-and-label-spacing-for-edges/1744/3 "2023-08-21T09:05:06Z")

</div>

is there something config which will do it? cause is all depends on the data itself every thing in a flow. Or can you recommend me some sort of properties for dot graph so that my 1st output will align to a structured and organised.

---

<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: [August 21, 2023, 10:04am UTC](https://forum.graphviz.org/t/graph-layout-and-label-spacing-for-edges/1744/4 "2023-08-21T10:04:47Z")

</div>

Fundamentally with everything connected to everything you are going to struggle to make a layout that makes sense.

Maybe you should try a “circo” graph?

[https://graphviz.org/docs/layouts/circo/](https://graphviz.org/docs/layouts/circo/)

---

<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: [August 21, 2023, 1:50pm UTC](https://forum.graphviz.org/t/graph-layout-and-label-spacing-for-edges/1744/5 "2023-08-21T13:50:52Z")

</div>

[In no particular order]

- overlap = false \<\< is ignored by **dot** ( **fdp** & **neato** only) ([overlap | Graphviz](https://graphviz.org/docs/attrs/overlap/))
- rankdir = TB \<\< TB is the default, so this has no impact
- Flowchart convention puts _start_ at the top and _end_ at the bottom. Easiest way to do this is to insert them into subgraphs with **rank=source** and **rank=sink** ([rank | Graphviz](https://graphviz.org/docs/attrs/rank/))
- if you want to continue with **ortho** , you might try **shape=square** to increase the size of the nodes, to help spread the edge landing points
- All of the edges are time-related. You might consider rewriting this as a timeline (countdown in this case) (see [Using Graphviz / yed to produce a timeline + graph - Stack Overflow](https://stackoverflow.com/questions/61550137/using-graphviz-yed-to-produce-a-timeline-graph/61552544#61552544))

---

<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: [August 22, 2023, 1:00am UTC](https://forum.graphviz.org/t/graph-layout-and-label-spacing-for-edges/1744/6 "2023-08-22T01:00:28Z")

</div>

In addition to the advice from @steveroush, in no particular order:

- Use a fixed node size for all nodes.
- Split the node labels on to multiple lines, allowing a narrower node.
- Use `taillabel` instead of `label` for edges when `splines=ortho`.
- Set tail label font name to `Arial` using `labelfontname="Arial"`
- Set tail label font size to something smaller using `labelfontsize=10`
- Use `labeldistance` attribute to move the tail label position.
- Use smaller arrowheads on edges using `arrowsize=0.5`
- Spread the nodes out horizontally and vertically a bit using `nodesep=0.625` and `ranksep=0.625`

Here is the results I came up with:

 ![gvforum](https://global.discourse-cdn.com/graphviz/original/2X/7/7c8e63687be3b318ba6463085d0d5416b453d850.png)

Here is the source for the diagram

```plaintext
strict digraph "main"
{
    layout="dot";
    splines="ortho";
    imagepath="C:\rv";
    
    node[shape=rect height=1 width=1 fixedsize=true];
    edge[arrowsize="0.5" fontname="Arial" labelfontname="Arial" labelfontsize="10"];
    nodesep=".625"
    ranksep=".625"
    { rank="source"; "start";}
    "start"[shape="octagon" height="1" width="1" fixedsize="True" fillcolor="Blue4" peripheries="2" fontname="Arial" fontcolor="White" style="filled" label="Start"];
    { rank="sink"; "end";}
    "end"[shape="octagon" height="1" width="1" fixedsize="True" fillcolor="Blue4" peripheries="2" fontname="Arial" fontcolor="White" style="filled" label="End"];
    "start" -> "invoice date"[penwidth=2 taillabel="1 Day"];
    "first discount available date"[label="First\nDiscount\nAvailable\nDate"];
    "first discount available date" -> "invoice release date"[labeldistance=3 taillabel="15 Day(s)"];
    "first discount available date" -> "payment due date"[penwidth=2];
    "first discount available date" -> "second discount available date"[labeldistance=2 taillabel="10 Day(s)"];
    "first discount available date" -> "invoice creation date"[labeldistance=1 taillabel="6 Day(s)"];
    "invoice creation date"[label="Invoice\nCreation\nDate"];
    "invoice creation date" -> "first discount available date";
    "invoice creation date" -> "invoice hold date";
    "invoice creation date" -> "invoice approval creation date"[taillabel="1 Min(s)"];
    "invoice creation date" -> "payment date";
    "invoice creation date" -> "end";
    "invoice approval creation date"[label="Invoice\nApproval\nCreation\nDate"];
    "invoice approval creation date" -> "payment due date"[taillabel="29 Days"];
    "invoice approval creation date" -> "invoice approval creation date"[taillabel="1 Hr(s)"];
    "invoice hold date"[label="Invoice\nHold\nDate"];
    "invoice hold date" -> "invoice hold date"[taillabel="2 Day(s)"];
    "invoice hold date" -> "invoice release date"[taillabel="3 Day(s)"];
    "invoice hold date" -> "first discount available date"[taillabel="7 Day(s)"];
    "invoice hold date" -> "second discount available date"[taillabel="6 Day(s)"];
    "invoice hold date" -> "payment due date"[penwidth=2 taillabel="24 Day(s)"];
    "invoice hold date" -> "end";
    "payment due date"[label="Payment\nDue\nDate"];
    "payment due date" -> "payment date"[taillabel="4 Day(s)"];
    "payment due date" -> "invoice creation date"[penwidth=2 taillabel="25 Day(s)"];
    "payment due date" -> "invoice release date"[taillabel="7 Day(s)"];
    "payment due date" -> "end";
    "invoice release date"[label="Invoice\nRelease\nDate"];
    "invoice release date" -> "payment due date"[taillabel="7 Day(s)"];
    "invoice release date" -> "first discount available date"[taillabel="15 Day(s)"];
    "invoice release date" -> "end";
    "payment date"[label="Payment\nDate"];
    "payment date" -> "invoice date"[color=gray taillabel="0 Sec"];
    "payment date" -> "second discount available date"[taillabel="7 Day(s)"];
    "payment date" -> "third discount available date"[taillabel="8 Day(s)"];
    "payment date" -> "payment due date"[penwidth=2 taillabel="23 Day(s)"];
    "payment date" -> "end";
    "second discount available date"[label="Second\nDiscount\nAvailable\nDate"];
    "second discount available date" -> "third discount available date"[taillabel="10 Day(s)"];
    "second discount available date" -> "payment date"[taillabel="1 Day(s)"];
    "invoice date"[label="Invoice\nDate"];
    "invoice date" -> "first discount available date"[labeldistance=1 taillabel="10 Day(s)"];
    "invoice date" -> "payment date"[labeldistance=2 taillabel="14 Day(s)"];
    "invoice date" -> "invoice creation date"[labledistance=3 color=gray taillabel="1 Day(s)"];
    "invoice date" -> "payment due date"[labeldistance=4 color=gray taillabel="2 Day(s)"];
    "third discount available date"[label="Third\nDiscount\nAvailable\nDate"];
    "third discount available date" -> "payment due date"[penwidth=2 taillabel="1 Mo"];
}

```

---

<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: [August 22, 2023, 1:13am UTC](https://forum.graphviz.org/t/graph-layout-and-label-spacing-for-edges/1744/7 "2023-08-22T01:13:10Z")

</div>

@mark Here is how `circo` rendered the diagram using the Graphviz source in my earlier post.

 ![gvforum_circo](https://global.discourse-cdn.com/graphviz/original/2X/7/78262c13c54f778952c4a40d4b7a11f6f9f49de2.png)

---

<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: [August 22, 2023, 2:19am UTC](https://forum.graphviz.org/t/graph-layout-and-label-spacing-for-edges/1744/8 "2023-08-22T02:19:30Z")

</div>

Yeah with circo i would probably turn off the rectinlinear lines

---

<div class="post-metadata">

### Author: ![NandaKumar](https://avatars.discourse-cdn.com/v4/letter/n/58956e/32.png) [@NandaKumar](https://forum.graphviz.org/u/NandaKumar)
#### Post date: [August 22, 2023, 7:09am UTC](https://forum.graphviz.org/t/graph-layout-and-label-spacing-for-edges/1744/9 "2023-08-22T07:09:50Z")

</div>

Thanks @jjlong, @steveroush  
will work around the graph as per your instructions and let you guys know…

---

<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: [August 22, 2023, 11:24am UTC](https://forum.graphviz.org/t/graph-layout-and-label-spacing-for-edges/1744/10 "2023-08-22T11:24:52Z")

</div>

Here is what it looks like with the `splines` attribute removed.

 ![gvforum_circo_nosplines](https://global.discourse-cdn.com/graphviz/original/2X/c/c7bd67e33a8944b4a202f9eaa90ff5d5b9a3757c.png)
