Confused about Dot Language -- Is this a bug?

I am trying to understand the Dot language semantics. Which attributes go with each node? Which nodes are in each subgraph? Etc. Here are two small examples. They have exactly the same nodes, edges, and subgraphs, declared in the same order. Yet, the nesting of nodes in subgraphs is different!

Each graph has four nodes and three edges.

In the first one, the node A appears by itself in a blue subgraph box. In the second one the nodes A and C, and the edge between them appears in a subgraph box. I expected the structure of these two graphs to be the same.

Is this a bug? I am a bit new to Graphviz, so, I could be confused. Or, perhaps there is a typo that I missed?

BTW, the first example has a lot of "junk" attributes in it -- which should be ignored by Graphviz.

I am using GVEdit version 1.02 and Graphviz version 2.38.0, running on Windows.

For convenience, I've attached the two dot files as "txt".

Thanks very much for your help.

strict digraph foo {
rank=5;
subgraph bop {
graph [rankdir=LR]
edge [color=blue]
color=green
subgraph baz {
node [color=darkgoldenrod4]
rank = same;
graph [rankdir=LR]
yap = fuzz;
shape=triangle;
color=red;
label="fred smith";
B;
C [fontcolor=red];
B->C
};
A [shape=triangle]
}

subgraph cluster_hop {
node [style=bold]
rank=same
A;
C [shape=triangle]
color=blue
}

A -> B ; C -> A
edge [color=red];
D
B->C [color=green]
}

strict digraph foo {
subgraph bop {
subgraph baz {
B
C
B->C
}
A
}

subgraph cluster_hop {
A;
C
}
A->B;
C->A
D
B->C
}

AttachmentSize
foo.txt545 bytes
wrong1.txt165 bytes

Not a bug per se, but a

Not a bug per se, but a limitation in the original ranking algorithm. The original algorithm limited a node from being in two separate constraint classes. In your first example, B, C, and D are put in the rank=same constraint class but C is left out of cluster_hop. On the other hand, A is put in cluster_hop but is left out of the rank=same constraint. (Yes, there should be a warning message.) In the current version of Graphviz, you can specify newrank=true. This will allow nodes to appear in any number of constraint classes unless the constraints are infeasible.

Note that non-cluster subgraphs have no visual effect being providing a local environment for setting default attributes such as rank=same or node[color=blue].

Recent comments