Пример #1
0
        private GraphModel GraphSetup()
        {
            GraphDB db    = new GraphDB();
            var     graph = new GraphModel();

            //get all the nodes
            foreach (var node in db.Nodes)
            {
                var dataVertex = new DataVertex()
                {
                    ID = node.Id, Text = node.label
                };
                graph.AddVertex(dataVertex);
                nodeList.Add(node.Id, node.label);
            }

            var vlist = graph.Vertices.ToList();

            //add all the edges
            foreach (var node in vlist)
            {
                Dictionary <int, int> edges = new Dictionary <int, int>();
                foreach (var edge in db.Edges.Where(x => x.FromNode == node.ID))
                {
                    var dataEdge = new DataEdge(node, vlist[vlist.FindIndex(x => x.ID == edge.ToNode)]);
                    graph.AddEdge(dataEdge);
                    edges.Add(edge.ToNode, 1);
                }

                vertices.Add(node.ID, edges);
            }

            return(graph);
        }
Пример #2
0
        public void Execute(object parameter)
        {
            MouseButtonEventArgs e = parameter as MouseButtonEventArgs;
            Canvas c = e.Device.Target as Canvas;

            if (c != null)
            {
                Point p = e.GetPosition(c);
                GraphModel.SelectVertices(p.X, p.Y);
                GraphModel.AddVertex(p.X, p.Y);
                GraphModel.LeftMouseDragStart(p.X, p.Y);
            }
        }
Пример #3
0
        private GraphModel GraphSetup()
        {
            GraphDB db = new GraphDB();
            var graph = new GraphModel();

            //get all the nodes
            foreach (var node in db.Nodes)
            {
                var dataVertex = new DataVertex() { ID = node.Id, Text = node.label };
                graph.AddVertex(dataVertex);
                nodeList.Add(node.Id,node.label);
            }

            var vlist = graph.Vertices.ToList();

            //add all the edges
            foreach (var node in vlist)
            {
                Dictionary<int,int> edges =  new Dictionary<int, int>();
                foreach (var edge in db.Edges.Where(x => x.FromNode == node.ID))
                {
                    var dataEdge = new DataEdge(node, vlist[vlist.FindIndex(x => x.ID == edge.ToNode)]);
                    graph.AddEdge(dataEdge);
                    edges.Add(edge.ToNode,1);
                }

                vertices.Add(node.ID,edges);

            }

            return graph;
        }