示例#1
0
 void clearEdgeDrawing()
 {
     _edGeo = null;
     if (_edFakeDV != null)
         dg_Area.LogicCore.Graph.RemoveVertex(_edFakeDV);
     _edFakeDV = null;
     _edVertex = null;
     _edEdge = null;
 }
示例#2
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;
        }
        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);
        }
示例#4
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();
        }
示例#5
0
        void dg_addvertex_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            /*var data = new DataVertex("Vertex "+ dg_Area.VertexList.Count + 1);
            dg_Area.LogicCore.Graph.AddVertex(data);
            dg_Area.AddVertex(data, new VertexControl(data));
            dg_Area.VertexList.Values.Last().SetPosition(new Point(0,0));

            data = new DataVertex("Vertex " + dg_Area.VertexList.Count + 2);
            dg_Area.LogicCore.Graph.AddVertex(data);
            dg_Area.AddVertex(data, new VertexControl(data));
            dg_Area.VertexList.Values.Last().SetPosition(new Point(300, 300));
            data = new DataVertex("Vertex " + dg_Area.VertexList.Count + 2);
            dg_Area.LogicCore.Graph.AddVertex(data);
            dg_Area.AddVertex(data, new VertexControl(data));
            dg_Area.VertexList.Values.Last().SetPosition(new Point(0, 300));

            dg_zoomctrl.ZoomToFill();
            return;*/

            var data = new DataVertex("Vertex " + dg_Area.VertexList.Count() + 1);
            dg_Area.LogicCore.Graph.AddVertex(data);
            dg_Area.AddVertex(data, new VertexControl(data));

            dg_Area.RelayoutGraph(true);
            dg_zoomctrl.ZoomToFill();
        }
示例#6
0
        void dg_Area_VertexSelectedForED(object sender, GraphX.Models.VertexSelectedEventArgs args)
        {
            if (_isInEDMode)
            {
                if (_edVertex == null) //select starting vertex
                {
                    _edVertex = args.VertexControl;
                    _edFakeDV = new DataVertex() { ID = -666 };
                    _edGeo = new PathGeometry(new PathFigureCollection() { new PathFigure() { IsClosed = false, StartPoint = _edVertex.GetPosition(), Segments = new PathSegmentCollection() { new PolyLineSegment(new List<Point>() { new Point() }, true) } } });
                    var dedge = new DataEdge(_edVertex.Vertex as DataVertex, _edFakeDV);
                    _edEdge = new EdgeControl(_edVertex, null, dedge) { ManualDrawing = true };
                    dg_Area.AddEdge(dedge, _edEdge);
                    dg_Area.LogicCore.Graph.AddVertex(_edFakeDV);
                    dg_Area.LogicCore.Graph.AddEdge(dedge);
                    _edEdge.SetEdgePathManually(_edGeo);
                }
                else if (_edVertex != args.VertexControl) //finish draw
                {
                    _edEdge.Target = args.VertexControl;
                    var dedge = _edEdge.Edge as DataEdge;
                    dedge.Target = args.VertexControl.Vertex as DataVertex;
                    var fig = _edGeo.Figures[0];
                    var seg = fig.Segments[_edGeo.Figures[0].Segments.Count - 1] as PolyLineSegment;

                    if (seg.Points.Count > 0)
                    {
                        var targetPos = _edEdge.Target.GetPosition();
                        var sourcePos = _edEdge.Source.GetPosition();
                        //get the size of the source
                        var sourceSize = new Size()
                        {
                            Width = _edEdge.Source.ActualWidth,
                            Height = _edEdge.Source.ActualHeight
                        };
                        var targetSize = new Size()
                        {
                            Width = _edEdge.Target.ActualWidth,
                            Height = _edEdge.Target.ActualHeight
                        };

                        var src_start = seg.Points.Count == 0 ? fig.StartPoint : seg.Points[0];
                        var src_end = seg.Points.Count > 1 ? (seg.Points[seg.Points.Count - 1] == targetPos ? seg.Points[seg.Points.Count - 2] : seg.Points[seg.Points.Count - 1]) : fig.StartPoint;
                        Point p1 = GeometryHelper.GetEdgeEndpoint(sourcePos, new Rect(sourceSize), src_start, _edEdge.Source.MathShape);
                        Point p2 = GeometryHelper.GetEdgeEndpoint(targetPos, new Rect(targetSize), src_end, _edEdge.Target.MathShape);

                        fig.StartPoint = p1;
                        if (seg.Points.Count > 1)
                            seg.Points[seg.Points.Count - 1] = p2;
                    }
                    GeometryHelper.TryFreeze(_edGeo);
                    _edEdge.SetEdgePathManually(new PathGeometry(_edGeo.Figures));
                    _isInEDMode = false;
                    clearEdgeDrawing();
                }
            }
        }
示例#7
0
        void dg_Area_Drop(object sender, System.Windows.DragEventArgs e)
        {
            if (e.Data.GetDataPresent(typeof(object)))
            {
                //how to get dragged data by its type
                var myobject = e.Data.GetData(typeof(object)) as object;

                var pos = dg_zoomctrl.TranslatePoint(e.GetPosition(dg_zoomctrl), dg_Area);
                var data = new DataVertex();
                dg_Area.LogicCore.Graph.AddVertex(data);
                var vc = new VertexControl(data);
                dg_Area.AddVertex(data, vc);
                //dg_Area.RelayoutGraph(true);
                GraphAreaBase.SetX(vc, pos.X, true);
                GraphAreaBase.SetY(vc, pos.Y, true);
                if (dg_Area.VertexList.Count() == 1)
                {
                    var of = System.Windows.Media.VisualTreeHelper.GetOffset(vc);
                    int offset = 400;
                    dg_zoomctrl.ZoomTo(new Rect(of.X - offset, of.Y - offset, vc.ActualWidth + offset * 2, vc.ActualHeight + offset * 2));

                    /* //FOR ZoomControl
                    zoomctrl.Mode = GraphX.Controls.ZoomControlModes.Original;
                    */
                }else dg_zoomctrl.ZoomToFill();
            }
        }
示例#8
0
        void dg_Area_VertexSelectedForED(object sender, GraphX.Models.VertexSelectedEventArgs args)
        {
            if (_isInEDMode)
            {
                if (_edVertex == null) //select starting vertex
                {
                    _edVertex = args.VertexControl;
                    _edFakeDV = new DataVertex()
                    {
                        ID = -666
                    };
                    _edGeo = new PathGeometry(new PathFigureCollection()
                    {
                        new PathFigure()
                        {
                            IsClosed = false, StartPoint = _edVertex.GetPosition(), Segments = new PathSegmentCollection()
                            {
                                new PolyLineSegment(new List <Point>()
                                {
                                    new Point()
                                }, true)
                            }
                        }
                    });
                    var dedge = new DataEdge(_edVertex.Vertex as DataVertex, _edFakeDV);
                    _edEdge = new EdgeControl(_edVertex, null, dedge)
                    {
                        ManualDrawing = true
                    };
                    dg_Area.AddEdge(dedge, _edEdge);
                    dg_Area.LogicCore.Graph.AddVertex(_edFakeDV);
                    dg_Area.LogicCore.Graph.AddEdge(dedge);
                    _edEdge.SetEdgePathManually(_edGeo);
                }
                else if (_edVertex != args.VertexControl) //finish draw
                {
                    _edEdge.Target = args.VertexControl;
                    var dedge = _edEdge.Edge as DataEdge;
                    dedge.Target = args.VertexControl.Vertex as DataVertex;
                    var fig = _edGeo.Figures[0];
                    var seg = fig.Segments[_edGeo.Figures[0].Segments.Count - 1] as PolyLineSegment;

                    if (seg.Points.Count > 0)
                    {
                        var targetPos = _edEdge.Target.GetPosition();
                        var sourcePos = _edEdge.Source.GetPosition();
                        //get the size of the source
                        var sourceSize = new Size()
                        {
                            Width  = _edEdge.Source.ActualWidth,
                            Height = _edEdge.Source.ActualHeight
                        };
                        var targetSize = new Size()
                        {
                            Width  = _edEdge.Target.ActualWidth,
                            Height = _edEdge.Target.ActualHeight
                        };

                        var   src_start = seg.Points.Count == 0 ? fig.StartPoint : seg.Points[0];
                        var   src_end   = seg.Points.Count > 1 ? (seg.Points[seg.Points.Count - 1] == targetPos ? seg.Points[seg.Points.Count - 2] : seg.Points[seg.Points.Count - 1]) : fig.StartPoint;
                        Point p1        = GeometryHelper.GetEdgeEndpoint(sourcePos, new Rect(sourceSize), src_start, _edEdge.Source.MathShape);
                        Point p2        = GeometryHelper.GetEdgeEndpoint(targetPos, new Rect(targetSize), src_end, _edEdge.Target.MathShape);


                        fig.StartPoint = p1;
                        if (seg.Points.Count > 1)
                        {
                            seg.Points[seg.Points.Count - 1] = p2;
                        }
                    }
                    GeometryHelper.TryFreeze(_edGeo);
                    _edEdge.SetEdgePathManually(new PathGeometry(_edGeo.Figures));
                    _isInEDMode = false;
                    clearEdgeDrawing();
                }
            }
        }
示例#9
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);*/
        }
示例#10
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();
        }
示例#11
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();
        }
示例#12
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);*/
        }