# How to optimize the edges in some simple situations?

**URL:** <https://forum.graphviz.org/t/how-to-optimize-the-edges-in-some-simple-situations/934>\
**Category:** Help\
**Created:** [December 8, 2021, 9:48am UTC](https://forum.graphviz.org/t/how-to-optimize-the-edges-in-some-simple-situations/934 "2021-12-08T09:48:15Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ichiruchan](https://avatars.discourse-cdn.com/v4/letter/i/c2a13f/32.png) [@Ichiruchan](https://forum.graphviz.org/u/Ichiruchan)\
**Post date:** [December 8, 2021, 9:48am UTC](https://forum.graphviz.org/t/how-to-optimize-the-edges-in-some-simple-situations/934/1 "2021-12-08T09:48:15Z")

</div>

![企业微信截图_95a979d8-96f9-471e-87d2-58d8d7407e8e](https://global.discourse-cdn.com/graphviz/original/1X/8e7fde21c78bfcd6752a92633c840a69b6ab3b9f.png)

As figure 1, this dot file’s **rankdir** is **LR**. Obviously, if the rectangle is moved further down, the edge will become horizontal and more beautiful. Anyway to optimize it ?

 ![situation2](https://global.discourse-cdn.com/graphviz/original/1X/970c2bc6ad13fc29e3e8b40121ea24268499a4eb.png)

As figure 2, the rank assignment has some problem.

---

<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:** [December 8, 2021, 6:03pm UTC](https://forum.graphviz.org/t/how-to-optimize-the-edges-in-some-simple-situations/934/2 "2021-12-08T18:03:04Z")

</div>

please provide your source (preformatted)

---

<div class="post-metadata">

**Author:** ![Ichiruchan](https://avatars.discourse-cdn.com/v4/letter/i/c2a13f/32.png) [@Ichiruchan](https://forum.graphviz.org/u/Ichiruchan)\
**Post date:** [December 9, 2021, 2:10am UTC](https://forum.graphviz.org/t/how-to-optimize-the-edges-in-some-simple-situations/934/3 "2021-12-09T02:10:21Z")

</div>

(post deleted by author)

---

<div class="post-metadata">

**Author:** ![Ichiruchan](https://avatars.discourse-cdn.com/v4/letter/i/c2a13f/32.png) [@Ichiruchan](https://forum.graphviz.org/u/Ichiruchan)\
**Post date:** [December 9, 2021, 2:12am UTC](https://forum.graphviz.org/t/how-to-optimize-the-edges-in-some-simple-situations/934/4 "2021-12-09T02:12:55Z")

</div>

[test.dot](https://forum.graphviz.org/uploads/short-url/dMjK49anzmUI33M3jpkjs5mVjuj.dot) (24.1 KB)

Here is my source dot file. For example, node 33859’s rank is obviously with some errors.

---

<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:** [December 9, 2021, 10:59pm UTC](https://forum.graphviz.org/t/how-to-optimize-the-edges-in-some-simple-situations/934/5 "2021-12-09T22:59:13Z")

</div>

- what release of Graphviz are you using? (type `dot -V` )
- what OS are you using? I’m seeing different results Linux vs. Windows. (Windows producing arguably poorer results)
- I couldn’t recognize any oddities with node 33859 (see below), but I did see odd node placement for a few other nodes (see further below)

All the node placements seem to be “legal”, just not necessarily “pretty”. If a node can “legally” be placed in any of a range of ranks, so be it. **Dot** will pick a rank, but not necessarily the rank you or I would pick.  
However, if you add this (undocumented) graph-level attribute to your graph, the node placement will be more consistent:

```auto
	// TBbalance - undocumented attribute
	// see https://gitlab.com/graphviz/graphviz/-/issues/1339
	TBbalance=min // max is other option

```

TBbalance is only documented here: [Align rank from bottom in dot graph (#1339) · Issues · graphviz / graphviz · GitLab](https://gitlab.com/graphviz/graphviz/-/issues/1339).  
I think it may make you happier.

 ![p1](https://global.discourse-cdn.com/graphviz/original/1X/f5cfc138b9c6159f88bab32e17fef9cf5a9f64a2.png)  
 ![p2](https://global.discourse-cdn.com/graphviz/original/1X/02735201d05ef6216f80b1632c74e0abdeb010d6.png)

---

<div class="post-metadata">

**Author:** ![Ichiruchan](https://avatars.discourse-cdn.com/v4/letter/i/c2a13f/32.png) [@Ichiruchan](https://forum.graphviz.org/u/Ichiruchan)\
**Post date:** [December 13, 2021, 3:01am UTC](https://forum.graphviz.org/t/how-to-optimize-the-edges-in-some-simple-situations/934/6 "2021-12-13T03:01:18Z")

</div>

Actually, i use python sdk for generate dot file and the version of dot is dot - graphviz version 2.49.3 (0).  
My computer’s OS is macOS.  
On my computer, the node 33859 is displayed as follows  
 ![企业微信截图_bd9d0ae0-bd41-4afe-9d95-17a1551a1db7](https://global.discourse-cdn.com/graphviz/original/1X/c844f89709e89f3e7c24c4f7a18c4df7c2dcad6d.png)  
I read the paper how graphviz assign the rank and I think it doesn’t fit the theory. (But, obviously, it is correct on your computer.)  
Thank you very much for answering my question. Next, I will try the new attributs you wrote. Have a nice day.

---

<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:** [December 13, 2021, 4:24pm UTC](https://forum.graphviz.org/t/how-to-optimize-the-edges-in-some-simple-situations/934/7 "2021-12-13T16:24:37Z")

</div>

Curiously inconsistent across computers, OSs, or something.
