Cluster alignment with DOT

[dot verbose=true fit=true]

digraph G {
		rankdir=TB
		node [fontname="Helvetica,Arial,sans-serif"]
		edge [fontname="Helvetica,Arial,sans-serif"]
		graph [fontsize=30 labelloc="t" label="" splines=false ratio = auto]

	subgraph cluster_left {
		style=filled 
		color="#F4F2EE" 
		fontcolor="black" 
		fontsize=36 
		border=0 
		label = "left side nodes"

		//left side nodes
		left1 -> left2 -> left3 [penwidth=3 color=deeppink style=dotted dir=none] //vertical edge lines will be made invisible
/* as soon as theese lines are uncommented, the clusters become twisted up 
		left1->mainA 
		left2->mainD 
		left3->mainD 
*/
	}

	subgraph cluster_main { 
		style=filled 
		color="#F4F2EE" 
		fontcolor="black" 
		fontsize=36 
		border=0 
		label = "main steps and\nrelated side nodes"

		//main steps
		mainA -> mainB -> mainC -> mainD -> mainE [weight=5]

	} //main cluster end

	subgraph cluster_right {
		style=filled 
		color="#F4F2EE" 
		fontcolor="black" 
		fontsize=36 
		border=0 
		label = "right side nodes"

		//right side nodes
		right1 -> right2 -> right3 -> right4 [penwidth=3 color=deeppink style=dotted dir=none] //vertical edge lines will be made invisible
/* as soon as theese lines are uncommented, the clusters become twisted up 
		right1->mainB 
		right2->mainC 
		right3->mainC 
		right4->mainC 
*/
	}
} //graph end

[/dot]

Hello all! I’m trying to achieve what maybe is a simple goal with DOT, but after many attempts using online editors, still cannot do with it.

There is a central cluster of vertical nodes, that acts like a rigid, hard “backbone”, where left and right floating nodes point to.
My example graph shows the nodes, but as soon as I use {rank=same …} and edges (with constraint=false) for aligning and connecting, clusters gex mixed, nodes migrate in unpredictable ways from one cluster to another, and the whole graph becomes messy.
What am I doing wrong?
Many thanks!

  • Not sure why the code displays badly on the web page
  • Moved the cross-cluster edges out of the clusters & to the Root graph
  • Used constraint=false on those edges, to keep the three clusters (reasonably) horizontally aligned
digraph G {
  rankdir=TB
  node [fontname="Helvetica,Arial,sans-serif"]
  edge [fontname="Helvetica,Arial,sans-serif"]
  graph [fontsize=30 labelloc="t" label="" splines=false ratio = auto]

subgraph cluster_left {
	style=filled 
	color="#F4F2EE" 
	fontcolor="black" 
	fontsize=36 
	border=0 
	label = "left side nodes"
	// left side nodes
	// vertical edge lines will be made invisible
	left1 -> left2 -> left3 [penwidth=3 color=deeppink style=dotted dir=none] 
}

subgraph cluster_main { 
	style=filled 
	color="#F4F2EE" 
	fontcolor="black" 
	fontsize=36 
	border=0 
	label = "main steps and\nrelated side nodes"
	//main steps
	mainA -> mainB -> mainC -> mainD -> mainE [weight=5]
} //main cluster end

subgraph cluster_right {
	style=filled 
	color="#F4F2EE" 
	fontcolor="black" 
	fontsize=36 
	border=0 
	label = "right side nodes"
	//right side nodes
	right1 -> right2 -> right3 -> right4 [penwidth=3 color=deeppink style=dotted dir=none]
}
	edge[constraint=false]
        left1->mainA
        left2->mainD
        left3->mainD
	right1->mainB
	right2->mainC
	right3->mainC
	right4->mainC	
}

Giving:

GREAT! Many many thanks for the answer. Now I will study your solution. Thanks again.

F

I took the liberty to edit your post slightly in order for the graph to render inline in the forum.

1 Like

Hello, sure! But it’s due to Steve’s good knowledge, not mine.

Hi, maybe this little sample could be useful for others to see in the Gallery. The nodes in the main area would be more meaningful if shaped as boxes.

F