Aligning subgraphs

Hello,

This graph creates two boxed columns, each with three nodes. However, the tops of the boxes do not align. Can someone offer a suggestion?

digraph default {

// label at top center followed by a blank line

graph [label="Graphviz Chart 3\n\n\n", labelloc=t; labeljust=center, fontname=Helvetica, fontsize=18]
labeljust=center;

ranksep=.5

node [shape="box", style=rounded, fontsize=12 fontname=helvetica];
edge [fontsize=9 fontname=helvetica];

subgraph cluster_0 {
label="EBS";
style="dashed";
Calculate_Options -> Validate_Option [style="invis"];
Validate_Option -> Add_ONC_Pmt [style="invis"];

}
subgraph cluster_1 {
label="Channel";
style="dashed";
Request_Options -> Select_Option [style="invis"];
Select_Option -> Request_ONC [style="invis"];
}

// now create edges between Channel and EBS

Request_Options -> Calculate_Options;
Calculate_Options -> Select_Option;

Select_Option -> Validate_Option;
Validate_Option -> Request_ONC;
Request_ONC -> Add_ONC_Pmt;
}

AttachmentSize
Graphics_Examples_Graphviz_004.png20.18 KB

Hello,   You can also use

Hello,

 

You can also use the constraint option (and invert the order of the clusters).

 

digraph default {
// label at top center followed by a blank line
graph [label="Graphviz Chart 3\n\n\n", labelloc=t; labeljust=center, fontname=Helvetica, fontsize=18]
labeljust=center;
ranksep=.5
node [shape="box", style=rounded, fontsize=12 fontname=helvetica];
edge [fontsize=9 fontname=helvetica];
subgraph cluster_1 {
label="Channel";
style="dashed";
Request_Options -> Select_Option [style="invis"];
Select_Option -> Request_ONC [style="invis"];
}
subgraph cluster_0 {
label="EBS";
style="dashed";
Calculate_Options -> Validate_Option [style="invis"];
Validate_Option -> Add_ONC_Pmt [style="invis"];
}

// now create edges between Channel and EBS
Request_Options -> Calculate_Options [constraint=false];
Calculate_Options -> Select_Option;
Select_Option -> Validate_Option [constraint=false];
Validate_Option -> Request_ONC;
Request_ONC -> Add_ONC_Pmt [constraint=false];
}

The boxes around clusters are

The boxes around clusters are made just large enough to contain the subgraph. If you want the boxes to align, you'll need to add some invisible nodes and edges, like

subgraph cluster_0 {
label="EBS";
style="dashed";
edge[style=invis]
a [style=invis]
a -> Calculate_Options
Calculate_Options -> Validate_Option
Validate_Option -> Add_ONC_Pmt

}
subgraph cluster_1 {
label="Channel";
style="dashed";
edge[style=invis]
Request_Options -> Select_Option
Select_Option -> Request_ONC
b [style=invis]
Request_ONC -> b
}

that did work

Thank you for your advice, erg. It looks better now. Here is what I have now. I think it could look better if, for example, "Failed" was moved up between the two nodes that connect to it. Can that be done?

 

Also, what determines which column comes first?

digraph A {

nodesep=.75 // distance between columns

ranksep=equally // rows spaced equally

rankdir=TB

node [fontsize=10, fontname=arial, width=1.5]

edge [fontsize=9; fontname=arial];

 

subgraph cluster_1{

 

// this will be second column - not sure why yet - will try to pinpoint what determines order of columns

node [shape="diamond", width=1.5];

label="EBS";

style="dashed";

 

// break node labels into two lines since they are long

Calculate_Options [label="Calculate\nOptions"];

Validate_Option [label="Validate\nOption"];

Add_ONC_Pmt [label="Add ONC\nPayment"];

 

// need invisible node (a) at top to align the subgraphs properly

a [style=invis]

 

// make invisible edges between nodes in subgraph to force correct order

a -> Calculate_Options -> Validate_Option -> Add_ONC_Pmt [style="invis"];

}

 

 

subgraph cluster_2 {

node [shape="box", style=rounded];

 

label="Channel";

style="dashed";

 

// need invisible node (b) at bottom to align the subgraphs properly

b [style=invis]

 

// trying to equalize subgraph dotted boxes by making label of b have more lines

b [label=" \n \n \n \n "];

 

// make invisible edges between nodes in subgraph to force correct order

Request_Options -> Select_Option -> Request_ONC -> b [style=invis];

}

 

 

// create the Failed and Succeeded nodes with colors

node [shape="ellipse"];

Failed [style=filled, color="red"];

Succeeded [style=filled, color="green"];

 

 

// now create edges between Channel and EBS

Request_Options -> Calculate_Options -> Failed;

Calculate_Options -> Select_Option;

Select_Option -> Validate_Option -> Failed;

Validate_Option -> Request_ONC ;

Request_ONC -> Add_ONC_Pmt ->"Succeeded";

}

 

 

There are various ways.

There are various ways. Recall two things about dot layouts: nodes lie on discrete ranks and, by default, an edge causes the head node to appear lower than the tail node. The problem of getting what you what with the current graph is that there is no row between Calculate Options and Validate Option for Failed to occupy, and the edge from Validate Option to Failed is going to force the latter node to appear lower than the former. To get around these, we set the default minlen=2 for edges, but set minlen=1 for the edge from Calculate Options to Failed, and turn off the ranking constraint on the edge Validate Option -> Failed by setting constraint=false. This introduces some unnecessary vertical space which can be removed by resetting ranksep. The modified graph is appended below.

digraph A {

nodesep=.75 // distance between columns

/* ranksep=equally // rows spaced equally */
ranksep="0.15 equally"

rankdir=TB

node [fontsize=10, fontname=arial, width=1.5]

edge [minlen=2 fontsize=9; fontname=arial];

 

subgraph cluster_1{

 

// this will be second column - not sure why yet - will try to pinpoint what determines order of columns

node [shape="diamond", width=1.5];

label="EBS";

style="dashed";

 

// break node labels into two lines since they are long

Calculate_Options [label="Calculate\nOptions"];

Validate_Option [label="Validate\nOption"];

Add_ONC_Pmt [label="Add ONC\nPayment"];

 

// need invisible node (a) at top to align the subgraphs properly

a [style=invis]

 

// make invisible edges between nodes in subgraph to force correct order

a -> Calculate_Options -> Validate_Option -> Add_ONC_Pmt [style="invis"];

}

 

 

subgraph cluster_2 {

node [shape="box", style=rounded];

 

label="Channel";

style="dashed";

 

// need invisible node (b) at bottom to align the subgraphs properly

b [style=invis]

 

// trying to equalize subgraph dotted boxes by making label of b have more lines

b [label=" \n \n \n \n "];

 

// make invisible edges between nodes in subgraph to force correct order

Request_Options -> Select_Option -> Request_ONC -> b [style=invis];

}

 

 

// create the Failed and Succeeded nodes with colors

node [shape="ellipse"];

Failed [style=filled, color="red"];

Succeeded [style=filled, color="green"];

// now create edges between Channel and EBS

Request_Options -> Calculate_Options
Calculate_Options -> Failed [minlen=1];

Calculate_Options -> Select_Option;

Select_Option -> Validate_Option
Validate_Option -> Failed [constraint=false];

Validate_Option -> Request_ONC ;

Request_ONC -> Add_ONC_Pmt ->"Succeeded";

}

 

Thanks, and self-learning for Graphviz

Thank you. It is good now.

I have two questions:

1. What determined the order of the subgraphs in my output above?

2. Do you have recommendations about where I can teach myself details about Graphviz - especially with lots of examples?

Thanks!

 

 

Recent comments