public override void ApplyLayout(LayoutGraph graph) { // determine the single node to keep at the center. var provider = graph.GetDataProvider("NodeLayouts"); Node centerNode = null; if (provider != null) { centerNode = graph.Nodes.FirstOrDefault(n => provider.Get(n) != null); } if (CoreLayout != null) { if (centerNode != null) { // remember old center RectD oldLayout = (RectD)provider.Get(centerNode); var fixedLocation = new YPoint(graph.GetX(centerNode) + graph.GetWidth(centerNode), graph.GetY(centerNode)); //Set to saved size (this is important for collapsed nodes to ensure correct size) graph.SetSize(centerNode, oldLayout.Width, oldLayout.Height); // run layout CoreLayout.ApplyLayout(graph); // obtain new center var newFixedLocation = new YPoint(graph.GetX(centerNode) + graph.GetWidth(centerNode), graph.GetY(centerNode)); // and adjust the layout LayoutGraphUtilities.MoveSubgraph(graph, graph.GetNodeCursor(), fixedLocation.X - newFixedLocation.X, fixedLocation.Y - newFixedLocation.Y); } else { CoreLayout.ApplyLayout(graph); } } }
public LayoutGraphPanel(LayoutGraph graph) { if (!GroupingSupport.IsFlat(graph)) { grouping = new GroupingSupport(graph); } this.BackColor = Color.White; this.BorderStyle = BorderStyle.Fixed3D; this.AutoScroll = true; global::yWorks.Algorithms.Geometry.Rectangle2D rect = LayoutGraphUtilities.GetBoundingBox(graph, graph.GetNodeCursor(), graph.GetEdgeCursor()); this.HScroll = true; this.VScroll = true; this.layoutGraph = graph; this.edgePen = new Pen(Brushes.Black, 1); this.nodeBorderPen = new Pen(Brushes.DarkGray, 1); this.labelBorderPen = new Pen(Brushes.Red, 1); this.nodeFillBrush = new SolidBrush(nodeFillColor); this.labelBrush = Brushes.Black; this.labelFont = new Font("sansserif", 6); this.MouseDown += new MouseEventHandler(LayoutGraphPanel_MouseDown); SetWorldRect(rect.X - insets, rect.Y - insets, rect.Width + insets * 2, rect.Height + insets * 2); }