GoLayout and diagram strting point

Hello ,

I posted a question a while a go about the diagram origin and how it shifts down and to the right.
Following your suggestion, I added the following line to my code
[code]
this.methodBuilderView1.DocPosition = new PointF(0F,0F);
[/code]
But still the entire diagram gets shifted to the fight and down.
I noticed however that it does not happen all the time.
It happens when I add a subgraph and specifically it is directly related to the subgrapjh's height.
So going back to the simple application from my yeasterday's post I added a subgraph to it with a large label. the entire application code is below:
[code]using System;
using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using Northwoods.Go; using Northwoods.Go.Layout; namespace WindowsApplication1 { public partial class Form1 : Form { GoLayoutLayeredDigraph layout = new GoLayoutLayeredDigraph(); public Form1() {

InitializeComponent();
layout.Document = goView1.Document;
goView1.Dock = DockStyle.Fill;
goView1.DocPosition = new PointF(0F, 0F);
GoShape s = new GoDiamond();
GoShape s1 = new GoRoundedRectangle();
GoShape s2 = new GoRectangle();

GoTextNode x = new GoTextNode();
x.Background = s;
GoTextNode x1 = new GoTextNode();
x1.Background = s1;
GoTextNode x2 = new GoTextNode();
x2.Background = s2;
GoSubGraph sub = new GoSubGraph();
sub.BorderPen = new Pen(Brushes.Black);

sub.Label.Wrapping = true;
sub.Label.WrappingWidth = 70;
sub.Text = “111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111”;

goView1.Document.Add(x);
goView1.Document.Add(x1);
goView1.Document.Add(x2);
goView1.Document.Add(sub);

GoLink l = new GoLink();
GoLink l1 = new GoLink();
GoLink l2 = new GoLink();
GoLink l3 = new GoLink();
l.FromPort = x.BottomPort;
l.ToPort = x2.TopPort;
goView1.Document.LinksLayer.Add(l);
l1.FromPort = x.RightPort;
l1.ToPort = x1.TopPort;
goView1.Document.LinksLayer.Add(l1);
l2.FromPort = x1.BottomPort;
l2.ToPort = x2.TopPort;

goView1.Document.LinksLayer.Add(l2);
layout.DirectionOption = GoLayoutDirection.Down;
layout.PerformLayout();

}
private void button1_Click(object sender, EventArgs e)
{
layout.Network = null;
layout.PerformLayout();
}
}
}[/code]

If you run that you will notice that the diagram does not start at the upper lft cornet of the document + the margins even though it is set for (0,0). It starts a further down.
If you comment the
[code]
goView1.Document.Add(sub);
[/code]
line then everything works well.
You will notice that bigger the height of the subgraph, more the offset.
I wonder if I am missing something ( very possible) or is that some behaviour to which you know a workaround.
Thanks very much.
Susan

I think it is automatically putting in a margin of LayerSpacing and ColumnSpacing. That’s why the bounds of the laid-out diagram don’t have a (0,0) position.
If you change the LayerSpacing and ColumnSpacing properties to 1, you’ll see the difference. (But note that you can’t set those properties to be non-positive.)

Hi Walter,

I agree that the LayerSpacing and ColumnSpacing should be added to the (0,0) and I am not really looking to start at exactly (0,0);
What I am saying is that as you add subgraphs, the offset moves further to he right and bottom in addition to the LayerSpacing and ColumnSpacing.
If I add a few subgraphs, it actually moves to the bottom of the page.
try the application which I posted in this post and see how the starting position changes if you comment the line which adds the subgraph to the view.
If you take the subgraph out the scrollbar starts at the top.
When you add the subgraph, the scrollbar is already down because the whole diagram has moved.
If you make the subgraph's text smaller (say 123) you won't see that issue.
Thanks for helping me out
Susan

I’m sorry, but everything is working as I would expect, no matter how often I call PerformLayout(), nor how many copies of that odd GoSubGraph there are, nor how much text there is in each GoSubGraph.Label.

If the scrollbars aren't what you expected, perhaps you just want to reset the size of the GoDocument to just fit the laid-out diagram.
goView1.Document.Bounds = goView1.Document.ComputeBounds();
LayoutDemo.DemoView.ZoomToFit does this, for example, and then calls GoView.RescaleToFit().

Hi Walter,

Thanks for the reply.
I added the
goView1.Document.Bounds = goView1.Document.ComputeBounds();
and now it starts exactly at the beginning as we want it to.
Thanks
Susan

Hello Suzi! How did you get all the colors from Visual Studio to show up on your posts? I’m just wondering if there’s an easy way. Thanks!