Пример #1
0
            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);
                    }
                }
            }