Automatically separate nodes based on link width


I have an evaluation version of GoDiagram that uses GoIconicNode objects linked using GoLabeledLink objects. To create a lable for our GoLabledLink objects I am usng a GoText object and assigning this to its MidLabel property.

My problem is: if the text on the link is long then I would like the nodes to automaticaly be spaced apart or the link to autosize its width so the link's midlabel text fits within the nodes and does not run over the outer edge of the nodes.

For the GoText object I am setting the following properties:

text.FontSize = 8;

text.Text = LinkLabel;

text.Multiline = true;

text.AutoResizes = true;

text.AutoRescales = true;

text.Alignment = GOTEXT_ALIGN_CENTRE;

for the GoLabeledLink I am setting the following properties:

link.MidLabel = text;

link.FromArrow = false;

link.ToArrow = false;

link.FromPort = fromNode.Port;

link.ToPort = toNode.Port;

link.MidLabelCentered = true

Thanks for your help.

Are you using one of the automatic Layout methods?


<w:LatentStyles DefLockedState=“false” LatentStyleCount=“156”>
</><![endif]–><!–[if gte mso 10]>
/* Style Definitions */
{mso-style-name:“Table Normal”;
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
font-family:“Times New Roman”;



I am using the GoLayoutLayeredDigraph object. See code below.

GoLayoutLayeredDigraph layout = new GoLayoutLayeredDigraph();

layout.Document = goView.Document;

layout.DirectionOption = GoLayoutDirection.Right;


You’ll want to override GoLayoutLayeredDigraph.NodeMinLayerSpace to return a larger value.

Here’s the default definition:

protected virtual float NodeMinLayerSpace(GoLayoutLayeredDigraphNode node, bool topleft) { if (node.GoObject == null) return 0; RectangleF r = node.Bounds; SizeF p = node.Focus; switch (this.DirectionOption) { case GoLayoutDirection.Up: case GoLayoutDirection.Down: if (topleft) return p.Height+10; else return r.Height-p.Height+10; default: case GoLayoutDirection.Left: case GoLayoutDirection.Right: if (topleft) return p.Width+10; else return r.Width-p.Width+10; } }
Of course if you know that the DirectionOption is always toward the Right, you can simplify this code.

In your case you’ll want to look at the links coming in (if topleft) or going out (if not topleft) to see if there is a link label, and if so if half its width is wider than half the GoLayoutLayeredDigraph.LayerSpacing plus the 10 as shown above.