1
Vote

AutoLayout

description

Autolayout isn't working right.
Checking the code I almost made it done, but there some issues that I can't find yet.
 
1) For not connected "shapes", lower the horizontal/vertical gap
2) For connected shapes, use the following code (near line 136 of Graph.cs):
 
        foreach (List<Node> linearNodes in LinearNodeLists)
        {
            yl = y;
 
            for (var CT = 0; CT < linearNodes.Count; CT++)
            {
                var node = linearNodes[CT];
                var height = CT > 0 ? linearNodes[CT - 1].Bounds.Height + 2 : 0;
 
                node.Bounds.X = x * 30;
                node.Bounds.Y = (y * 30) + yl * height;
                yl += Math.Max((int)node.Bounds.Height / 20, 1);
            }
 
            x++;
            maxY = Math.Max(yl, maxY);
        }
 
Where:
 
linearNodes[CT - 1] should be the connected shape, so we can get the current height of connected shape and add to "this" shape, plus a small vertical gap. With just 2 shapes connected works fine, but when we add some others, linearNodes[CT - 1] no longers points to the correct connected shape.
 
Also, CT > 0 ? linearNodes[CT - 1].Bounds.Height + 2 : 0; where 2 should be maybe the grid spacing, so is the vertical gap in the connected shapes. The grid spacing should be the gapping for every autolayout, so the user could control how the autolayout is done.

comments