protected Rectangle GetLinksFullBounds(MindMap map) { if (map == null) { throw new ArgumentNullException(); } Rectangle result = Rectangle.Empty; Link[] lines = map.GetLinks(true); for (int i = 0; i < lines.Length; i++) { Link line = lines[i]; if (line.Visible) { lines[i].RefreshLayout(); Rectangle rect = line.LayoutData.GetFullBounds(); rect.Inflate(10, 10); if (i == 0) { result = rect; } else { result = Rectangle.Union(result, rect); } } } return(result); }
public Size LayoutMap(MindMap map, MindMapLayoutArgs e) { if (map == null) { throw new ArgumentNullException(); } if (map.Root != null) { Rectangle bounds = Layout(map.Root, e); Rectangle linesBounds = GetLinksFullBounds(map); if (!linesBounds.IsEmpty) { bounds = Rectangle.Union(bounds, linesBounds); } // page size var psx = Math.Max(0, (map.PageSize.Width - (bounds.Width + map.Margin.Horizontal)) / 2); var psy = Math.Max(0, (map.PageSize.Height - (bounds.Height + map.Margin.Vertical)) / 2); Offset(map.Root, map.Margin.Left - bounds.X + psx, map.Margin.Top - bounds.Y + psy); // refresh line's layout Link[] lines = map.GetLinks(true); for (int i = 0; i < lines.Length; i++) { lines[i].RefreshLayout(); } bounds.Width += map.Margin.Horizontal; bounds.Height += map.Margin.Vertical; // page size bounds.Width = Math.Max(bounds.Width, map.PageSize.Width); bounds.Height = Math.Max(bounds.Height, map.PageSize.Height); map.LayoutInitialized = true; return(bounds.Size); } else { return(Size.Empty); } }