Exemplo n.º 1
0
        private GraphExample GenerateTestGraph()
        {
            var graph = new GraphExample();
            var v1    = new DataVertex()
            {
                Text = "Test1", ID = 1
            };

            graph.AddVertex(v1);
            var v2 = new DataVertex()
            {
                Text = "Test2", ID = 2
            };

            graph.AddVertex(v2);
            var v3 = new DataVertex()
            {
                Text = "Test3", ID = 3
            };

            graph.AddVertex(v3);
            var v4 = new DataVertex()
            {
                Text = "Test4", ID = 4
            };

            graph.AddVertex(v4);

            graph.AddEdge(new DataEdge(v1, v2, 100));
            graph.AddEdge(new DataEdge(v2, v3, 100));
            graph.AddEdge(new DataEdge(v2, v4, 100));
            return(graph);
        }
Exemplo n.º 2
0
        public static GraphExample Example2()
        {
            var graph = new GraphExample();

            // 1. add vertexes
            var vertices = new[]
            {
                new DataVertex(1),
                new DataVertex(2),
                new DataVertex(3),
                new DataVertex(4),
            };

            // 2. add edges
            graph.AddVertex(vertices[0]);
            graph.AddVertex(vertices[1]);
            graph.AddVertex(vertices[2]);

            graph.AddEdge(new DataEdge(vertices[0], vertices[1]));
            graph.AddEdge(new DataEdge(vertices[1], vertices[2]));
            graph.AddEdge(new DataEdge(vertices[2], vertices[0]));

            graph.AddVerticesAndEdge(new DataEdge(vertices[2], vertices[3]));

            return(graph);
        }
Exemplo n.º 3
0
        public GraphExample Graph_Setup(string FOCUS = "")
        {
            if (Produit.GrandeurPhysiques == null)
                return null;

            var dataGraph = new GraphExample();
            if (FOCUS == "FOCUS")
            {
                foreach (var GP in Produit.GrandeurPhysiques)
                {
                    if (GP.Value.Selectionne)
                    {
                        var dataVertex = new DataVertex(GP.Key);
                        dataGraph.AddVertex(dataVertex);
                    }
                }  
            }
            else
            {
              foreach (var GP in Produit.GrandeurPhysiques)
                {
                    //if (GP.Value.EstPremier)
                    //{
                        var dataVertex = new DataVertex(GP.Key);
                        dataGraph.AddVertex(dataVertex);
                    //}
                }  
            }
            
            //Now lets make some edges that will connect our vertices
            //get the indexed list of graph vertices we have already added
            var vlist = dataGraph.Vertices.ToList();
            var dataEdge = new DataEdge(); //= new DataEdge(vlist[0], vlist[1]);
            //dataGraph.AddEdge(dataEdge);
            foreach (var R1 in vlist)
            {
                foreach (var R2 in vlist)
                {
                    if (Relation.MatriceRelations[Produit.GrandeurPhysiques[R1.Text].iM][
                            Produit.GrandeurPhysiques[R2.Text].iM] != null)
                        if (Relation.MatriceRelations[Produit.GrandeurPhysiques[R1.Text].iM][
                            Produit.GrandeurPhysiques[R2.Text].iM] !=1 -1)
                            {
                                dataEdge = new DataEdge(R1, R2);
                                dataGraph.AddEdge(dataEdge);
                            }
               }
            }

            return dataGraph;
        }
Exemplo n.º 4
0
        public static GraphExample GenerateGraphUI <T>(NGramGraphMarkovChain <T> markovChain)
            where T : IEquatable <T>
        {
            var dataGraph = new GraphExample();

            Dictionary <NGram <T>, int> indices = new Dictionary <NGram <T>, int>();
            int i = 0;

            foreach (var item in markovChain)
            {
                var dataVertex = new DataVertex(NGramHelper.ShowNGram <T>(item.Key.AsEnumerableObject()))
                {
                    ID = i
                };
                dataGraph.AddVertex(dataVertex);
                indices.Add(item.Key, i);
                i++;
            }
            var vlist = dataGraph.Vertices.ToList();

            foreach (var item in markovChain)
            {
                foreach (var edge in item.Value)
                {
                    var dataEdge = new DataEdge(vlist[indices[item.Key]], vlist[indices[edge.Edge]], edge.Probability)
                    {
                        Text = edge.Probability.ToString()
                    };
                    dataGraph.AddEdge(dataEdge);
                }
            }

            return(dataGraph);
        }
Exemplo n.º 5
0
        private GraphExample GenerateGraph()
        {
            var dataGraph = new GraphExample();

            foreach (var node in nodeCollection.Nodes)
            {
                var dataVertex = new DataVertex(node.name);
                nodeCollection.getNodeByName(node.name).vertex = dataVertex;
                dataGraph.AddVertex(dataVertex);
            }

            DataEdge dataEdge;

            var vlist = dataGraph.Vertices.ToList();

            //Then create two edges optionaly defining Text property to show who are connected
            for (int i = 0; i < nodeCollection.Nodes.Count; i++)
            {
                if (nodeCollection.Nodes[i].neighborsCollection.Nodes.Count > 0)
                {
                    foreach (var neighbor in nodeCollection.Nodes[i].neighborsCollection.Nodes)
                    {
                        dataEdge = new DataEdge(vlist[i], vlist[nodeCollection.getIndexByName(neighbor.node.name)])
                        {
                            Text = neighbor.jarak.ToString()
                        };
                        dataGraph.AddEdge(dataEdge);

                        neighbor.edge = dataEdge;
                    }
                }
            }

            return(dataGraph);
        }
Exemplo n.º 6
0
        private GraphExample GraphExample_Setup()
        {
            var dataGraph = new GraphExample();

            for (int i = 1; i < 100; i++)
            {
                var dataVertex = new DataVertex(i.ToString());
                dataGraph.AddVertex(dataVertex);
            }


            var vlist = dataGraph.Vertices.ToList();

            Random Rand = new Random();

            foreach (var item in vlist)
            {
                if (Rand.Next(0, 50) > 25)
                {
                    continue;
                }
                var vertex2 = vlist[Rand.Next(0, dataGraph.VertexCount - 1)];
                dataGraph.AddEdge(new DataEdge(item, vertex2, Rand.Next(1, 50))
                {
                    Text = $"{item} -> {vertex2}"
                });
            }


            return(dataGraph);
        }
Exemplo n.º 7
0
        private GraphExample GenerateGraph()
        {
            //FOR DETAILED EXPLANATION please see SimpleGraph example project
            var dataGraph = new GraphExample();

            for (int i = 1; i < 10; i++)
            {
                var dataVertex = new DataVertex("MyVertex " + i);
                dataGraph.AddVertex(dataVertex);
            }
            var vlist = dataGraph.Vertices.ToList();
            //Then create two edges optionaly defining Text property to show who are connected
            var dataEdge = new DataEdge(vlist[0], vlist[1])
            {
                Text = string.Format("{0} -> {1}", vlist[0], vlist[1])
            };

            dataGraph.AddEdge(dataEdge);
            dataEdge = new DataEdge(vlist[2], vlist[3])
            {
                Text = string.Format("{0} -> {1}", vlist[2], vlist[3])
            };
            dataGraph.AddEdge(dataEdge);


            dataEdge = new DataEdge(vlist[2], vlist[2])
            {
                Text = string.Format("{0} -> {1}", vlist[2], vlist[2])
            };
            dataGraph.AddEdge(dataEdge);
            return(dataGraph);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Generate example graph data
        /// </summary>
        /// <param name="count">Items count</param>
        private GraphExample GenerateDataGraph(int count)
        {
            var graph = new GraphExample();

            foreach (var item in DataSource.Take(count))
            {
                graph.AddVertex(new DataVertex(item.Text)
                {
                    ID = item.ID
                });
            }

            var vlist = graph.Vertices.ToList();

            /*graph.AddEdge(new DataEdge(vlist[0], vlist[3], 1));
            *  graph.AddEdge(new DataEdge(vlist[1], vlist[4], 1));
            *  graph.AddEdge(new DataEdge(vlist[2], vlist[5], 1));*/
            var cnt = 1;

            foreach (var item in vlist)
            {
                if (Rand.Next(0, 50) > 25)
                {
                    continue;
                }
                var vertex2 = vlist[Rand.Next(0, graph.VertexCount - 1)];
                graph.AddEdge(new DataEdge(item, vertex2)
                {
                    ID = cnt
                });
                cnt++;
            }
            return(graph);
        }
Exemplo n.º 9
0
        public static GraphExample GenerateSugiDataGraph()
        {
            var graph = new GraphExample();

            foreach (var item in DataSource.Take(25))
            {
                graph.AddVertex(new DataVertex(item.Text)
                {
                    ImageId = Rand.Next(0, 3)
                });
            }

            var vList  = graph.Vertices.ToList();
            var edgeId = 1;

            //1 tier
            graph.AddNewEdge(vList[0], vList[1], ++edgeId);
            graph.AddNewEdge(vList[0], vList[2], ++edgeId);
            graph.AddNewEdge(vList[0], vList[3], ++edgeId);
            graph.AddNewEdge(vList[0], vList[4], ++edgeId);
            //2 tier
            graph.AddNewEdge(vList[1], vList[5], ++edgeId);
            graph.AddNewEdge(vList[1], vList[6], ++edgeId);
            graph.AddNewEdge(vList[2], vList[7], ++edgeId);
            graph.AddNewEdge(vList[2], vList[8], ++edgeId);
            graph.AddNewEdge(vList[3], vList[1], ++edgeId);
            graph.AddNewEdge(vList[4], vList[9], ++edgeId);
            graph.AddNewEdge(vList[4], vList[9], ++edgeId);
            //3 tier
            graph.AddNewEdge(vList[8], vList[10], ++edgeId);
            graph.AddNewEdge(vList[8], vList[11], ++edgeId);
            graph.AddNewEdge(vList[8], vList[12], ++edgeId);

            return(graph);
        }
Exemplo n.º 10
0
        private GraphExample GenerateGraph()
        {
            var links = new Dictionary <string, Link>();
            HashSet <string> hstates = new HashSet <string>();

            for (int i = 0; i <= 10; i++)
            {
                hstates.Add(string.Format("r{0}", i));
                links.Add(string.Format("r{0}", i), new Link());
            }
            links["r0"].Add("x2", "r5");
            links["r0"].Add("x3", "r1");
            links["r0"].Add("x4", "r3");
            links["r1"].Add("x1", "r2");
            links["r2"].Add("x3", "r3");
            links["r2"].Add("x7", "r3");
            links["r3"].Add("x1", "r10");
            links["r3"].Add("x5", "r4");
            links["r4"].Add("x6", "r10");
            links["r4"].Add("x0", "r0");
            links["r5"].Add("x2", "r9");
            links["r5"].Add("x5", "r6");
            links["r5"].Add("x7", "r6");
            links["r6"].Add("x4", "r7");
            links["r7"].Add("x6", "r8");
            links["r8"].Add("x0", "r10");
            links["r9"].Add("x0", "r8");

            var dataGraph = new GraphExample();

            foreach (string vs in hstates)
            {
                var dataVertex = new DataVertex(vs);
                dataGraph.AddVertex(dataVertex);
            }
            var      vlist = dataGraph.Vertices.ToList();
            DataEdge edge;

            //Then create two edges optionaly defining Text property to show who are connected
            foreach (string state in hstates)
            {
                if (links.ContainsKey(state))
                {
                    foreach (KeyValuePair <string, string> link in links[state])
                    {
                        var vA = vlist.Find(x => x.Text.Equals(state));
                        var vB = vlist.Find(x => x.Text.Equals(link.Value));
                        edge = new DataEdge(vA, vB)
                        {
                            Text = link.Key
                        };

                        dataGraph.AddEdge(edge);
                    }
                }
            }
            return(dataGraph);
        }
Exemplo n.º 11
0
        private GraphExample GraphExample_Setup()
        {
            //Lets make new data graph instance
            var dataGraph = new GraphExample();

            //Now we need to create edges and vertices to fill data graph
            //This edges and vertices will represent graph structure and connections
            //Lets make some vertices
            for (int i = 1; i <= numOfVertices; i++)
            {
                //Create new vertex with specified Text. Also we will assign custom unique ID.
                //This ID is needed for several features such as serialization and edge routing algorithms.
                //If you don't need any custom IDs and you are using automatic Area.GenerateGraph() method then you can skip ID assignment
                //because specified method automaticaly assigns missing data ids (this behavior is controlled by method param).

                var dataVertex = new DataVertex {
                    ID = i, Text = string.Format("{0}", i)
                };
                //Add vertex to data graph

                dataGraph.AddVertex(dataVertex);
            }

            if (matrix == null)
            {
                //Now lets make some edges that will connect our vertices
                //get the indexed list of graph vertices we have already added

                var vlist = dataGraph.Vertices.ToList();

                //Then create two edges optionaly defining Text property to show who are connected

                var dataEdge = new DataEdge(vlist[0], vlist[1], 3)
                {
                    Text = string.Format("{0} -> {1}", vlist[0], vlist[1])
                };
                dataGraph.AddEdge(dataEdge);
                dataEdge = new DataEdge(vlist[2], vlist[3], 3)
                {
                    Text = string.Format("{0} -> {1}", vlist[2], vlist[3])
                };
                dataGraph.AddEdge(dataEdge);
            }
            else
            {
                var vlist = dataGraph.Vertices.ToList();
                for (int i = 0; i < matrix.Count; i++)
                {
                    var dataEdge = new DataEdge(Search(dataGraph, matrix[i][0]), Search(dataGraph, matrix[i][1]), matrix[i][2])
                    {
                        Text = string.Format("{0}", matrix[i][2])
                    };
                    dataGraph.AddEdge(dataEdge);
                }
            }
            return(dataGraph);
        }
Exemplo n.º 12
0
        private GraphExample GenerateTestGraph()
        {
            var graph = new GraphExample();
            var v1 = new DataVertex() { Text = "Test1", ID = 1 };
            graph.AddVertex(v1);
            var v2 = new DataVertex() { Text = "Test2", ID = 2 };
            graph.AddVertex(v2);
            var v3 = new DataVertex() { Text = "Test3", ID = 3 };
            graph.AddVertex(v3);
            var v4 = new DataVertex() { Text = "Test4", ID = 4 };
            graph.AddVertex(v4);

            graph.AddEdge(new DataEdge(v1, v2, 100));
            graph.AddEdge(new DataEdge(v2, v3, 100));
            graph.AddEdge(new DataEdge(v2, v4, 100));

            return graph;
        }
Exemplo n.º 13
0
        void tst_but_gen_Click(object sender, RoutedEventArgs e)
        {
            var _graph = new GraphExample();

            /*var v1 = new DataVertex("Start");
             * _graph.AddVertex(v1);
             * var v2 = new DataVertex("End");
             * _graph.AddVertex(v2);
             * var e1 = new DataEdge(v1, v2);
             * _graph.AddEdge(e1);
             *
             * _graph.AddVertex(new DataVertex("Block 1"));
             * _graph.AddVertex(new DataVertex("Block 2"));
             */
            for (int i = 0; i < 10; i++)
            {
                _graph.AddVertex(new DataVertex(i.ToString() + "bldsddd\ndssdsds"));
            }

            _graph.AddEdge(new DataEdge(_graph.Vertices.First(), _graph.Vertices.Last()));
            _graph.AddEdge(new DataEdge(_graph.Vertices.Last(), _graph.Vertices.First()));
            _graph.AddEdge(new DataEdge(_graph.Vertices.First(), _graph.Vertices.Last()));

            // Resets external algorithms to null to start new fresh graph given that starting algo is a default algo
            tst_Area.DefaultEdgeRoutingAlgorithm = EdgeRoutingAlgorithmTypeEnum.None;
            //tst_Area.DefaultEdgeRoutingAlgorithmParams = tst_Area.AlgorithmFactory.CreateEdgeRoutingParameters(EdgeRoutingAlgorithmTypeEnum.SimpleER);
            //((SimpleERParameters)tst_Area.DefaultEdgeRoutingAlgorithmParams).BackStep = 10;

            tst_Area.DefaultOverlapRemovalAlgorithm = OverlapRemovalAlgorithmTypeEnum.FSA;

            tst_Area.GenerateGraph(_graph, true);

            /*var vlist = tst_Area.VertexList.Values.ToList();
             * vlist[0].SetPosition(new Point(100, 100)); vlist[0].MathShape = VertexShape.Circle;
             * vlist[1].SetPosition(new Point(600, 100));
             *
             * vlist[2].SetPosition(new Point(400, 100));
             * vlist[3].SetPosition(new Point(440, 150));
             */
            foreach (var item in tst_Area.VertexList)
            {
                item.Value.MathShape = VertexShape.Rectangle;
                DragBehaviour.SetIsDragEnabled(item.Value, true);
                DragBehaviour.SetUpdateEdgesOnMove(item.Value, true);
                HighlightBehaviour.SetIsHighlightEnabled(item.Value, true);
                HighlightBehaviour.SetHighlightControl(item.Value, GraphControlType.VertexAndEdge);
                HighlightBehaviour.SetHighlightEdges(item.Value, EdgesType.All);
            }

            foreach (var item in tst_Area.EdgesList.Values)
            {
                HighlightBehaviour.SetHighlightControl(item, GraphControlType.VertexAndEdge);
                HighlightBehaviour.SetHighlightEdges(item, EdgesType.All);
                HighlightBehaviour.SetHighlightControl(item, GraphControlType.VertexAndEdge);
            }
        }
Exemplo n.º 14
0
        public static GraphExample FirstSimpleExample()
        {
            var graph = new GraphExample();

            // 1. add vertexes
            var v1 = new DataVertex(1);
            var v2 = new DataVertex(2);



            graph.AddVertex(v1);
            graph.AddVertex(v2);

            // 2. add edges
            var edge1 = new DataEdge(v1, v2);

            graph.AddEdge(edge1);

            return(graph);
        }
Exemplo n.º 15
0
        private GraphExample GraphExample_Setup()
        {
            var dataGraph = new GraphExample();

            //debug


            dataGraph.AddVertex(new DataVertex("MyVertex " + 1)
            {
                ID = 1, VisualDiameter = 10, VisualInnerDiameter = 10
            });
            dataGraph.AddVertex(new DataVertex("MyVertex " + 2)
            {
                ID = 2, VisualDiameter = 10, VisualInnerDiameter = 10
            });
            var vlist = dataGraph.Vertices.ToList();

            AddEdge(dataGraph, 0, 1, vlist);
            return(dataGraph);
        }
Exemplo n.º 16
0
 private GraphExample GenerateGraph()
 {
     //FOR DETAILED EXPLANATION please see SimpleGraph example project
     var dataGraph = new GraphExample();
     for (int i = 1; i < 10; i++)
     {
         var dataVertex = new DataVertex("MyVertex " + i) { ID = i };
         dataGraph.AddVertex(dataVertex);
     }
     var vlist = dataGraph.Vertices.ToList();
     //Then create two edges optionaly defining Text property to show who are connected
     var dataEdge = new DataEdge(vlist[0], vlist[1]) { Text = string.Format("{0} -> {1}", vlist[0], vlist[1]) };
     dataGraph.AddEdge(dataEdge);
     dataEdge = new DataEdge(vlist[2], vlist[3]) { Text = string.Format("{0} -> {1}", vlist[2], vlist[3]) };
     dataGraph.AddEdge(dataEdge);
     return dataGraph;
 }
Exemplo n.º 17
0
        public static GraphExample GenerateGraph()
        {
            //FOR DETAILED EXPLANATION please see SimpleGraph example project
            var dataGraph = new GraphExample();

            if (DSK != null)
            {
                foreach (var key in DSK.Keys)
                {
                    var dataVertex = new DataVertex(key.ToString());
                    dataGraph.AddVertex(dataVertex);
                }
            }

            var vlist = dataGraph.Vertices.ToList();

            //Then create two edges optionaly defining Text property to show who are connected

            DataEdge dataEdge;

            foreach (var p in vlist)
            {
                foreach (var k in DSK)
                {
                    if (k.Key.ToString() == p.ToString())
                    {
                        foreach (var val in k.Value)
                        {
                            foreach (var v in vlist)
                            {
                                if (v.ToString() == val.ToString())
                                {
                                    dataEdge = new DataEdge(v, p);
                                    dataGraph.AddEdge(dataEdge);
                                }
                            }
                        }
                    }
                }
            }
            return(dataGraph);
        }
Exemplo n.º 18
0
        /// <summary>
        /// Generate example graph data
        /// </summary>
        /// <param name="count">Items count</param>
        /// <param name="addEdges"></param>
        public static GraphExample GenerateDataGraph(int count, bool addEdges = true)
        {
            var graph = new GraphExample();

            foreach (var item in DataSource.Take(count))
                graph.AddVertex(new DataVertex(item.Text) { ID = item.ID, ImageId = Rand.Next(0,3)});

            var vlist = graph.Vertices.ToList();
            var edgeId = count + 1;

            if (!addEdges) return graph;

            foreach (var item in vlist)
            {
                if (Rand.Next(0, 50) > 25) continue;
                var vertex2 = vlist[Rand.Next(0, graph.VertexCount - 1)];
                var txt = string.Format("{0} -> {1}", item.Text, vertex2.Text);
                graph.AddEdge(new DataEdge(item, vertex2, Rand.Next(1, 50)) { ID = edgeId, Text = txt, ToolTipText = txt });
                edgeId++;
            }
            return graph;
        }
Exemplo n.º 19
0
        /// <summary>
        /// Generate example graph data
        /// </summary>
        /// <param name="count">Items count</param>
        /// <param name="addEdges"></param>
        public static GraphExample GenerateDataGraph(int count, bool addEdges = true, int edgeCountMult = 25)
        {
            var graph = new GraphExample();

            foreach (var item in DataSource.Take(count))
            {
                graph.AddVertex(new DataVertex(item.Text)
                {
                    ImageId = Rand.Next(0, 3)
                });
            }

            var vlist  = graph.Vertices.ToList();
            var edgeId = count + 1;

            if (!addEdges)
            {
                return(graph);
            }

            foreach (var item in vlist)
            {
                if (Rand.Next(0, 50) > edgeCountMult)
                {
                    continue;
                }
                var vertex2 = vlist[Rand.Next(0, graph.VertexCount - 1)];
                var txt     = string.Format("{0} -> {1}", item.Text, vertex2.Text);
                graph.AddEdge(new DataEdge(item, vertex2, Rand.Next(1, 50))
                {
                    ID = edgeId, Text = txt, ToolTipText = txt
                });
                edgeId++;
            }
            return(graph);
        }
Exemplo n.º 20
0
        private GraphExample GraphExample_Setup()
        {
            var dataGraph = new GraphExample();
            var vlist     = new List <DataVertex>();;

            //debug

            /* dataGraph.AddVertex(new DataVertex("MyVertex " + 1) { ID = 1, VisualDiameter = 10, VisualInnerDiameter = 10 });
             * dataGraph.AddVertex(new DataVertex("MyVertex " + 2) { ID = 2, VisualDiameter = 10, VisualInnerDiameter = 10 });
             * vlist = dataGraph.Vertices.ToList();
             * AddEdge(dataGraph, 0, 1, vlist);
             * return dataGraph;*/



            switch ((LayoutAlgorithmTypeEnum)cboxLayout.SelectedItem)
            {
            case LayoutAlgorithmTypeEnum.EfficientSugiyama:
            case LayoutAlgorithmTypeEnum.Sugiyama:
            case LayoutAlgorithmTypeEnum.BoundedFR:
            case LayoutAlgorithmTypeEnum.FR:
            case LayoutAlgorithmTypeEnum.Tree:
                for (int i = 1; i < 14; i++)
                {
                    var dataVertex = new DataVertex("MyVertex " + i)
                    {
                        ID = i, VisualDiameter = _rnd.Next(25, 50), VisualInnerDiameter = _rnd.Next(10, 22)
                    };
                    dataGraph.AddVertex(dataVertex);
                }
                vlist = dataGraph.Vertices.ToList();
                AddEdge(dataGraph, 0, 1, vlist);
                AddEdge(dataGraph, 0, 0, vlist);

                AddEdge(dataGraph, 0, 2, vlist);
                AddEdge(dataGraph, 1, 3, vlist);
                AddEdge(dataGraph, 1, 4, vlist);
                AddEdge(dataGraph, 2, 5, vlist);
                AddEdge(dataGraph, 2, 6, vlist);
                AddEdge(dataGraph, 2, 7, vlist);

                AddEdge(dataGraph, 8, 9, vlist);
                AddEdge(dataGraph, 9, 10, vlist);
                AddEdge(dataGraph, 10, 7, vlist);
                AddEdge(dataGraph, 10, 11, vlist);
                AddEdge(dataGraph, 10, 12, vlist);

                break;

            default:
                for (var i = 1; i < 11; i++)
                {
                    var dataVertex = new DataVertex("MyVertex " + i)
                    {
                        ID = i, VisualDiameter = _rnd.Next(50, 100), VisualInnerDiameter = _rnd.Next(20, 45)
                    };
                    if (i == 2)
                    {
                        dataVertex.LabelText += "\nMultiline!";
                    }
                    dataGraph.AddVertex(dataVertex);
                }
                vlist = dataGraph.Vertices.ToList();
                AddEdge(dataGraph, 0, 1, vlist);

                AddEdge(dataGraph, 1, 2, vlist);
                AddEdge(dataGraph, 1, 3, vlist);
                AddEdge(dataGraph, 1, 4, vlist);

                AddEdge(dataGraph, 4, 5, vlist);
                AddEdge(dataGraph, 4, 6, vlist);

                AddEdge(dataGraph, 2, 7, vlist);
                AddEdge(dataGraph, 2, 8, vlist);

                AddEdge(dataGraph, 8, 9, vlist);

                //add some cross references
                AddEdge(dataGraph, 4, 2, vlist);
                AddEdge(dataGraph, 4, 8, vlist);
                AddEdge(dataGraph, 9, 2, vlist);

                break;
            }

            /* foreach (var item in graph.EdgesList)
             * {
             *   //item.Value.LabelVerticalOffset = -40;
             *   item.Value.LabelAngle = 45;
             * }*/


            return(dataGraph);

            /*ManipulationDelta += MainPage_ManipulationDelta;
             * ManipulationMode = ManipulationModes.Scale;
             *
             * for (int i = 1; i < 10; i++)
             * {
             *  var dataVertex = new DataVertex("MyVertex " + i) { ID = i };
             *  dataGraph.AddVertex(dataVertex);
             * }
             *
             * var vlist = dataGraph.Vertices.ToList();
             * //var dataEdge = new DataEdge(vlist[0], vlist[1]) { Text = string.Format("{0} -> {1}", vlist[0], vlist[1]) };
             * //dataGraph.AddEdge(dataEdge);
             * var dataEdge = new DataEdge(vlist[2], vlist[3]) { Text = "23" };
             * dataGraph.AddEdge(dataEdge);
             * dataEdge = new DataEdge(vlist[3], vlist[2]) { Text = "32" };
             * dataGraph.AddEdge(dataEdge);
             *
             * return dataGraph;*/
        }
Exemplo n.º 21
0
        void erg_but_randomgraph_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            if ((EdgeRoutingAlgorithmTypeEnum)erg_eralgo.SelectedItem != EdgeRoutingAlgorithmTypeEnum.Bundling)
            {
                var gr = GenerateDataGraph(30);

                if (erg_Area.LogicCore.EnableParallelEdges)
                {
                    if (erg_Area.VertexList.Count() < 2)
                    {
                        var v1 = new DataVertex(); gr.AddVertex(v1);
                        var v2 = new DataVertex(); gr.AddVertex(v2);
                        gr.AddEdge(new DataEdge(v1, v2)
                        {
                            Text = string.Format("{0} -> {1}", v1.Text, v2.Text)
                        });
                        gr.AddEdge(new DataEdge(v2, v1)
                        {
                            Text = string.Format("{0} -> {1}", v2.Text, v1.Text)
                        });
                    }
                    else
                    {
                        var v1 = gr.Vertices.ToList()[0];
                        var v2 = gr.Vertices.ToList()[1];
                        gr.AddEdge(new DataEdge(v1, v2)
                        {
                            Text = string.Format("{0} -> {1}", v1.Text, v2.Text)
                        });
                        gr.AddEdge(new DataEdge(v2, v1)
                        {
                            Text = string.Format("{0} -> {1}", v2.Text, v1.Text)
                        });
                    }
                }

                erg_Area.GetLogicCore <LogicCoreExample>().DefaultEdgeRoutingAlgorithm = (EdgeRoutingAlgorithmTypeEnum)erg_eralgo.SelectedItem;
                switch ((EdgeRoutingAlgorithmTypeEnum)erg_eralgo.SelectedItem)
                {
                case EdgeRoutingAlgorithmTypeEnum.SimpleER:
                    erg_Area.GetLogicCore <LogicCoreExample>().DefaultEdgeRoutingAlgorithmParams = erg_SimpleERParameters;
                    break;

                case EdgeRoutingAlgorithmTypeEnum.PathFinder:
                    erg_Area.GetLogicCore <LogicCoreExample>().DefaultEdgeRoutingAlgorithmParams = erg_PFERParameters;
                    // erg_Area.SideExpansionSize = new Size(erg_PFERParameters.SideGridOffset, erg_PFERParameters.SideGridOffset);
                    break;
                }

                erg_Area.GetLogicCore <LogicCoreExample>().DefaultLayoutAlgorithm               = LayoutAlgorithmTypeEnum.SimpleRandom;
                erg_Area.GetLogicCore <LogicCoreExample>().DefaultOverlapRemovalAlgorithm       = OverlapRemovalAlgorithmTypeEnum.FSA;
                erg_Area.GetLogicCore <LogicCoreExample>().DefaultOverlapRemovalAlgorithmParams = erg_Area.LogicCore.AlgorithmFactory.CreateOverlapRemovalParameters(OverlapRemovalAlgorithmTypeEnum.FSA);
                var oprm = erg_Area.GetLogicCore <LogicCoreExample>().DefaultOverlapRemovalAlgorithmParams as OverlapRemovalParameters;
                //oprm.HorizontalGap = 100;
                //oprm.VerticalGap = 100;
                //erg_Area.ExternalEdgeRoutingAlgorithm = new SimpleEdgeRouting<DataVertex, DataEdge,  GraphExample>(gr as GraphExample, erg_Area.GetVertexPositions(), erg_Area.GetVertexSizeRectangles());

                erg_Area.GenerateGraph(gr);
                erg_zoomctrl.ZoomToFill();//.ZoomToFill();
                erg_Area.GenerateAllEdges();
                foreach (var item in erg_Area.GetAllVertexControls())
                {
                    DragBehaviour.SetIsDragEnabled(item, true);
                }
                erg_recalculate_Checked(null, null);
                erg_showEdgeArrows_Checked(null, null);
                erg_showEdgeLabels_Checked(null, null);
                erg_alignEdgeLabels_Checked(null, null);
                return;
            }

            erg_Area.RemoveAllEdges();
            erg_Area.RemoveAllVertices();
            //generate graph
            var graph = new GraphExample();

            foreach (var item in DataSource.Take(120))
            {
                graph.AddVertex(new DataVertex(item.Text)
                {
                    ID = item.ID
                });
            }

            var vlist = graph.Vertices.ToList();

            foreach (var item in vlist)
            {
                if (Rand.Next(0, 50) > 25)
                {
                    continue;
                }
                var vertex2 = vlist[Rand.Next(0, graph.VertexCount - 1)];
                graph.AddEdge(new DataEdge(item, vertex2, Rand.Next(1, 50))
                {
                    ToolTipText = string.Format("{0} -> {1}", item, vertex2)
                });
            }

            /* graph.AddEdge(new DataEdge(vlist[0], vlist[3], 1));
             * graph.AddEdge(new DataEdge(vlist[1], vlist[4], 1));
             * graph.AddEdge(new DataEdge(vlist[2], vlist[5], 1));
             *
             * graph.AddEdge(new DataEdge(vlist[0], vlist[6], 1));
             * graph.AddEdge(new DataEdge(vlist[1], vlist[7], 1));
             * graph.AddEdge(new DataEdge(vlist[2], vlist[8], 1));
             * //generate vertex positions
             * var VertexPositions = new Dictionary<DataVertex, Point>();
             *
             * VertexPositions.Add(vlist[6], new Point(5000, 1000));
             * VertexPositions.Add(vlist[7], new Point(5000, 1100));
             * VertexPositions.Add(vlist[8], new Point(5000, 1300));
             *
             * VertexPositions.Add(vlist[0], new Point(100, 100));
             * VertexPositions.Add(vlist[1], new Point(300, 100));
             * VertexPositions.Add(vlist[2], new Point(200, 300));
             *
             * VertexPositions.Add(vlist[3], new Point(10000, 1000));
             * VertexPositions.Add(vlist[4], new Point(10300, 1000));
             * VertexPositions.Add(vlist[5], new Point(10200, 1300));*/
            //generate vertices

            var VertexPositions = new Dictionary <DataVertex, Point>();

            foreach (var item in GenerateRandomVertices(graph, 0, 40, 0, 2000, 0, 2000))
            {
                VertexPositions.Add(item.Key, item.Value);
            }
            foreach (var item in GenerateRandomVertices(graph, 40, 40, 5000, 7000, 3000, 4000))
            {
                VertexPositions.Add(item.Key, item.Value);
            }
            foreach (var item in GenerateRandomVertices(graph, 80, 40, 500, 2500, 6000, 9000))
            {
                VertexPositions.Add(item.Key, item.Value);
            }
            erg_Area.LogicCore.Graph = graph;
            UpdateLayout();


            CalcBundling();



            //generate edges
            erg_Area.GenerateAllEdges(Visibility.Visible);
            foreach (var item in erg_Area.GetAllVertexControls())
            {
                DragBehaviour.SetIsDragEnabled(item, true);
            }
            erg_recalculate_Checked(null, null);
            erg_showEdgeArrows_Checked(null, null);
            erg_showEdgeLabels_Checked(null, null);
            erg_zoomctrl.ZoomToFill();
        }
Exemplo n.º 22
0
        private void button4_Click(object sender, EventArgs e)
        {
            var    links      = new Dictionary <string, Link>();
            var    states     = new HashSet <string>();
            string initState  = "";
            string finalState = "";

            for (int i = 0; i < txtFSMTable.Lines.Count(); i++)
            {
                string   line          = txtFSMTable.Lines[i];
                string[] StateAndLinks = line.Split(':');
                string   StateName     = StateAndLinks[0].Trim(' ');
                states.Add(StateName);
                if (i == 0)
                {
                    initState = StateName;
                }
                if (i == txtFSMTable.Lines.Count() - 1)
                {
                    finalState = StateName;
                }
                links.Add(StateName, new Link());

                if (StateAndLinks[1] != "") // Парсим переходы к другим состояниям
                {
                    foreach (string LinkPair in StateAndLinks[1].Split(','))
                    {
                        string[] SymAndDestState = LinkPair.Split('-');
                        string   Symbol          = SymAndDestState[0].Trim(' ').Substring(1); //.Substring(1);
                        string   DestState       = SymAndDestState[1].Trim(' ');
                        states.Add(DestState);
                        links[StateName].Add(Symbol, DestState);
                    }
                }
            }
            parser = new fsm.Parser(states, links, initState, finalState);
            var dataGraph = new GraphExample();

            foreach (string vs in states)
            {
                var dataVertex = new DataVertex(vs);
                dataGraph.AddVertex(dataVertex);
            }
            var      vlist = dataGraph.Vertices.ToList();
            DataEdge edge;

            //Then create two edges optionaly defining Text property to show who are connected
            foreach (string state in states)
            {
                if (links.ContainsKey(state))
                {
                    foreach (KeyValuePair <string, string> link in links[state])
                    {
                        var vA = vlist.Find(x => x.Text.Equals(state));
                        var vB = vlist.Find(x => x.Text.Equals(link.Value));
                        edge = new DataEdge(vA, vB)
                        {
                            Text = link.Key
                        };
                        dataGraph.AddEdge(edge);
                    }
                }
            }
            _gArea.LogicCore.Graph = dataGraph;
            _gArea.GenerateGraph(true);
            _gArea.RelayoutGraph();
            _gArea.SetVerticesDrag(true, true);
            _zoomctrl.ZoomToFill();
        }
Exemplo n.º 23
0
        private GraphExample GraphExample_Setup()
        {
            //Lets make new data graph instance
            var dataGraph = new GraphExample();
            //Now we need to create edges and vertices to fill data graph
            //This edges and vertices will represent graph structure and connections
            //Lets make some vertices
            for (int i = 1; i < 10; i++)
            {
                //Create new vertex with specified Text. Also we will assign custom unique ID.
                //This ID is needed for several features such as serialization and edge routing algorithms.
                //If you don't need any custom IDs and you are using automatic Area.GenerateGraph() method then you can skip ID assignment
                //because specified method automaticaly assigns missing data ids (this behavior controlled by method param).
                var dataVertex = new DataVertex("MyVertex " + i) { ID = i };
                //Add vertex to data graph
                dataGraph.AddVertex(dataVertex);
            }

            //Now lets make some edges that will connect our vertices
            //get the indexed list of graph vertices we have already added
            var vlist = dataGraph.Vertices.ToList();
            //Then create two edges optionaly defining Text property to show who are connected
            var dataEdge = new DataEdge(vlist[0], vlist[1]) { Text = string.Format("{0} -> {1}", vlist[0], vlist[1]) };
            dataGraph.AddEdge(dataEdge);
                dataEdge = new DataEdge(vlist[2], vlist[3]) { Text = string.Format("{0} -> {1}", vlist[2], vlist[3]) };
            dataGraph.AddEdge(dataEdge);

            return dataGraph;
        }
Exemplo n.º 24
0
        void erg_but_randomgraph_Click(object sender, RoutedEventArgs e)
        {
            if ((EdgeRoutingAlgorithmTypeEnum)erg_eralgo.SelectedItem != EdgeRoutingAlgorithmTypeEnum.Bundling)
            {
                var gr = ShowcaseHelper.GenerateDataGraph(30);

                if (erg_Area.LogicCore.EnableParallelEdges)
                {
                    if (erg_Area.VertexList.Count() < 2)
                    {
                        var v1 = new DataVertex(); gr.AddVertex(v1);
                        var v2 = new DataVertex(); gr.AddVertex(v2);
                        gr.AddEdge(new DataEdge(v1, v2)
                        {
                            Text = string.Format("{0} -> {1}", v1.Text, v2.Text)
                        });
                        gr.AddEdge(new DataEdge(v2, v1)
                        {
                            Text = string.Format("{0} -> {1}", v2.Text, v1.Text)
                        });
                    }
                    else
                    {
                        var v1 = gr.Vertices.ToList()[0];
                        var v2 = gr.Vertices.ToList()[1];
                        gr.AddEdge(new DataEdge(v1, v2)
                        {
                            Text = string.Format("{0} -> {1}", v1.Text, v2.Text)
                        });
                        gr.AddEdge(new DataEdge(v2, v1)
                        {
                            Text = string.Format("{0} -> {1}", v2.Text, v1.Text)
                        });
                    }
                }

                erg_Area.GetLogicCore <LogicCoreExample>().DefaultEdgeRoutingAlgorithm = (EdgeRoutingAlgorithmTypeEnum)erg_eralgo.SelectedItem;
                switch ((EdgeRoutingAlgorithmTypeEnum)erg_eralgo.SelectedItem)
                {
                case EdgeRoutingAlgorithmTypeEnum.SimpleER:
                    erg_Area.GetLogicCore <LogicCoreExample>().DefaultEdgeRoutingAlgorithmParams = SimpleErParameters;
                    break;

                case EdgeRoutingAlgorithmTypeEnum.PathFinder:
                    erg_Area.GetLogicCore <LogicCoreExample>().DefaultEdgeRoutingAlgorithmParams = PfErParameters;
                    break;
                }

                erg_Area.GetLogicCore <LogicCoreExample>().DefaultLayoutAlgorithm               = LayoutAlgorithmTypeEnum.SimpleRandom;
                erg_Area.GetLogicCore <LogicCoreExample>().DefaultOverlapRemovalAlgorithm       = OverlapRemovalAlgorithmTypeEnum.FSA;
                erg_Area.GetLogicCore <LogicCoreExample>().DefaultOverlapRemovalAlgorithmParams = erg_Area.LogicCore.AlgorithmFactory.CreateOverlapRemovalParameters(OverlapRemovalAlgorithmTypeEnum.FSA);

                erg_Area.GenerateGraph(gr, true);
                erg_Area.SetVerticesDrag(true, true);
                erg_zoomctrl.ZoomToFill();

                return;
            }

            erg_Area.RemoveAllEdges();
            erg_Area.RemoveAllVertices();
            //generate graph
            var graph = new GraphExample();

            foreach (var item in ShowcaseHelper.DataSource.Take(120))
            {
                graph.AddVertex(new DataVertex(item.Text)
                {
                    ID = item.ID
                });
            }

            var vlist = graph.Vertices.ToList();

            foreach (var item in vlist)
            {
                if (ShowcaseHelper.Rand.Next(0, 50) > 25)
                {
                    continue;
                }
                var vertex2 = vlist[ShowcaseHelper.Rand.Next(0, graph.VertexCount - 1)];
                graph.AddEdge(new DataEdge(item, vertex2, ShowcaseHelper.Rand.Next(1, 50))
                {
                    ToolTipText = string.Format("{0} -> {1}", item, vertex2)
                });
            }

            //generate vertices

            var vertexPositions = GenerateRandomVertices(graph, 0, 40, 0, 2000, 0, 2000).ToDictionary(item => item.Key, item => item.Value);

            foreach (var item in GenerateRandomVertices(graph, 40, 40, 5000, 7000, 3000, 4000))
            {
                vertexPositions.Add(item.Key, item.Value);
            }
            foreach (var item in GenerateRandomVertices(graph, 80, 40, 500, 2500, 6000, 9000))
            {
                vertexPositions.Add(item.Key, item.Value);
            }
            erg_Area.LogicCore.Graph = graph;
            UpdateLayout();

            erg_Area.SetVerticesDrag(true);
            _logicCore.DefaultLayoutAlgorithm            = LayoutAlgorithmTypeEnum.Custom;
            _logicCore.DefaultEdgeRoutingAlgorithm       = EdgeRoutingAlgorithmTypeEnum.Bundling;
            _logicCore.DefaultEdgeRoutingAlgorithmParams = BundleEdgeRoutingParameters;
            erg_Area.GenerateGraph(true);

            erg_zoomctrl.ZoomToFill();
        }
Exemplo n.º 25
0
        void erg_but_randomgraph_Click(object sender, RoutedEventArgs e)
        {
            if ((EdgeRoutingAlgorithmTypeEnum)erg_eralgo.SelectedItem != EdgeRoutingAlgorithmTypeEnum.Bundling)
            {
                var gr = GenerateDataGraph(30);

                if (erg_Area.LogicCore.EnableParallelEdges)
                {
                    if (erg_Area.VertexList.Count() < 2)
                    {
                        var v1 = new DataVertex(); gr.AddVertex(v1);
                        var v2 = new DataVertex(); gr.AddVertex(v2);
                        gr.AddEdge(new DataEdge(v1, v2)
                        {
                            Text = string.Format("{0} -> {1}", v1.Text, v2.Text)
                        });
                        gr.AddEdge(new DataEdge(v2, v1)
                        {
                            Text = string.Format("{0} -> {1}", v2.Text, v1.Text)
                        });
                    }
                    else
                    {
                        var v1 = gr.Vertices.ToList()[0];
                        var v2 = gr.Vertices.ToList()[1];
                        gr.AddEdge(new DataEdge(v1, v2)
                        {
                            Text = string.Format("{0} -> {1}", v1.Text, v2.Text)
                        });
                        gr.AddEdge(new DataEdge(v2, v1)
                        {
                            Text = string.Format("{0} -> {1}", v2.Text, v1.Text)
                        });
                    }
                }

                erg_Area.GetLogicCore <LogicCoreExample>().DefaultEdgeRoutingAlgorithm = (EdgeRoutingAlgorithmTypeEnum)erg_eralgo.SelectedItem;
                switch ((EdgeRoutingAlgorithmTypeEnum)erg_eralgo.SelectedItem)
                {
                case EdgeRoutingAlgorithmTypeEnum.SimpleER:
                    erg_Area.GetLogicCore <LogicCoreExample>().DefaultEdgeRoutingAlgorithmParams = erg_SimpleERParameters;
                    break;

                case EdgeRoutingAlgorithmTypeEnum.PathFinder:
                    erg_Area.GetLogicCore <LogicCoreExample>().DefaultEdgeRoutingAlgorithmParams = erg_PFERParameters;
                    // erg_Area.SideExpansionSize = new Size(erg_PFERParameters.SideGridOffset, erg_PFERParameters.SideGridOffset);
                    break;
                }

                erg_Area.GetLogicCore <LogicCoreExample>().DefaultLayoutAlgorithm               = LayoutAlgorithmTypeEnum.SimpleRandom;
                erg_Area.GetLogicCore <LogicCoreExample>().DefaultOverlapRemovalAlgorithm       = OverlapRemovalAlgorithmTypeEnum.FSA;
                erg_Area.GetLogicCore <LogicCoreExample>().DefaultOverlapRemovalAlgorithmParams = erg_Area.LogicCore.AlgorithmFactory.CreateOverlapRemovalParameters(OverlapRemovalAlgorithmTypeEnum.FSA);

                erg_Area.GenerateGraph(gr, true);
                erg_Area.SetVerticesDrag(true, true);
                erg_zoomctrl.ZoomToFill();//.ZoomToFill();

                /*erg_recalculate_Checked(null, null);
                 * erg_showEdgeArrows_Checked(null, null);
                 * erg_showEdgeLabels_Checked(null, null);
                 * erg_alignEdgeLabels_Checked(null, null);*/
                return;
            }

            erg_Area.RemoveAllEdges();
            erg_Area.RemoveAllVertices();
            //generate graph
            var graph = new GraphExample();

            foreach (var item in DataSource.Take(120))
            {
                graph.AddVertex(new DataVertex(item.Text)
                {
                    ID = item.ID
                });
            }

            var vlist = graph.Vertices.ToList();

            foreach (var item in vlist)
            {
                if (Rand.Next(0, 50) > 25)
                {
                    continue;
                }
                var vertex2 = vlist[Rand.Next(0, graph.VertexCount - 1)];
                graph.AddEdge(new DataEdge(item, vertex2, Rand.Next(1, 50))
                {
                    ToolTipText = string.Format("{0} -> {1}", item, vertex2)
                });
            }

            //generate vertices

            var vertexPositions = new Dictionary <DataVertex, Point>();

            foreach (var item in GenerateRandomVertices(graph, 0, 40, 0, 2000, 0, 2000))
            {
                vertexPositions.Add(item.Key, item.Value);
            }
            foreach (var item in GenerateRandomVertices(graph, 40, 40, 5000, 7000, 3000, 4000))
            {
                vertexPositions.Add(item.Key, item.Value);
            }
            foreach (var item in GenerateRandomVertices(graph, 80, 40, 500, 2500, 6000, 9000))
            {
                vertexPositions.Add(item.Key, item.Value);
            }
            erg_Area.LogicCore.Graph = graph;
            UpdateLayout();

            erg_Area.SetVerticesDrag(true, false);
            _er_logic.DefaultLayoutAlgorithm            = LayoutAlgorithmTypeEnum.Custom;
            _er_logic.DefaultEdgeRoutingAlgorithm       = EdgeRoutingAlgorithmTypeEnum.Bundling;
            _er_logic.DefaultEdgeRoutingAlgorithmParams = erg_BundleEdgeRoutingParameters;
            erg_Area.GenerateGraph(true);
            // CalcBundling();
            //erg_Area.GenerateAllEdges(Visibility.Visible);

            /*erg_recalculate_Checked(null, null);
             * erg_showEdgeArrows_Checked(null, null);
             * erg_showEdgeLabels_Checked(null, null);*/
            erg_zoomctrl.ZoomToFill();
        }
Exemplo n.º 26
0
        private GraphExample GraphExample_Setup()
        {
            var dataGraph = new GraphExample();

            //debug


            dataGraph.AddVertex(new DataVertex("MyVertex " + 1) { ID = 1, VisualDiameter = 10, VisualInnerDiameter = 10 });
            dataGraph.AddVertex(new DataVertex("MyVertex " + 2) { ID = 2, VisualDiameter = 10, VisualInnerDiameter = 10 });
            var vlist = dataGraph.Vertices.ToList();
            AddEdge(dataGraph, 0, 1, vlist);
            return dataGraph;
        }
Exemplo n.º 27
0
        void tst_but_gen_Click(object sender, RoutedEventArgs e)
        {
            var _graph = new GraphExample();
            var v1     = new DataVertex()
            {
                Text = "Test1", ID = 1
            };

            _graph.AddVertex(v1);
            var v2 = new DataVertex()
            {
                Text = "Test2", ID = 2
            };

            _graph.AddVertex(v2);
            var v3 = new DataVertex()
            {
                Text = "Test3", ID = 3
            };

            _graph.AddVertex(v3);
            var v4 = new DataVertex()
            {
                Text = "Test4", ID = 4
            };

            _graph.AddVertex(v4);

            _graph.AddEdge(new DataEdge(v1, v2, 1)
            {
                ID = 1000
            });
            _graph.AddEdge(new DataEdge(v1, v2, 1)
            {
                ID = 1
            });


            _graph.AddEdge(new DataEdge(v1, v4, 1)
            {
                ID = 1000
            });
            _graph.AddEdge(new DataEdge(v1, v4, 1)
            {
                ID = 1
            });
            _graph.AddEdge(new DataEdge(v1, v4, 1)
            {
                ID = 2
            });
            _graph.AddEdge(new DataEdge(v2, v4, 1)
            {
                ID = 1001
            });
            _graph.AddEdge(new DataEdge(v3, v4, 1)
            {
                ID = 1002
            });
            _graph.AddEdge(new DataEdge(v3, v4, 1)
            {
                ID = 1003
            });
            _graph.AddEdge(new DataEdge(v4, v3, 1)
            {
                ID = 1004
            });
            _graph.AddEdge(new DataEdge(v4, v3, 1)
            {
                ID = 1005
            });
            _graph.AddEdge(new DataEdge(v4, v3, 1)
            {
                ID = 1006
            });

            tst_Area.ShowAllEdgesArrows(true);

            var ergTreeLayoutParameters = new KKLayoutParameters {
            };

            var logic = new LogicCoreExample();

            TSTLC       = logic;
            logic.Graph = _graph;
            logic.EnableParallelEdges = true;

            logic.ParallelEdgeDistance = 15;

            logic.DefaultLayoutAlgorithm       = LayoutAlgorithmTypeEnum.KK;
            logic.DefaultLayoutAlgorithmParams = ergTreeLayoutParameters;

            logic.DefaultOverlapRemovalAlgorithm       = OverlapRemovalAlgorithmTypeEnum.FSA;
            logic.DefaultOverlapRemovalAlgorithmParams = logic.AlgorithmFactory.CreateOverlapRemovalParameters(OverlapRemovalAlgorithmTypeEnum.FSA);

            ((GraphX.GraphSharp.Algorithms.OverlapRemoval.OverlapRemovalParameters)logic.DefaultOverlapRemovalAlgorithmParams).HorizontalGap = 140;
            ((GraphX.GraphSharp.Algorithms.OverlapRemoval.OverlapRemovalParameters)logic.DefaultOverlapRemovalAlgorithmParams).VerticalGap   = 140;
            tst_Area.GenerateGraph(_graph, true);
            //tst_Area.VertexList[v1].Visibility = System.Windows.Visibility.Collapsed;
            //tst_Area.VertexList[v2].Visibility = System.Windows.Visibility.Collapsed;
            //tst_Area.VertexList[v3].Visibility = System.Windows.Visibility.Collapsed;
            //tst_Area.VertexList[v4].SetPosition(new Point(0, 0));
            tst_Area.ShowAllEdgesLabels();
            tst_Area.AlignAllEdgesLabels();
            tst_zoomctrl.ZoomToFill();

            /* var img = new BitmapImage(new Uri(@"pack://application:,,,/ShowcaseExample;component/Images/birdy.png", UriKind.Absolute)) { CacheOption = BitmapCacheOption.OnLoad };
             * GraphAreaBase.SetX(img, -100);
             * GraphAreaBase.SetY(img, -100);
             * var image = new Image() { Source = img, Width = 100, Height = 100 };
             * var border = new Border() { BorderBrush = Brushes.Black, BorderThickness = new Thickness(2), Background = Brushes.Black, Width = 100, Height = 100 };
             * image.Visibility = System.Windows.Visibility.Visible;
             * border.Visibility = System.Windows.Visibility.Visible;
             * tst_Area.InsertCustomChildControl(0, image);
             * tst_Area.InsertCustomChildControl(0, border);*/
        }
Exemplo n.º 28
0
        void tst_but_gen_Click(object sender, RoutedEventArgs e)
        {
            var _graph = new GraphExample();
            var v1 = new DataVertex() { Text = "Test1", ID = 1 };
            _graph.AddVertex(v1);
            var v2 = new DataVertex() { Text = "Test2", ID = 2 };
            _graph.AddVertex(v2);
            var v3 = new DataVertex() { Text = "Test3", ID = 3 };
            _graph.AddVertex(v3);
            var v4 = new DataVertex() { Text = "Test4", ID = 4 };
            _graph.AddVertex(v4);

            _graph.AddEdge(new DataEdge(v1, v2, 1) { ID = 1000 });
            _graph.AddEdge(new DataEdge(v1, v2, 1) { ID = 1 });

            _graph.AddEdge(new DataEdge(v1, v4, 1) { ID = 1000 });
            _graph.AddEdge(new DataEdge(v1, v4, 1) { ID = 1 });
            _graph.AddEdge(new DataEdge(v1, v4, 1) { ID = 2 });
            _graph.AddEdge(new DataEdge(v2, v4, 1) { ID = 1001 });
            _graph.AddEdge(new DataEdge(v3, v4, 1) { ID = 1002 });
            _graph.AddEdge(new DataEdge(v3, v4, 1) { ID = 1003 });
            _graph.AddEdge(new DataEdge(v4, v3, 1) { ID = 1004 });
            _graph.AddEdge(new DataEdge(v4, v3, 1) { ID = 1005 });
            _graph.AddEdge(new DataEdge(v4, v3, 1) { ID = 1006 });

            tst_Area.ShowAllEdgesArrows(true);

            var ergTreeLayoutParameters = new KKLayoutParameters { };

            var logic = new LogicCoreExample();
            TSTLC = logic;
            logic.Graph = _graph;
            logic.EnableParallelEdges = true;

            logic.ParallelEdgeDistance = 15;

            logic.DefaultLayoutAlgorithm = LayoutAlgorithmTypeEnum.KK;
            logic.DefaultLayoutAlgorithmParams = ergTreeLayoutParameters;

            logic.DefaultOverlapRemovalAlgorithm = OverlapRemovalAlgorithmTypeEnum.FSA;
            logic.DefaultOverlapRemovalAlgorithmParams = logic.AlgorithmFactory.CreateOverlapRemovalParameters(OverlapRemovalAlgorithmTypeEnum.FSA);

            ((GraphX.GraphSharp.Algorithms.OverlapRemoval.OverlapRemovalParameters)logic.DefaultOverlapRemovalAlgorithmParams).HorizontalGap = 140;
            ((GraphX.GraphSharp.Algorithms.OverlapRemoval.OverlapRemovalParameters)logic.DefaultOverlapRemovalAlgorithmParams).VerticalGap = 140;
            tst_Area.GenerateGraph(_graph, true);
            //tst_Area.VertexList[v1].Visibility = System.Windows.Visibility.Collapsed;
            //tst_Area.VertexList[v2].Visibility = System.Windows.Visibility.Collapsed;
            //tst_Area.VertexList[v3].Visibility = System.Windows.Visibility.Collapsed;
            //tst_Area.VertexList[v4].SetPosition(new Point(0, 0));
            tst_Area.ShowAllEdgesLabels();
            tst_Area.AlignAllEdgesLabels();
            tst_zoomctrl.ZoomToFill();

               /* var img = new BitmapImage(new Uri(@"pack://application:,,,/ShowcaseExample;component/Images/birdy.png", UriKind.Absolute)) { CacheOption = BitmapCacheOption.OnLoad };
            GraphAreaBase.SetX(img, -100);
            GraphAreaBase.SetY(img, -100);
            var image = new Image() { Source = img, Width = 100, Height = 100 };
            var border = new Border() { BorderBrush = Brushes.Black, BorderThickness = new Thickness(2), Background = Brushes.Black, Width = 100, Height = 100 };
            image.Visibility = System.Windows.Visibility.Visible;
            border.Visibility = System.Windows.Visibility.Visible;
            tst_Area.InsertCustomChildControl(0, image);
            tst_Area.InsertCustomChildControl(0, border);*/
        }
Exemplo n.º 29
0
        private GraphExample GraphExample_Setup()
        {
            var dataGraph = new GraphExample();
            var vlist = new List<DataVertex>();;

            //debug
           /* dataGraph.AddVertex(new DataVertex("MyVertex " + 1) { ID = 1, VisualDiameter = 10, VisualInnerDiameter = 10 });
            dataGraph.AddVertex(new DataVertex("MyVertex " + 2) { ID = 2, VisualDiameter = 10, VisualInnerDiameter = 10 });
            vlist = dataGraph.Vertices.ToList();
            AddEdge(dataGraph, 0, 1, vlist);
            return dataGraph;*/



            switch ((LayoutAlgorithmTypeEnum)cboxLayout.SelectedItem)
            {
                case LayoutAlgorithmTypeEnum.EfficientSugiyama:
                case LayoutAlgorithmTypeEnum.Sugiyama:
                case LayoutAlgorithmTypeEnum.BoundedFR:
                case LayoutAlgorithmTypeEnum.FR:
                case LayoutAlgorithmTypeEnum.Tree:
                    for (int i = 1; i < 14; i++)
                    {
                        var dataVertex = new DataVertex("MyVertex " + i) { ID = i, VisualDiameter = _rnd.Next(25, 50), VisualInnerDiameter = _rnd.Next(10, 22) };
                        dataGraph.AddVertex(dataVertex);
                    }
                    vlist = dataGraph.Vertices.ToList();
                    AddEdge(dataGraph, 0, 1, vlist);
                    AddEdge(dataGraph, 0, 0, vlist);

                    AddEdge(dataGraph, 0, 2, vlist);
                    AddEdge(dataGraph, 1, 3, vlist);
                    AddEdge(dataGraph, 1, 4, vlist);
                    AddEdge(dataGraph, 2, 5, vlist);
                    AddEdge(dataGraph, 2, 6, vlist);
                    AddEdge(dataGraph, 2, 7, vlist);

                    AddEdge(dataGraph, 8, 9, vlist);
                    AddEdge(dataGraph, 9, 10, vlist);
                    AddEdge(dataGraph, 10, 7, vlist);
                    AddEdge(dataGraph, 10, 11, vlist);
                    AddEdge(dataGraph, 10, 12, vlist);

                    break;
                default:
                     for (var i = 1; i < 11; i++)
                    {
                        var dataVertex = new DataVertex("MyVertex " + i) { ID = i, VisualDiameter = _rnd.Next(50, 100), VisualInnerDiameter = _rnd.Next(20, 45) };
                        if (i == 2)
                            dataVertex.LabelText += "\nMultiline!";
                        dataGraph.AddVertex(dataVertex);
                    }
                     vlist = dataGraph.Vertices.ToList();
                    AddEdge(dataGraph, 0, 1, vlist);

                    AddEdge(dataGraph, 1, 2, vlist);
                    AddEdge(dataGraph, 1, 3, vlist);
                    AddEdge(dataGraph, 1, 4, vlist);

                    AddEdge(dataGraph, 4, 5, vlist);
                    AddEdge(dataGraph, 4, 6, vlist);

                    AddEdge(dataGraph, 2, 7, vlist);
                    AddEdge(dataGraph, 2, 8, vlist);

                    AddEdge(dataGraph, 8, 9, vlist);

                    //add some cross references
                    AddEdge(dataGraph, 4, 2, vlist);
                    AddEdge(dataGraph, 4, 8, vlist);
                    AddEdge(dataGraph, 9, 2, vlist);

                    break;
            }

           /* foreach (var item in graph.EdgesList)
            {
                //item.Value.LabelVerticalOffset = -40;
                item.Value.LabelAngle = 45;
            }*/


            return dataGraph;

            /*ManipulationDelta += MainPage_ManipulationDelta;
            ManipulationMode = ManipulationModes.Scale;

            for (int i = 1; i < 10; i++)
            {
                var dataVertex = new DataVertex("MyVertex " + i) { ID = i };
                dataGraph.AddVertex(dataVertex);
            }

            var vlist = dataGraph.Vertices.ToList();
            //var dataEdge = new DataEdge(vlist[0], vlist[1]) { Text = string.Format("{0} -> {1}", vlist[0], vlist[1]) };
            //dataGraph.AddEdge(dataEdge);
            var dataEdge = new DataEdge(vlist[2], vlist[3]) { Text = "23" }; 
            dataGraph.AddEdge(dataEdge);
            dataEdge = new DataEdge(vlist[3], vlist[2]) { Text = "32" };
            dataGraph.AddEdge(dataEdge);

            return dataGraph;*/
        }
Exemplo n.º 30
0
        void erg_but_randomgraph_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            if ((EdgeRoutingAlgorithmTypeEnum)erg_eralgo.SelectedItem != EdgeRoutingAlgorithmTypeEnum.Bundling)
            {
                var gr = GenerateDataGraph(30);

                if (erg_Area.LogicCore.EnableParallelEdges)
                {
                    if (erg_Area.VertexList.Count() < 2)
                    {
                        var v1 = new DataVertex(); gr.AddVertex(v1);
                        var v2 = new DataVertex(); gr.AddVertex(v2);
                        gr.AddEdge(new DataEdge(v1, v2) { Text = string.Format("{0} -> {1}", v1.Text, v2.Text) });
                        gr.AddEdge(new DataEdge(v2, v1) { Text = string.Format("{0} -> {1}", v2.Text, v1.Text) });
                    }
                    else
                    {
                        var v1 = gr.Vertices.ToList()[0];
                        var v2 = gr.Vertices.ToList()[1];
                        gr.AddEdge(new DataEdge(v1, v2) { Text = string.Format("{0} -> {1}", v1.Text, v2.Text) });
                        gr.AddEdge(new DataEdge(v2, v1) { Text = string.Format("{0} -> {1}", v2.Text, v1.Text) });
                    }
                }

                erg_Area.GetLogicCore<LogicCoreExample>().DefaultEdgeRoutingAlgorithm = (EdgeRoutingAlgorithmTypeEnum)erg_eralgo.SelectedItem;
                switch ((EdgeRoutingAlgorithmTypeEnum)erg_eralgo.SelectedItem)
                {
                    case EdgeRoutingAlgorithmTypeEnum.SimpleER:
                        erg_Area.GetLogicCore<LogicCoreExample>().DefaultEdgeRoutingAlgorithmParams = erg_SimpleERParameters;
                        break;
                    case EdgeRoutingAlgorithmTypeEnum.PathFinder:
                        erg_Area.GetLogicCore<LogicCoreExample>().DefaultEdgeRoutingAlgorithmParams = erg_PFERParameters;
                       // erg_Area.SideExpansionSize = new Size(erg_PFERParameters.SideGridOffset, erg_PFERParameters.SideGridOffset);
                        break;
                }

                erg_Area.GetLogicCore<LogicCoreExample>().DefaultLayoutAlgorithm = LayoutAlgorithmTypeEnum.SimpleRandom;
                erg_Area.GetLogicCore<LogicCoreExample>().DefaultOverlapRemovalAlgorithm = OverlapRemovalAlgorithmTypeEnum.FSA;
                erg_Area.GetLogicCore<LogicCoreExample>().DefaultOverlapRemovalAlgorithmParams = erg_Area.LogicCore.AlgorithmFactory.CreateOverlapRemovalParameters(OverlapRemovalAlgorithmTypeEnum.FSA);
                var oprm = erg_Area.GetLogicCore<LogicCoreExample>().DefaultOverlapRemovalAlgorithmParams as OverlapRemovalParameters;
                //oprm.HorizontalGap = 100;
                //oprm.VerticalGap = 100;
                //erg_Area.ExternalEdgeRoutingAlgorithm = new SimpleEdgeRouting<DataVertex, DataEdge,  GraphExample>(gr as GraphExample, erg_Area.GetVertexPositions(), erg_Area.GetVertexSizeRectangles());

                erg_Area.GenerateGraph(gr);
                erg_zoomctrl.ZoomToFill();//.ZoomToFill();
                erg_Area.GenerateAllEdges();
                foreach (var item in erg_Area.GetAllVertexControls())
                    DragBehaviour.SetIsDragEnabled(item, true);
                erg_recalculate_Checked(null, null);
                erg_showEdgeArrows_Checked(null, null);
                erg_showEdgeLabels_Checked(null, null);
                erg_alignEdgeLabels_Checked(null, null);
                return;
            }

            erg_Area.RemoveAllEdges();
            erg_Area.RemoveAllVertices();
            //generate graph
            var graph = new GraphExample();
            foreach (var item in DataSource.Take(120))
                graph.AddVertex(new DataVertex(item.Text) { ID = item.ID });

            var vlist = graph.Vertices.ToList();
            foreach (var item in vlist)
            {
                if (Rand.Next(0, 50) > 25) continue;
                var vertex2 = vlist[Rand.Next(0, graph.VertexCount - 1)];
                graph.AddEdge(new DataEdge(item, vertex2, Rand.Next(1, 50)) { ToolTipText = string.Format("{0} -> {1}", item, vertex2) });
            }
               /* graph.AddEdge(new DataEdge(vlist[0], vlist[3], 1));
            graph.AddEdge(new DataEdge(vlist[1], vlist[4], 1));
            graph.AddEdge(new DataEdge(vlist[2], vlist[5], 1));

            graph.AddEdge(new DataEdge(vlist[0], vlist[6], 1));
            graph.AddEdge(new DataEdge(vlist[1], vlist[7], 1));
            graph.AddEdge(new DataEdge(vlist[2], vlist[8], 1));
            //generate vertex positions
            var VertexPositions = new Dictionary<DataVertex, Point>();

            VertexPositions.Add(vlist[6], new Point(5000, 1000));
            VertexPositions.Add(vlist[7], new Point(5000, 1100));
            VertexPositions.Add(vlist[8], new Point(5000, 1300));

            VertexPositions.Add(vlist[0], new Point(100, 100));
            VertexPositions.Add(vlist[1], new Point(300, 100));
            VertexPositions.Add(vlist[2], new Point(200, 300));

            VertexPositions.Add(vlist[3], new Point(10000, 1000));
            VertexPositions.Add(vlist[4], new Point(10300, 1000));
            VertexPositions.Add(vlist[5], new Point(10200, 1300));*/
            //generate vertices

            var VertexPositions = new Dictionary<DataVertex, Point>();
            foreach (var item in GenerateRandomVertices(graph, 0, 40, 0, 2000, 0, 2000))
                VertexPositions.Add(item.Key, item.Value);
            foreach (var item in GenerateRandomVertices(graph, 40, 40, 5000, 7000, 3000, 4000))
                VertexPositions.Add(item.Key, item.Value);
            foreach (var item in GenerateRandomVertices(graph, 80, 40, 500, 2500, 6000, 9000))
                VertexPositions.Add(item.Key, item.Value);
            erg_Area.LogicCore.Graph = graph;
            UpdateLayout();

            CalcBundling();

            //generate edges
            erg_Area.GenerateAllEdges(Visibility.Visible);
            foreach (var item in erg_Area.GetAllVertexControls())
                DragBehaviour.SetIsDragEnabled(item, true);
            erg_recalculate_Checked(null, null);
            erg_showEdgeArrows_Checked(null, null);
            erg_showEdgeLabels_Checked(null, null);
            erg_zoomctrl.ZoomToFill();
        }
Exemplo n.º 31
0
        /// <summary>
        /// Generate example graph data
        /// </summary>
        /// <param name="count">Items count</param>
        private GraphExample GenerateDataGraph(int count)
        {
            var graph = new GraphExample();

            foreach (var item in DataSource.Take(count))
                graph.AddVertex(new DataVertex(item.Text) { ID = item.ID });

            var vlist = graph.Vertices.ToList();

            /*graph.AddEdge(new DataEdge(vlist[0], vlist[3], 1));
            graph.AddEdge(new DataEdge(vlist[1], vlist[4], 1));
            graph.AddEdge(new DataEdge(vlist[2], vlist[5], 1));*/
            var cnt = 1;
            foreach (var item in vlist)
            {
                if (Rand.Next(0, 50) > 25) continue;
                var vertex2 = vlist[Rand.Next(0, graph.VertexCount - 1)];
                graph.AddEdge(new DataEdge(item, vertex2, Rand.Next(1, 50)) { ID = cnt, Text = string.Format("{0} -> {1}", item.Text, vertex2.Text) });
                cnt++;
            }
            return graph;
        }
Exemplo n.º 32
0
        public GraphExample Graph_Setup(string FOCUS = "")
        {
            if (Produit.GrandeurPhysiques == null)
            {
                return(null);
            }

            var dataGraph = new GraphExample();

            if (FOCUS == "FOCUS")
            {
                foreach (var GP in Produit.GrandeurPhysiques)
                {
                    if (GP.Value.Selectionne)
                    {
                        var dataVertex = new DataVertex(GP.Key);
                        dataGraph.AddVertex(dataVertex);
                    }
                }
            }
            else if (FOCUS == "ENSEMBLE")
            {
                foreach (var GP in Produit.GrandeurPhysiques)
                {
                    var dataVertex = new DataVertex(GP.Key);
                    dataGraph.AddVertex(dataVertex);
                }
            }
            else
            {
                foreach (var GP in Produit.GrandeurPhysiques)
                {
                    if (GP.Value.EstPremier)
                    {
                        var dataVertex = new DataVertex(GP.Key);
                        dataGraph.AddVertex(dataVertex);
                    }
                }
            }

            //Now lets make some edges that will connect our vertices
            //get the indexed list of graph vertices we have already added
            var vlist    = dataGraph.Vertices.ToList();
            var dataEdge = new DataEdge(); //= new DataEdge(vlist[0], vlist[1]);

            //dataGraph.AddEdge(dataEdge);
            foreach (var R1 in vlist)
            {
                foreach (var R2 in vlist)
                {
                    if (Relation.MatriceRelations[Produit.GrandeurPhysiques[R1.Text].iM][
                            Produit.GrandeurPhysiques[R2.Text].iM] != null)
                    {
                        if (Relation.MatriceRelations[Produit.GrandeurPhysiques[R1.Text].iM][
                                Produit.GrandeurPhysiques[R2.Text].iM] != 1 - 1)
                        {
                            dataEdge = new DataEdge(R1, R2);
                            dataGraph.AddEdge(dataEdge);
                        }
                    }
                }
            }

            return(dataGraph);
        }
Exemplo n.º 33
0
        void erg_but_randomgraph_Click(object sender, RoutedEventArgs e)
        {

            if ((EdgeRoutingAlgorithmTypeEnum)erg_eralgo.SelectedItem != EdgeRoutingAlgorithmTypeEnum.Bundling)
            {
                var gr = ShowcaseHelper.GenerateDataGraph(30);

                if (erg_Area.LogicCore.EnableParallelEdges)
                {
                    if (erg_Area.VertexList.Count() < 2)
                    {
                        var v1 = new DataVertex(); gr.AddVertex(v1);
                        var v2 = new DataVertex(); gr.AddVertex(v2);
                        gr.AddEdge(new DataEdge(v1, v2) { Text = string.Format("{0} -> {1}", v1.Text, v2.Text) });
                        gr.AddEdge(new DataEdge(v2, v1) { Text = string.Format("{0} -> {1}", v2.Text, v1.Text) });
                    }
                    else
                    {
                        var v1 = gr.Vertices.ToList()[0];
                        var v2 = gr.Vertices.ToList()[1];
                        gr.AddEdge(new DataEdge(v1, v2) { Text = string.Format("{0} -> {1}", v1.Text, v2.Text) });
                        gr.AddEdge(new DataEdge(v2, v1) { Text = string.Format("{0} -> {1}", v2.Text, v1.Text) });
                    }
                }

                erg_Area.GetLogicCore<LogicCoreExample>().DefaultEdgeRoutingAlgorithm = (EdgeRoutingAlgorithmTypeEnum)erg_eralgo.SelectedItem;
                switch ((EdgeRoutingAlgorithmTypeEnum)erg_eralgo.SelectedItem)
                {
                    case EdgeRoutingAlgorithmTypeEnum.SimpleER:
                        erg_Area.GetLogicCore<LogicCoreExample>().DefaultEdgeRoutingAlgorithmParams = SimpleErParameters;
                        break;
                    case EdgeRoutingAlgorithmTypeEnum.PathFinder:
                        erg_Area.GetLogicCore<LogicCoreExample>().DefaultEdgeRoutingAlgorithmParams = PfErParameters;
                        break;
                }

                erg_Area.GetLogicCore<LogicCoreExample>().DefaultLayoutAlgorithm = LayoutAlgorithmTypeEnum.SimpleRandom;
                erg_Area.GetLogicCore<LogicCoreExample>().DefaultOverlapRemovalAlgorithm = OverlapRemovalAlgorithmTypeEnum.FSA;
                erg_Area.GetLogicCore<LogicCoreExample>().DefaultOverlapRemovalAlgorithmParams = erg_Area.LogicCore.AlgorithmFactory.CreateOverlapRemovalParameters(OverlapRemovalAlgorithmTypeEnum.FSA);

                erg_Area.GenerateGraph(gr, true);
                erg_Area.SetVerticesDrag(true, true);
                erg_zoomctrl.ZoomToFill();

                return;
            }

            erg_Area.RemoveAllEdges();
            erg_Area.RemoveAllVertices();
            //generate graph
            var graph = new GraphExample();
            foreach (var item in ShowcaseHelper.DataSource.Take(120))
                graph.AddVertex(new DataVertex(item.Text) { ID = item.ID });

            var vlist = graph.Vertices.ToList();
            foreach (var item in vlist)
            {
                if (ShowcaseHelper.Rand.Next(0, 50) > 25) continue;
                var vertex2 = vlist[ShowcaseHelper.Rand.Next(0, graph.VertexCount - 1)];
                graph.AddEdge(new DataEdge(item, vertex2, ShowcaseHelper.Rand.Next(1, 50)) { ToolTipText = string.Format("{0} -> {1}", item, vertex2) });
            }

            //generate vertices

            var vertexPositions = GenerateRandomVertices(graph, 0, 40, 0, 2000, 0, 2000).ToDictionary(item => item.Key, item => item.Value);
            foreach (var item in GenerateRandomVertices(graph, 40, 40, 5000, 7000, 3000, 4000))
                vertexPositions.Add(item.Key, item.Value);
            foreach (var item in GenerateRandomVertices(graph, 80, 40, 500, 2500, 6000, 9000))
                vertexPositions.Add(item.Key, item.Value);
            erg_Area.LogicCore.Graph = graph;
            UpdateLayout();

            erg_Area.SetVerticesDrag(true);
            _logicCore.DefaultLayoutAlgorithm = LayoutAlgorithmTypeEnum.Custom;
            _logicCore.DefaultEdgeRoutingAlgorithm = EdgeRoutingAlgorithmTypeEnum.Bundling;
            _logicCore.DefaultEdgeRoutingAlgorithmParams = BundleEdgeRoutingParameters;
            erg_Area.GenerateGraph(true);

            erg_zoomctrl.ZoomToFill();
        }
Exemplo n.º 34
0
        private void GenerateGraph(bool reset = false)
        {
            gr.Clear();
            foreach (var d in Story.Dialogs)
            {
                gr.AddVertex(new DialogVertex(d));
            }

            foreach (var v in gr.Vertices)
            {
                foreach (var o in v.Dialog.Options)
                {
                    if (!o.TargetID.IsNullOrEmpty())
                    {
                        gr.AddEdge(new DialogEdge(v, gr.Vertices.First(x => x.Dialog.ID == o.TargetID))
                        {
                            DialogOption = o
                        });
                    }
                }
            }

            if (graph.LogicCore == null)
            {
                var LogicCore = new GXLogicCoreExample()
                {
                    Graph = gr
                };
                LogicCore.DefaultLayoutAlgorithm       = LayoutAlgorithmTypeEnum.Tree;
                LogicCore.DefaultLayoutAlgorithmParams =
                    LogicCore.AlgorithmFactory.CreateLayoutParameters(LayoutAlgorithmTypeEnum.Tree);
                ((SimpleTreeLayoutParameters)LogicCore.DefaultLayoutAlgorithmParams).Direction = LayoutDirection.LeftToRight;
                //LogicCore.DefaultOverlapRemovalAlgorithm = OverlapRemovalAlgorithmTypeEnum.OneWayFSA;
                //LogicCore.DefaultOverlapRemovalAlgorithmParams = LogicCore.AlgorithmFactory.CreateOverlapRemovalParameters(OverlapRemovalAlgorithmTypeEnum.OneWayFSA);
                //LogicCore.DefaultOverlapRemovalAlgorithmParams.HorizontalGap = 50;
                //LogicCore.DefaultOverlapRemovalAlgorithmParams.VerticalGap = 50;
                LogicCore.DefaultEdgeRoutingAlgorithm = EdgeRoutingAlgorithmTypeEnum.None;
                LogicCore.AsyncAlgorithmCompute       = false;
                LogicCore.EdgeCurvingEnabled          = true;
                LogicCore.EnableParallelEdges         = true;
                LogicCore.ParallelEdgeDistance        = 10;

                graph.LogicCore = LogicCore;
            }

            graph.GenerateGraph(true, true);
            if (!reset && path.Length > 0 && File.Exists(path.Replace(".apstp", ".apmap")))
            {
                System.Xml.Serialization.XmlSerializer xml = new System.Xml.Serialization.XmlSerializer(typeof(List <GraphPos>));
                try
                {
                    using (var fs = File.OpenRead(path.Replace(".apstp", ".apmap")))
                        pos = xml.Deserialize(fs) as List <GraphPos>;
                    Relayout(false);
                }
                catch { }
            }
            graph.ShowAllEdgesLabels(false);
            graph.SetVerticesDrag(true, true);
            graph.SetEdgesDashStyle(EdgeDashStyle.Dash);
            foreach (var v in graph.VertexList)
            {
                v.Value.Background = v.Key.Dialog.Tag == null ? Brushes.LightGray : new SolidColorBrush(v.Key.Dialog.Tag.Color.ToMediaColor());
            }
        }
Exemplo n.º 35
0
        public MainWindow()
        {
            InitializeComponent();

            ZoomControl.SetViewFinderVisibility(GgZoomctrl, Visibility.Visible);
            //Set Fill zooming strategy so whole graph will be always visible
            GgZoomctrl.ZoomToFill();

            var packageKeys = new[]
            {
                new PackageKey("NServiceBus.NHibernate", "4.5.5"),
                //new PackageKey("FluentNHibernate", "1.4.0"),
                //new PackageKey("Common.Logging", "3.3.1"),
                ////new PackageKey("Common.Logging", "3.3.1"),
                //new PackageKey("Common.Logging.Core", "3.3.1"),
                //new PackageKey("Iesi.Collections", "3.2.0.4000"),
                //new PackageKey("log4net", "1.2.10"),
                //new PackageKey("Microsoft.AspNet.WebApi.Client", "5.2.3"),
                //new PackageKey("Microsoft.AspNet.WebApi.Core", "5.2.3"),
                //new PackageKey("Microsoft.AspNet.WebApi.Owin", "5.2.3"),
                //new PackageKey("Microsoft.Owin", "2.0.2"),
                //new PackageKey("Microsoft.Owin.Diagnostics", "2.0.2"),
                //new PackageKey("Microsoft.Owin.Host.HttpListener", "2.0.2"),
                //new PackageKey("Microsoft.Owin.Hosting", "2.0.2"),
                //new PackageKey("Microsoft.Owin.SelfHost", "2.0.2"),
                //new PackageKey("Newtonsoft.Json", "6.0.8"),
                //new PackageKey("NHibernate", "3.4.1.4000"),
                //new PackageKey("NServiceBus", "2.6.0.1505"),
                //new PackageKey("NServiceBus.StructureMap", "2.6.0.1505"),
                //new PackageKey("NUnit", "2.5.7.10213"),
                //new PackageKey("Owin", "1.0"),
                //new PackageKey("Quartz", "1.0.3"),
                //new PackageKey("RhinoMocks", "3.6"),
                //new PackageKey("SharpZipLib", "0.86.0"),
                //new PackageKey("SmartThreadPool.dll", "2.2.3"),
                //new PackageKey("Spring.Aop", "2.0.1"),
                //new PackageKey("Spring.Core", "2.0.1"),
                //new PackageKey("Spring.Data", "2.0.1"),
                //new PackageKey("Spring.Data.NHibernate3", "2.0.1"),
                //new PackageKey("Spring.Services", "2.0.1"),
                //new PackageKey("Spring.Testing.NUnit", "2.0.1"),
                //new PackageKey("structuremap", "2.6.2")
            };

            var storage           = new Storage <PackageDto>("Storage");
            var packageRepository = PackageRepositoryFactory.Default.CreateRepository("https://packages.nuget.org/api/v2");
            var nugetLibraryProxy = new NugetLibraryProxy(storage, packageRepository);
            var inspector         = new PackageInspector(nugetLibraryProxy);

            var node = inspector.InspectPackage(packageKeys)
                       .ToList();


            DataContext = new MainWindowViewModel(new MainWindowModel(nugetLibraryProxy, packageKeys));

            var restrictions = new Dictionary <string, VersionSpec>();

            node.ForEachItem(
                x =>
            {
                x.Value.Dependencies.ForEachItem(
                    y =>
                {
                    var key = y.Id;
                    VersionSpec restrictedVersion;
                    if (restrictions.ContainsKey(key))
                    {
                        restrictedVersion = y.VersionSpec.Intersect(restrictions[key]);
                        Debug.WriteLine($"intersecting {y.VersionSpec} with {restrictions[key]} -> {restrictedVersion}");
                    }
                    else
                    {
                        restrictedVersion = y.VersionSpec;
                    }
                    restrictions[key] = restrictedVersion;
                });
            });

            restrictions.ForEachItem(
                x => { Debug.WriteLine($"{x.Key} : {x.Value}"); });

            node = node.Select(
                x => x.Filter <PackageNode>(
                    y =>
            {
                var key = y.Key.Id;
                if (!restrictions.ContainsKey(key))
                {
                    if (x.Parent == null)
                    {
                        return(true);
                    }

                    Debug.WriteLine($"no restriction for {key}");
                    return(false);
                }
                var restriction = restrictions[key];
                return(restriction.Satisfies(y.SemanticVersion));
            }))
                   .Where(x => x != null)
                   .ToList();

            var graph = new GraphExample();

            var graphNodes   = new Dictionary <string, DataVertex>();
            var groupIds     = new Dictionary <string, int>();
            var nextId       = 1L;
            var nextGroupId  = 1;
            var visitedNodes = new HashSet <PackageKey>();

            node.ForEachItem(
                x =>
            {
                x.ForEachItem(
                    y =>
                {
                    var packageDto = y.Value;
                    var packageKey = packageDto.Key;
                    var packageId  = packageKey.Id;

                    var nodeKey = ComposeNodeKey(packageDto);

                    if (!groupIds.ContainsKey(packageId))
                    {
                        groupIds[packageId] = nextGroupId++;
                    }

                    if (visitedNodes.Contains(packageKey))
                    {
                        return;
                    }
                    var existing = storage.GetById(packageId)
                                   .Value
                                   .Select(z => z.Key)
                                   .ToList();
                    visitedNodes.Add(packageKey);

                    if (graphNodes.ContainsKey(nodeKey))
                    {
                        var existring = graphNodes[nodeKey];
                        existring.AddVersion(existing, packageKey);
                        return;
                    }
                    var dataVertex = new DataVertex(packageId)
                    {
                        ID      = nextId++,
                        GroupId = groupIds[packageId]
                    };
                    dataVertex.AddVersion(existing, packageKey);

                    graphNodes[nodeKey] = dataVertex;
                    graph.AddVertex(dataVertex);
                });
            });

            node.ForEachItem(
                x =>
            {
                x.ForEachItem(
                    y =>
                {
                    if (y.Parent == null)
                    {
                        return;
                    }
                    var packageDto = y.Value;
                    var thisKey    = ComposeNodeKey(packageDto);
                    var thisVertex = graphNodes[thisKey];

                    var parent    = y.Parent.Value;
                    var parentKey = ComposeNodeKey(parent);

                    if (graphNodes.ContainsKey(parentKey))
                    {
                        var parentVertex = graphNodes[parentKey];
                        graph.AddEdge(new DataEdge(thisVertex, parentVertex));
                    }
                    else
                    {
                        Debug.WriteLine($"no parent node for this: {thisKey} parent: {parentKey}");
                    }
                });
            });

            var logicCore = new GxLogicCoreExample
            {
                Graph = graph
            };

            logicCore.DefaultLayoutAlgorithm       = LayoutAlgorithmTypeEnum.KK;
            logicCore.DefaultLayoutAlgorithmParams = logicCore.AlgorithmFactory.CreateLayoutParameters(LayoutAlgorithmTypeEnum.KK);
            ((KKLayoutParameters)logicCore.DefaultLayoutAlgorithmParams).MaxIterations = 4000;
            logicCore.DefaultOverlapRemovalAlgorithm = OverlapRemovalAlgorithmTypeEnum.FSA;
            logicCore.DefaultOverlapRemovalAlgorithmParams.HorizontalGap = 200;
            logicCore.DefaultOverlapRemovalAlgorithmParams.VerticalGap   = 150;

            logicCore.DefaultEdgeRoutingAlgorithm = EdgeRoutingAlgorithmTypeEnum.SimpleER;

            logicCore.AsyncAlgorithmCompute = false;

            GgArea.LogicCore = logicCore;

            GgArea.GenerateGraph(true, true);

            /*
             * After graph generation is finished you can apply some additional settings for newly created visual vertex and edge controls
             * (VertexControl and EdgeControl classes).
             *
             */

            //This method sets the dash style for edges. It is applied to all edges in Area.EdgesList. You can also set dash property for
            //each edge individually using EdgeControl.DashStyle property.
            //For ex.: Area.EdgesList[0].DashStyle = GraphX.EdgeDashStyle.Dash;
            GgArea.SetEdgesDashStyle(EdgeDashStyle.Dash);

            //This method sets edges arrows visibility. It is also applied to all edges in Area.EdgesList. You can also set property for
            //each edge individually using property, for ex: Area.EdgesList[0].ShowArrows = true;
            GgArea.ShowAllEdgesArrows(true);

            //This method sets edges labels visibility. It is also applied to all edges in Area.EdgesList. You can also set property for
            //each edge individually using property, for ex: Area.EdgesList[0].ShowLabel = true;
            GgArea.ShowAllEdgesLabels(true);

            GgZoomctrl.ZoomToFill();
        }
Exemplo n.º 36
0
        private void UpdateTabGraphX(Solution s)
        {
            //Create data graph object
            var graph = new GraphExample();

            //Create and add vertices using some DataSource for ID's
            foreach (Node n in ModelManager.Instance.Filecvrp.LstNodes)
            {
                graph.AddVertex(new DataVertex()
                {
                    ID = n.Id, Text = n.Id.ToString()
                });
            }
            foreach (List <Node> ruta in s.BestRutas)
            {
                if (ruta.Count > 0)
                {
                    DataVertex origen  = graph.Vertices.ToList()[ModelManager.Instance.Filecvrp.IdNodeDepot - 1];
                    DataVertex destino = graph.Vertices.ToList()[ruta[0].Id - 1];
                    graph.AddEdge(new DataEdge(origen, destino));
                    for (int i = 0; i < ruta.Count - 1; i++)
                    {
                        origen  = graph.Vertices.ToList()[ruta[i].Id - 1];
                        destino = graph.Vertices.ToList()[ruta[i + 1].Id - 1];
                        graph.AddEdge(new DataEdge(origen, destino));
                    }

                    origen  = graph.Vertices.ToList()[ruta[ruta.Count - 1].Id - 1];
                    destino = graph.Vertices.ToList()[ModelManager.Instance.Filecvrp.IdNodeDepot - 1];
                    graph.AddEdge(new DataEdge(origen, destino));
                }
            }

            var LogicCore = new GXLogicCoreExample();

            LogicCore.Graph = graph;
            //This property sets layout algorithm that will be used to calculate vertices positions
            //Different algorithms uses different values and some of them uses edge Weight property.
            LogicCore.DefaultLayoutAlgorithm = GraphX.PCL.Common.Enums.LayoutAlgorithmTypeEnum.KK;
            //Now we can set optional parameters using AlgorithmFactory
            //NOTE: default parameters can be automatically created each time you change Default algorithms
            LogicCore.DefaultLayoutAlgorithmParams =
                LogicCore.AlgorithmFactory.CreateLayoutParameters(GraphX.PCL.Common.Enums.LayoutAlgorithmTypeEnum.KK);
            //Unfortunately to change algo parameters you need to specify params type which is different for every algorithm.
            ((KKLayoutParameters)LogicCore.DefaultLayoutAlgorithmParams).MaxIterations = 100;

            //This property sets vertex overlap removal algorithm.
            //Such algorithms help to arrange vertices in the layout so no one overlaps each other.
            LogicCore.DefaultOverlapRemovalAlgorithm = GraphX.PCL.Common.Enums.OverlapRemovalAlgorithmTypeEnum.FSA;
            //Setup optional params
            LogicCore.DefaultOverlapRemovalAlgorithmParams =
                LogicCore.AlgorithmFactory.CreateOverlapRemovalParameters(GraphX.PCL.Common.Enums.OverlapRemovalAlgorithmTypeEnum.FSA);
            ((OverlapRemovalParameters)LogicCore.DefaultOverlapRemovalAlgorithmParams).HorizontalGap = 50;
            ((OverlapRemovalParameters)LogicCore.DefaultOverlapRemovalAlgorithmParams).VerticalGap   = 50;

            //This property sets edge routing algorithm that is used to build route paths according to algorithm logic.
            //For ex., SimpleER algorithm will try to set edge paths around vertices so no edge will intersect any vertex.
            LogicCore.DefaultEdgeRoutingAlgorithm = GraphX.PCL.Common.Enums.EdgeRoutingAlgorithmTypeEnum.SimpleER;

            //This property sets async algorithms computation so methods like: Area.RelayoutGraph() and Area.GenerateGraph()
            //will run async with the UI thread. Completion of the specified methods can be catched by corresponding events:
            //Area.RelayoutFinished and Area.GenerateGraphFinished.
            LogicCore.AsyncAlgorithmCompute = false;

            LogicCoreSolution = LogicCore;
        }