Unbound Node overlapping

Hi Walter,

I am adding a unbound Node programatically and its coming up on the location I am setting to it.
Now the problem I am facing is, if there are multiple unbound nodes, its overlapping on each other.
Also the size(Height and Width) of the unbound node is not fixed. How can I make sure that its not overlapped ?

In general the positioning of nodes is the responsibility of a layout. Do you have a Diagram.Layout?

We have the default Diagram.Layout. We have bound and unbound nodes.
We are adding the unbound nodes to the PartsModel programatically and the bound nodes are binded to Model.

The default layout just makes sure each node has a real location. It’s not very smart about trying to position the nodes, so of course there will be overlaps.

So you might want to use a Diagram.Layout, either an instance of a predefined class or one you define yourself.

Do you mean different layout for bounded and unbounded nodes ?

That’s possible, but by default the Diagram.Layout should operate on all Nodes and Links.

Maybe you want to use GridLayout. Or maybe you want to customize the default DiagramLayout so that it places unlocated nodes where you want them to be. I really can’t tell what you want to do.

Could you please give us a code sample for having multiple Diagram.Layout ? or may be with GridLayout too? I am fine with either of the approaches just that the nodes and unbound nodes should not overlap.

Here’s a simple custom layout that only moves nodes that don’t have a real Position to the right of the rest of the nodes that do have a real position, in a column:

  public class CustomLayout : DiagramLayout {
    public override void DoLayout(IEnumerable<Node> nodes, IEnumerable<Link> links) {
      var maxx = Double.NegativeInfinity;
      var miny = Double.PositiveInfinity;
      foreach (Node n in nodes) {
        if (!Double.IsNaN(n.Bounds.X) && !Double.IsNaN(n.Bounds.Y)) {
          maxx = Math.Max(maxx, n.Bounds.X + n.Bounds.Width);
          miny = Math.Min(miny, n.Bounds.Y);
        }
      }
      if (maxx == Double.NegativeInfinity) maxx = 0;
      if (miny == Double.PositiveInfinity) miny = 0;
      var x = maxx + 50;
      var y = miny;
      var mgr = this.Diagram.LayoutManager;
      foreach (Node n in nodes) {
        if (Double.IsNaN(n.Bounds.X) || Double.IsNaN(n.Bounds.Y)) {
          mgr.MoveAnimated(n, new Point(x, y));
          y += n.Bounds.Height + 50;
        }
      }
    }
  }

If there aren’t any nodes with a real position, then it uses (0,0) as the starting point for the column of unpositioned nodes.