示例#1
0
        /// <summary>
        /// Renders nodes and links and adds them to the global variables.
        /// </summary>
        public void RenderGraphs()
        {
            Hashtable Graphs     = GlobalVariables.Graphnodes;
            Hashtable nodesToAdd = new Hashtable();
            Hashtable linksToAdd = new Hashtable();
            int       graphCount = Graphs.Count;

            for (int k = 1; k <= graphCount; k++)
            {
                Hashtable Graph = (Hashtable)Graphs[k];

                foreach (DictionaryEntry node in Graph)
                {
                    Node n = (Node)node.Value;

                    List <Link> adjacentLinks = n.AdjacentLinks;

                    Object nodeObject = InstantiateNode(n);

                    if (!nodesToAdd.ContainsKey(nodeObject.name))
                    {
                        nodesToAdd.Add(nodeObject.name, nodeObject);
                    }

                    foreach (Link adjacentLink in adjacentLinks)
                    {
                        Node sourceNode = (Node)Graph[adjacentLink.Source];
                        if (n.Id == sourceNode.Id)
                        {
                            Node targetNode = (Node)Graph[adjacentLink.Target];

                            if (sourceNode != targetNode)
                            {
                                Object edgeObject = InstantiateLink(adjacentLink, sourceNode, targetNode);
                                if (!linksToAdd.ContainsKey(adjacentLink.Id))
                                {
                                    linksToAdd.Add(adjacentLink.Id, edgeObject);
                                }
                            }
                        }
                    }
                }
                nodeCount.text = "Nodes: " + nodesToAdd.Count;
                edgeCount.text = "Links: " + linksToAdd.Count;
                GlobalVariables.AddRenderedGraphNodes(nodesToAdd);
                GlobalVariables.AddRenderedGraphLinks(linksToAdd);
            }
        }