# Graph formatting (1. Centralising clusters, 2. Avoiding edge intersections)

**URL:** https://forum.graphviz.org/t/graph-formatting-1-centralising-clusters-2-avoiding-edge-intersections/2274
**Category:** Help
**Created:** [June 18, 2024, 3:31am UTC](https://forum.graphviz.org/t/graph-formatting-1-centralising-clusters-2-avoiding-edge-intersections/2274 "2024-06-18T03:31:42Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![nwl](https://avatars.discourse-cdn.com/v4/letter/n/45deac/32.png) [@nwl](https://forum.graphviz.org/u/nwl)
#### Post date: [June 18, 2024, 3:31am UTC](https://forum.graphviz.org/t/graph-formatting-1-centralising-clusters-2-avoiding-edge-intersections/2274/1 "2024-06-18T03:31:42Z")

</div>

Hi all, I have 2 questions regarding the formatting of the graph shown below.

 ![example](https://global.discourse-cdn.com/graphviz/original/2X/f/fd0c8a6e551a54b4378654ce92b81ef5ad966e45.png)

1. I would like to ask if it is possible to centralise the clusters as shown in the photo below?  

2. Also, may I ask how I should avoid situations that create unnecessary edge intersections such as the photo shown below?  

Thanks!

---

<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: [June 18, 2024, 12:29pm UTC](https://forum.graphviz.org/t/graph-formatting-1-centralising-clusters-2-avoiding-edge-intersections/2274/2 "2024-06-18T12:29:01Z")

</div>

Can you provide your source?

---

<div class="post-metadata">

### Author: ![nwl](https://avatars.discourse-cdn.com/v4/letter/n/45deac/32.png) [@nwl](https://forum.graphviz.org/u/nwl)
#### Post date: [June 19, 2024, 2:08am UTC](https://forum.graphviz.org/t/graph-formatting-1-centralising-clusters-2-avoiding-edge-intersections/2274/3 "2024-06-19T02:08:54Z")

</div>

Hi @steveroush ,

```auto
digraph {
	0	[label="ab685dac-53c6-47cb-bd8c-2b763154df49"];
	26	[label="8b80a59b-abc1-4500-8b21-d6a6ae5ad4eb"];
	0 -> 26;
	1	[label="b2db2a05-f586-4efb-a023-bd18b8e4eec2"];
	25	[label="de774b1c-42bd-449c-8bdf-d7cefc7d34d2"];
	1 -> 25;
	2	[label="72d56c0f-b11b-4c1b-bcb7-c9649e8cd912"];
	24	[label="5ba9993d-8ca6-409b-8cbb-1abe0e4ef752"];
	2 -> 24;
	3	[label="c14de66d-016d-4dee-ab85-a2e9b60fb941"];
	3 -> 25;
	4	[label="ca1406f6-e620-4b5c-96d6-36fce47d6120"];
	4 -> 26;
	5	[label="d5e6e0cb-04c7-46a4-939b-9638b79e02b6"];
	5 -> 24;
	6	[label="27d8c5ed-f557-4641-b6c5-96d09347ff69"];
	6 -> 26;
	7	[label="ca3b038b-ee3a-4558-afb8-cd7626512bbb"];
	7 -> 24;
	8	[label="49051dd6-3456-44da-9d9c-51bdca652acb"];
	8 -> 0;
	9	[label="466a93ed-588d-44e6-966d-8f0304be3568"];
	9 -> 1;
	10	[label="521fc552-6948-40a0-9d61-372c187157a2"];
	10 -> 2;
	11	[label="d651a156-472e-4030-bb3f-2b61ed67d295"];
	11 -> 5;
	12	[label="3cdd3cb7-0aa6-4af4-95c7-cade81be64da"];
	12 -> 4;
	13	[label="f1e2a1c3-eb78-45fb-a716-12f8788005fe"];
	13 -> 3;
	14	[label="55c5f279-2394-436a-a373-b45258b21128"];
	23	[label="f43d97b9-02c2-410c-b33e-7081dee090c6"];
	14 -> 23;
	15	[label="9874fc36-0d76-402c-b4e1-426616a9a844"];
	21	[label="82033c6f-6784-4354-b5dd-3f1af1eb0af7"];
	15 -> 21;
	16	[label="6778506b-2879-402e-8fb2-16a181c93de6"];
	22	[label="e8045cab-1313-4aed-8ae2-9c175f3907be"];
	16 -> 22;
	17	[label="37ff8002-058e-450e-b28d-2249562f1507"];
	20	[label="04806d6c-be6f-4389-83e3-e39776973c8d"];
	17 -> 20;
	18	[label="117a7813-bb9e-4d24-8409-d09cca3d10de"];
	19	[label="f4dba1f3-634a-47ab-8300-c973f23258f8"];
	18 -> 19;
	35	[label="1b8b6543-5562-4af7-96cd-f71175201429"];
	19 -> 35;
	34	[label="6294b6e8-de49-439b-9379-dc7978268865"];
	20 -> 34;
	33	[label="a0eda76b-2874-4e97-930f-d8269068e0a4"];
	21 -> 33;
	32	[label="6de9478b-e6dc-4e10-99a6-6b033c4caae5"];
	22 -> 32;
	36	[label="e401e6f1-6e08-46b2-b91c-3c29c345c76b"];
	23 -> 36;
	24 -> 15;
	24 -> 18;
	25 -> 16;
	26 -> 14;
	26 -> 17;
	27	[label="e66806e0-d2d7-4eaa-a241-871cab284c95"];
	29	[label="3fb89e3f-2b29-4f89-93e2-49e07e82fad9"];
	27 -> 29;
	28	[label="56bc7363-aaf5-48a5-b946-8db8903240f7"];
	28 -> 12;
	29 -> 11;
	30	[label="6b2dff82-a9b6-4449-89cf-1536063ba786"];
	30 -> 11;
	31	[label="c60891bf-763e-4ea4-b21b-4c6536ee7735"];
	31 -> 13;
	37	[label="d3cd3893-7001-41f8-ae68-41bda9bf1f0d"];
	32 -> 37;
	40	[label="f8db0486-c942-4ea2-bac0-da8332766c19"];
	33 -> 40;
	39	[label="c201ce38-babb-48dd-83e6-32d5d7e68885"];
	34 -> 39;
	41	[label="9b304aa8-9306-43f7-a9ba-3f33078bebed"];
	35 -> 41;
	38	[label="f84613f4-5899-4cbf-bc37-6b11efe6bfa1"];
	36 -> 38;
	51	[label="8f0fdf07-5c63-4fd5-b5c7-aadaf387cdfe"];
	37 -> 51;
	52	[label="82b75274-aaae-4d9f-b8e5-e96ab13fd428"];
	38 -> 52;
	53	[label="66fd5c05-b7df-4c8e-bdd7-745af447fdc4"];
	39 -> 53;
	50	[label="56387a03-fb26-49a5-893b-2e1965e564b2"];
	40 -> 50;
	54	[label="cb063cea-03e5-45dd-9743-6364fea3bce3"];
	41 -> 54;
	42	[label="a9933610-96f8-482a-9f15-2c5a3ec04e26"];
	46	[label="d204956a-0fc8-430e-9abd-37e25f240358"];
	42 -> 46;
	47	[label="3e26c35d-eaed-4cbe-9937-879ded6a30f4"];
	42 -> 47;
	48	[label="d587ca6d-621b-4d6f-881e-684a83c000d2"];
	42 -> 48;
	43	[label="d70d9f7f-f1af-47ef-8653-3b8e7220adf8"];
	43 -> 28;
	43 -> 30;
	44	[label="3830528e-9d99-468d-8e9f-b46b84dbe564"];
	44 -> 31;
	45	[label="996c17d4-f300-44f9-acc3-1cba4b94fd4a"];
	45 -> 6;
	45 -> 7;
	46 -> 45;
	47 -> 43;
	48 -> 44;
	49	[label="65462aed-928c-481d-ab7b-f49c3d04f1c8"];
}

```

[dot]  
digraph {  
0 [label=“ab685dac-53c6-47cb-bd8c-2b763154df49”];  
26 [label=“8b80a59b-abc1-4500-8b21-d6a6ae5ad4eb”];  
0 → 26;  
1 [label=“b2db2a05-f586-4efb-a023-bd18b8e4eec2”];  
25 [label=“de774b1c-42bd-449c-8bdf-d7cefc7d34d2”];  
1 → 25;  
2 [label=“72d56c0f-b11b-4c1b-bcb7-c9649e8cd912”];  
24 [label=“5ba9993d-8ca6-409b-8cbb-1abe0e4ef752”];  
2 → 24;  
3 [label=“c14de66d-016d-4dee-ab85-a2e9b60fb941”];  
3 → 25;  
4 [label=“ca1406f6-e620-4b5c-96d6-36fce47d6120”];  
4 → 26;  
5 [label=“d5e6e0cb-04c7-46a4-939b-9638b79e02b6”];  
5 → 24;  
6 [label=“27d8c5ed-f557-4641-b6c5-96d09347ff69”];  
6 → 26;  
7 [label=“ca3b038b-ee3a-4558-afb8-cd7626512bbb”];  
7 → 24;  
8 [label=“49051dd6-3456-44da-9d9c-51bdca652acb”];  
8 → 0;  
9 [label=“466a93ed-588d-44e6-966d-8f0304be3568”];  
9 → 1;  
10 [label=“521fc552-6948-40a0-9d61-372c187157a2”];  
10 → 2;  
11 [label=“d651a156-472e-4030-bb3f-2b61ed67d295”];  
11 → 5;  
12 [label=“3cdd3cb7-0aa6-4af4-95c7-cade81be64da”];  
12 → 4;  
13 [label=“f1e2a1c3-eb78-45fb-a716-12f8788005fe”];  
13 → 3;  
14 [label=“55c5f279-2394-436a-a373-b45258b21128”];  
23 [label=“f43d97b9-02c2-410c-b33e-7081dee090c6”];  
14 → 23;  
15 [label=“9874fc36-0d76-402c-b4e1-426616a9a844”];  
21 [label=“82033c6f-6784-4354-b5dd-3f1af1eb0af7”];  
15 → 21;  
16 [label=“6778506b-2879-402e-8fb2-16a181c93de6”];  
22 [label=“e8045cab-1313-4aed-8ae2-9c175f3907be”];  
16 → 22;  
17 [label=“37ff8002-058e-450e-b28d-2249562f1507”];  
20 [label=“04806d6c-be6f-4389-83e3-e39776973c8d”];  
17 → 20;  
18 [label=“117a7813-bb9e-4d24-8409-d09cca3d10de”];  
19 [label=“f4dba1f3-634a-47ab-8300-c973f23258f8”];  
18 → 19;  
35 [label=“1b8b6543-5562-4af7-96cd-f71175201429”];  
19 → 35;  
34 [label=“6294b6e8-de49-439b-9379-dc7978268865”];  
20 → 34;  
33 [label=“a0eda76b-2874-4e97-930f-d8269068e0a4”];  
21 → 33;  
32 [label=“6de9478b-e6dc-4e10-99a6-6b033c4caae5”];  
22 → 32;  
36 [label=“e401e6f1-6e08-46b2-b91c-3c29c345c76b”];  
23 → 36;  
24 → 15;  
24 → 18;  
25 → 16;  
26 → 14;  
26 → 17;  
27 [label=“e66806e0-d2d7-4eaa-a241-871cab284c95”];  
29 [label=“3fb89e3f-2b29-4f89-93e2-49e07e82fad9”];  
27 → 29;  
28 [label=“56bc7363-aaf5-48a5-b946-8db8903240f7”];  
28 → 12;  
29 → 11;  
30 [label=“6b2dff82-a9b6-4449-89cf-1536063ba786”];  
30 → 11;  
31 [label=“c60891bf-763e-4ea4-b21b-4c6536ee7735”];  
31 → 13;  
37 [label=“d3cd3893-7001-41f8-ae68-41bda9bf1f0d”];  
32 → 37;  
40 [label=“f8db0486-c942-4ea2-bac0-da8332766c19”];  
33 → 40;  
39 [label=“c201ce38-babb-48dd-83e6-32d5d7e68885”];  
34 → 39;  
41 [label=“9b304aa8-9306-43f7-a9ba-3f33078bebed”];  
35 → 41;  
38 [label=“f84613f4-5899-4cbf-bc37-6b11efe6bfa1”];  
36 → 38;  
51 [label=“8f0fdf07-5c63-4fd5-b5c7-aadaf387cdfe”];  
37 → 51;  
52 [label=“82b75274-aaae-4d9f-b8e5-e96ab13fd428”];  
38 → 52;  
53 [label=“66fd5c05-b7df-4c8e-bdd7-745af447fdc4”];  
39 → 53;  
50 [label=“56387a03-fb26-49a5-893b-2e1965e564b2”];  
40 → 50;  
54 [label=“cb063cea-03e5-45dd-9743-6364fea3bce3”];  
41 → 54;  
42 [label=“a9933610-96f8-482a-9f15-2c5a3ec04e26”];  
46 [label=“d204956a-0fc8-430e-9abd-37e25f240358”];  
42 → 46;  
47 [label=“3e26c35d-eaed-4cbe-9937-879ded6a30f4”];  
42 → 47;  
48 [label=“d587ca6d-621b-4d6f-881e-684a83c000d2”];  
42 → 48;  
43 [label=“d70d9f7f-f1af-47ef-8653-3b8e7220adf8”];  
43 → 28;  
43 → 30;  
44 [label=“3830528e-9d99-468d-8e9f-b46b84dbe564”];  
44 → 31;  
45 [label=“996c17d4-f300-44f9-acc3-1cba4b94fd4a”];  
45 → 6;  
45 → 7;  
46 → 45;  
47 → 43;  
48 → 44;  
49 [label=“65462aed-928c-481d-ab7b-f49c3d04f1c8”];  
}  
[/dot]

This is the output from the anonymizer program provided previously.

Thanks.

---

<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: [June 19, 2024, 5:02am UTC](https://forum.graphviz.org/t/graph-formatting-1-centralising-clusters-2-avoiding-edge-intersections/2274/4 "2024-06-19T05:02:55Z")

</div>

Not sure which anonymizer you used (please point to it), but it seems that there is no anonymizer that handles clusters.  
Phooey!

Until a useful anonymizer appears, we will try to move forward.

- There is no graph-level or cluster-level attribute that means “line clusters symmetrically”. It is very difficult to adjust cluster positions. (it would be a nice enhancement)
- Neither is there a way to tell **dot** “be extra careful about node & edge placement” (another nice enhancement)
- However, the **group** attribute ([group | Graphviz](https://graphviz.org/docs/attrs/group/)) might help sweet-talk nodes into alignment and then the clusters that contain them. At this moment I don’t remember if **group** works across clusters. Also, **group** is easier to apply manually than programmatically.
- Another way to align clusters would be to pad them with invisible nodes (ugh, not my first choice)
- Just remembered: **osage** see: [Is there a way to draw "desks" (2 boxes side by side and 2 below them) without using arrows on graphviz?](https://forum.graphviz.org/t/is-there-a-way-to-draw-desks-2-boxes-side-by-side-and-2-below-them-without-using-arrows-on-graphviz/1987)  
and  
[How can I center nodes in a Graphviz cluster? - #5 by steveroush](https://forum.graphviz.org/t/how-can-i-center-nodes-in-a-graphviz-cluster/2020/5)
- Side note: have you tried other **spline** types? That wouldn’t rearrange the clusters or nodes, but might help the edge intersections.

---

<div class="post-metadata">

### Author: ![nwl](https://avatars.discourse-cdn.com/v4/letter/n/45deac/32.png) [@nwl](https://forum.graphviz.org/u/nwl)
#### Post date: [June 19, 2024, 9:12am UTC](https://forum.graphviz.org/t/graph-formatting-1-centralising-clusters-2-avoiding-edge-intersections/2274/5 "2024-06-19T09:12:27Z")

</div>

Hi @steveroush,

I tried using splines ortho and it seems to give cleaner results.

 ![example4](https://global.discourse-cdn.com/graphviz/original/2X/6/6b9882722c3cc2d7537f1a70fb823ad27ace1d14.png)

However, situations like these occur in which the edge runs parallel too close to the node. How should I prevent this?

 ![example3](https://global.discourse-cdn.com/graphviz/original/2X/1/123b042e1898701ccbbca4d3ad0e45d18e7ee0e4.png)  
 ![example5a](https://global.discourse-cdn.com/graphviz/original/2X/6/6d72b2a14679bb505ef22bec9e7650e53d755343.png)

And although this is a small issue, the lines leave a small gap and do not touch the nodes at the end.

 ![example3a](https://global.discourse-cdn.com/graphviz/original/2X/0/0fe50c3f062b98862c777bbf2be6f0bab61d2f57.png)

Thanks.

---

<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: [June 19, 2024, 12:39pm UTC](https://forum.graphviz.org/t/graph-formatting-1-centralising-clusters-2-avoiding-edge-intersections/2274/6 "2024-06-19T12:39:44Z")

</div>

[whine, we really need to get a more useful anonymizer. By eyeball:]

- **ortho** is a bit of a problem child. Maybe try increasing **nodesep** and **ranksep** to give the **ortho** router more room to work in. And you might try increasing **margin** at the cluster-level.
- not sure about the gaps at the end of the arrowheads. There have been improvements in that code fairly recently, what version of **Graphviz** are you using? (type `dot -V`)

---

<div class="post-metadata">

### Author: ![smattr](https://sea2.discourse-cdn.com/graphviz/user_avatar/forum.graphviz.org/smattr/32/85_2.png) [@smattr](https://forum.graphviz.org/u/smattr)
#### Post date: [June 19, 2024, 10:44pm UTC](https://forum.graphviz.org/t/graph-formatting-1-centralising-clusters-2-avoiding-edge-intersections/2274/7 "2024-06-19T22:44:21Z")

</div>

> [@steveroush](#):
>
> we really need to get a more useful anonymizer

If you create a Gitlab issue describing the requirements, we can probably implement such a thing within Graphviz itself. If the basic operation is “rename all entities”, should be trivial. Though I am not sure how to deal with renamed labels affecting layout.

---

<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: [June 19, 2024, 10:50pm UTC](https://forum.graphviz.org/t/graph-formatting-1-centralising-clusters-2-avoiding-edge-intersections/2274/8 "2024-06-19T22:50:22Z")

</div>

I agree. My attempt became quicksand.  
The killer problems were HTML & Record labels - both the text & the port names.  
And there are probably more issues lurking in the corners.

---

<div class="post-metadata">

### Author: ![nwl](https://avatars.discourse-cdn.com/v4/letter/n/45deac/32.png) [@nwl](https://forum.graphviz.org/u/nwl)
#### Post date: [June 20, 2024, 2:21am UTC](https://forum.graphviz.org/t/graph-formatting-1-centralising-clusters-2-avoiding-edge-intersections/2274/9 "2024-06-20T02:21:31Z")

</div>

1. This is the anonymizer I’m using.

> <https://gitlab.com/graphviz/graphviz/-/blob/main/cmd/gvpr/lib/anon>

1. This is the graphviz version - 9.0.0 (20230911.1827). I’m actually using the python api.  
[API Reference — graphviz 0.20.3 documentation](https://graphviz.readthedocs.io/en/stable/api.html)

2. Regarding the small gap between the edges and the node, I’ve realised that its because of the default node margin value which also affects the head and tails of edges. The gap disappears when setting node margin to (0, 0). I did not encounter this problem previously as I was able to set ports for the nodes despite setting margin. However, ports do not work with ortho and I removed ports, resulting in the problem surfacing.

This is when the margin is set to (0, 0).

 ![example6a](https://global.discourse-cdn.com/graphviz/original/2X/4/44ed25718ae54d72cb130988dd74ed228c8a49bc.png)

This is when the margin is set to (1, 1).

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

I was wondering if the above 2 problems could be resolved if the node margin could be set to (0,0) without affecting the heads and tails of edges (although I’m not sure how to achieve that)?

Thanks
