Nodes.Visible = false and GoDocument.TopLeft

Hi Northwoods,

in my app, a network diagram is being generated and displayed. The end user cannot add nor delete nodes.
We know how many layers are in the network, and so derived from GoLayoutLayeredDigraph
to assign a specific layer to a specific type of hardware (e.g., router).
Sometimes we cannot find what should fall into a layer, and so skip that node. We do however , want the link to span the missing node, and want the nodes to show in the right layer.
A <-> B <-> C
B' <-> C'
So , above has 3 layers, and 3 columns, right?
Sometimes we only know "B" and "C" , so we want the diagram to look like
B <- > C
now there are only 2 layers. Since "A" is missing.
It can get complicated, e.g., if
A <------- > C
B'< --->C''
In order to create the layers and get the right value for "MaxLayer" , I'm creating nodes and links and setting Visible to false.
However the GoDocument's TopLeftPosition now seems to be shifting.
I want the Visible nodes to always appear at Location (20, 20)
goView1.DocPosition = new PointF(20F, 20F);
How can I
a) either specify the MaxLayers for the document such that I don't have to create dummy/invisible nodes
b) tell GoDocument to ignore the invisible nodes when computing the DocPosition, such that it looks like the Visible nodes always start at
new PointF(20F, 20F); code to create dummy nodes to set maxlayer (e.g., to 3:
GoTextNode gn = null; GoTextNode gnPrev = null;
for (int i = 0; i < 3; i++)
{ gnPrev = gn; gn = new GoTextNode(); gn.Text = "basic " + i; goView1.Document.Add(gn); gn.Visible = false; // we don't want to see it, just use it if (gnPrev != null) { GoLabeledLink gl = new GoLabeledLink(); gl.FromPort = gnPrev.Ports.Last; gl.ToPort = gn.Ports.First; gl.ToArrow = true; goView1.Document.LinksLayer.Add(gl); gl.Visible = false; // we don't want to see it, just use it } }
Addendum / More Info:
the GoView is being re-used, i.e., there's a selection list ,
when the selection is changed, the code calls
and reshows the GoView with the new data.
I've noticed that the Y offset problem happens after the goView has been reused one time (i.e., the goView has nodes, the nodes are cleared, then new nodes are added).

You can create dummy nodes (GoLayoutLayeredDigraphNode) in the GoLayoutLayeredDigraphNetwork before you call to perform the layout.

Look for the phrase “dummy node” in the FamilyTree sample.

To review the possibilities:
(a) create dummy GoNodes that are not Visible, as you have shown
(b) create dummy GoLayoutLayeredDigraphNodes in the GoLayoutLayeredDigraphNetwork, as Jake mentions
© if you know there aren’t any nodes in the third layer (containing "A"s), you could set the ArrangementOrigin point to be further to the right, maybe to (100, 0). Set GoView.DocPosition to (0, 0) in either case.

thanks Walter and Jake,

the sample from FamilyTree tree provided a good solution (create GoLayoutLayeredDigraphNetwork nodes)