private Size CalculateBoundingBoxes(RadDiagramShape node) { if (!node.HasChildren()) { var size = new Size(node.ActualBounds.Width, node.ActualBounds.Height); this.sizeCache.Add(node.Id, size); return size; } double width = 0; double height = 0; Size shapeBox; var children = GetChildren(node); foreach (var child in children) { shapeBox = this.CalculateBoundingBoxes(child); width += shapeBox.Width; height = Math.Max(height, shapeBox.Height); } width += (children.Count() - 1) * this.HorizontalLevelSeparation; height += this.HorizontalLevelSeparation + node.ActualBounds.Height; shapeBox = new Size(width, height); this.sizeCache.Add(node.Id, shapeBox); return shapeBox; }
private void LayoutShape(RadDiagramShape node, Point point) { if (!node.HasChildren()) { node.Position = new Point(point.X, point.Y); } else { double x, y; Point selfLocation; var boundingBox = this.sizeCache[node.Id]; selfLocation = new Point(point.X + ((boundingBox.Width - node.ActualBounds.Width) / 2), point.Y); node.Position = selfLocation; if (Math.Abs(selfLocation.X - point.X) < Telerik.Windows.Diagrams.Core.Utils.Epsilon) { x = point.X + ((node.ActualBounds.Width - boundingBox.Width) / 2); } else { x = point.X; } var children = GetChildren(node); foreach (var childNode in children) { y = selfLocation.Y + this.VerticalLevelSeparation + node.ActualBounds.Height; var childPoint = new Point(x, y); this.LayoutShape(childNode, childPoint); var size = this.sizeCache[childNode.Id]; x += size.Width + this.HorizontalLevelSeparation; } } }