private static void ApplyShapesLayout(GleeGraph g, Dictionary <string, NodeShape> shapesMap, double graphLeft, double graphTop) { // apply layout information to child shapes foreach (string key in shapesMap.Keys) { NodeShape nodeShape = shapesMap[key]; Node node = g.NodeMap[key]; // appy layout information for shape double shapeTop = (graphTop - node.BBox.Top) + HostMargin; double shapeLeft; if (graphLeft <= 0) { shapeLeft = Math.Abs(graphLeft) + node.BBox.Left + HostMargin; } else { shapeLeft = node.BBox.Left - graphLeft + HostMargin; } if (nodeShape.MovementBehaviour == ShapeMovementBehaviour.PositionOnEdgeOfParent) { if (nodeShape.Parent != null) { nodeShape.SetLocation(NodeShape.CorrectPortLocation(nodeShape.Parent, nodeShape, new PointD(shapeLeft, shapeTop))); } } else { nodeShape.SetLocation(new PointD(shapeLeft, shapeTop)); } } }
private static void SetPortAtFreePositionOnParent(NodeShape shape) { float width = (float)shape.Bounds.Width; float height = (float)shape.Bounds.Height; float parentWidth = (float)shape.Parent.Bounds.Width; float parentHeight = (float)shape.Parent.Bounds.Height; Dictionary <PortPlacement, int> dict = new Dictionary <PortPlacement, int>(); dict.Add(PortPlacement.Left, 0); dict.Add(PortPlacement.Top, 0); dict.Add(PortPlacement.Bottom, 0); dict.Add(PortPlacement.Right, 0); for (int i = 0; i < shape.Parent.RelativeChildren.Count; i++) { if (shape.Parent.RelativeChildren[i] == shape) { continue; } dict[shape.Parent.RelativeChildren[i].PlacementSide]++; } List <KeyValuePair <PortPlacement, int> > myList = new List <KeyValuePair <PortPlacement, int> >(dict); myList.Sort((firstPair, nextPair) => { return(firstPair.Value.CompareTo(nextPair.Value)); }); foreach (KeyValuePair <PortPlacement, int> p in myList) { RectangleF rectH; switch (p.Key) { case PortPlacement.Left: rectH = new RectangleF(-width / 2, 0, width, parentHeight); break; case PortPlacement.Top: rectH = new RectangleF(0, -height / 2, parentWidth, height); break; case PortPlacement.Right: rectH = new RectangleF(parentWidth - width / 2, 0, width, parentHeight); break; case PortPlacement.Bottom: rectH = new RectangleF(0, parentHeight - height / 2, parentWidth, height); break; default: throw new NotSupportedException(); } if (SetPortAtFreePositionOnParent(shape, p.Key, rectH)) { return; } } shape.SetLocation(NodeShape.CorrectPortLocation(shape.Parent, shape, new PointD(0, 0))); }