示例#1
0
        ///<summary>
        /// Apply the current settings to the graph.
        ///</summary>
        private async Task ApplyConfigurations()
        {
            IGraph graph = graphControl.Graph;
            // Get the root node of the tree.
            var   graphAdapter = new YGraphAdapter(graph);
            INode root         = graphAdapter.GetOriginalNode(Trees.GetRoot(graphAdapter.YGraph));

            // apply the current setting to all nodes of the same layer.
            ApplySettingsRecursively(graph, root, 0);
            await ApplyLayout();
        }
示例#2
0
        /// <summary>
        /// Creates a large random graph to give the layout algorithms something to chew.
        /// </summary>
        private static void BuildGraph(IGraph graph)
        {
            graph.Clear();
            // Create 400 nodes
            INode[] nodes = new INode[400];
            for (int i = 0; i < nodes.Length; i++)
            {
                nodes[i] = graph.CreateNode();
            }
            // Connect the nodes randomly
            Random random = new Random(0);

            for (int i = 0; i < nodes.Length; i++)
            {
                int edgeCount;
                if (random.Next(10) == 0)
                {
                    edgeCount = 4 + random.Next(5);
                }
                else
                {
                    edgeCount = random.Next(3);
                }
                for (int j = 0; j < edgeCount; j++)
                {
                    graph.CreateEdge(nodes[i], nodes[random.Next(nodes.Length)]);
                }
            }

            // remove all components except the largest one
            var adapter = new YGraphAdapter(graph);

            NodeList[] components = GraphConnectivity.ConnectedComponents(adapter.YGraph);

            Array.Sort(components, (o1, o2) => o2.Count - o1.Count);

            for (int i = components.Length - 1; i > 0; i--)
            {
                foreach (var node in components[i])
                {
                    graph.Remove(adapter.GetOriginalNode(node));
                }
            }

            // add labels
            int count = 0;

            foreach (var node in graph.Nodes)
            {
                graph.AddLabel(node, count++.ToString());
            }
            RandomizeGraph(graph);
        }
示例#3
0
        /// <summary>
        /// Update the node placer configurations in the <see cref="NodePlacerPanel"/>
        /// </summary>
        /// <returns></returns>
        public void UpdatePlacerList()
        {
            IGraph graph = graphControl.Graph;

            // Determine the root node of the tree:
            var   graphAdapter = new YGraphAdapter(graph);
            INode root         = graphAdapter.GetOriginalNode(Trees.GetRoot(graphAdapter.YGraph));

            nodePlacerPanel.NodePlacers.Clear();
            // Fill the Array recursively
            UpdatePlacerListRecursively(graph, placers, nodePlacerPanel.NodePlacers, root, 0);
        }