Пример #1
0
        /// <summary>
        /// Creates a random connected graph and displayes a (non-unique) spanning tree using Prim's algorithm.
        /// </summary>
        /// <param name="diagram">The diagram.</param>
        /// <param name="specs">The specs.</param>
        private void Prims(RadDiagram diagram, GraphGenerationSpecifications specs)
        {
            diagram.Clear();
            Dictionary <Node, RadDiagramShape>      nodeMap;
            Dictionary <Edge, RadDiagramConnection> edgeMap;
            var randomConnectedGraph = GraphExtensions.CreateRandomConnectedGraph(10);
            var root = randomConnectedGraph.FindTreeRoot();
            var g    = diagram.CreateDiagram(randomConnectedGraph, out nodeMap, out edgeMap, GraphExtensions.CreateShape, specs.RandomShapeSize);

            // making it undirected will reach all the nodes since the random graph is connected
            g.IsDirected = false;
            var tree = g.PrimsSpanningTree(root);

            if (tree != null)
            {
                this.Highlight(tree, nodeMap, edgeMap, this.HighlighBrush);
            }
            var settings = new TreeLayoutSettings
            {
                TreeLayoutType       = TreeLayoutType.TreeDown,
                VerticalSeparation   = 50d,
                HorizontalSeparation = 80d,
            };

            diagram.Layout(LayoutType.Tree, settings);
        }
Пример #2
0
        /// <summary>
        /// Creates a tree which grows symmetrically.
        /// </summary>
        /// <param name="diagram">The diagram.</param>
        /// <param name="specs">The specs.</param>
        private void BalancedRadialTree(RadDiagram diagram, GraphGenerationSpecifications specs)
        {
            this.diagram.Clear();
            Dictionary <Node, RadDiagramShape>      nodeMap;
            Dictionary <Edge, RadDiagramConnection> edgeMap;

            // the algorithm to create a balanced tree is quite straighforward
            var g = this.diagram.CreateDiagram(GraphExtensions.CreateBalancedTree(), out nodeMap, out edgeMap, GraphExtensions.CreateShape, this.RandomSizeCheck.IsChecked.HasValue && this.RandomSizeCheck.IsChecked.Value);

            // the result is best displayed with the radial tree layout
            var settings = new TreeLayoutSettings
            {
                TreeLayoutType               = TreeLayoutType.RadialTree,
                HorizontalSeparation         = this.HorizontalSeparationSlider.Value,
                VerticalSeparation           = this.VerticalSeparationSlider.Value,
                UnderneathHorizontalOffset   = this.UnderneathHorizontalOffsetSlider.Value,
                UnderneathVerticalSeparation = this.UnderneathVerticalOffsetSlider.Value,
                StartRadialAngle             = Math.PI,
                // use a specific angle rather than the full 360° to show one of the layout's (hidden) gem
                EndRadialAngle = 3.47 * Math.PI / 2
            };
            var center = g.FindNode(-1);

            settings.Roots.Add(nodeMap[center]);
            var layout = new TreeLayout();

            layout.Layout(this.diagram, settings);

            // center and size autimagically
            this.diagram.AutoFit();

            // you can colorize the shapes, if you wish
            // this.Colorize(g, nodeMap, center);
        }
Пример #3
0
        /// <summary>
        /// Creates a forest of unbalanced trees and applies a radial layout.
        /// </summary>
        /// <param name="diagram">The diagram.</param>
        /// <param name="specs">The specs.</param>
        private void RandomRadialForest(RadDiagram diagram, GraphGenerationSpecifications specs)
        {
            this.diagram.Clear();
            Dictionary <Node, RadDiagramShape>      nodeMap;
            Dictionary <Edge, RadDiagramConnection> edgeMap;
            var g        = this.diagram.CreateDiagram(GraphExtensions.CreateRandomGraph(250, 4, true), out nodeMap, out edgeMap, GraphExtensions.CreateShape, this.RandomSizeCheck.IsChecked.HasValue && this.RandomSizeCheck.IsChecked.Value);
            var settings = new TreeLayoutSettings
            {
                TreeLayoutType                  = TreeLayoutType.RadialTree,
                HorizontalSeparation            = this.HorizontalSeparationSlider.Value,
                VerticalSeparation              = this.VerticalSeparationSlider.Value,
                UnderneathHorizontalOffset      = this.UnderneathHorizontalOffsetSlider.Value,
                UnderneathVerticalSeparation    = this.UnderneathVerticalOffsetSlider.Value,
                KeepComponentsInOneRadialLayout = true,
                RadialSeparation                = 45d
            };
            var center = g.FindNode(0);

            settings.Roots.Add(nodeMap[center]);
            var layout = new TreeLayout();

            layout.Layout(this.diagram, settings);
            this.diagram.AutoFit();
            //Colorize(g, nodeMap, center);
        }
Пример #4
0
 public static void CreateGraph(this RadDiagram diagram, GraphGenerationSpecifications specs, CreateShapeDelegate createShape)
 {
     diagram.Clear();
     if (specs.Connections)
     {
         var g = specs.Connected ? GraphExtensions.CreateRandomConnectedGraph(specs.NodeCount, 4, specs.TreeGraph) : GraphExtensions.CreateRandomGraph(specs.NodeCount, 4, specs.TreeGraph);
         diagram.CreateDiagram(g, GraphExtensions.CreateShape, specs.RandomShapeSize);
     }
     else
     {
         for (var i = 0; i < specs.NodeCount; i++)
         {
             var shape = createShape(new Node(i, false), specs.RandomShapeSize);
             diagram.AddShape(shape);
         }
     }
 }
Пример #5
0
        private void CreateContainersButton_OnClick(object sender, RoutedEventArgs e)
        {
            diagram.Clear();
            this.containerSampleRoots = new List <IShape>();

            var directors = diagram.CreateContainerShape("Board of directors");
            var ceo       = diagram.CreateShape("CEO");
            var cfo       = diagram.CreateShape("CFO");
            var cio       = diagram.CreateShape("CIO");

            GraphExtensions.ApplyColor(new SolidColorBrush(Colors.Green), ceo, cfo, cio);
            for (var i = 0; i < 5; i++)
            {
                var boardmember = diagram.CreateShape("M" + i);
                boardmember.Background = new SolidColorBrush(Colors.Purple);
                directors.AddItem(boardmember);
            }

            var chiefs    = diagram.CreateContainerShape("Chiefs");
            var divisions = diagram.CreateContainerShape("Divisions");

            diagram.Connect(directors, chiefs);
            diagram.Connect(chiefs, divisions);
            chiefs.AddItems(new[] { ceo, cfo, cio });

            #region IT division
            var it = diagram.CreateContainerShape("IT");
            divisions.AddItem(it);

            var itBranch1 = this.diagram.CreateDivisionBranch("WPF");
            it.AddItems(itBranch1);
            this.containerSampleRoots.Add(itBranch1[0]); // the first item is the root of the branch by design

            var itBranch2 = this.diagram.CreateDivisionBranch("HTML");
            it.AddItems(itBranch2);
            this.containerSampleRoots.Add(itBranch2[0]);
            #endregion

            #region Finance division
            var finance = diagram.CreateContainerShape("Finance");
            divisions.AddItem(finance);
            for (var i = 0; i < 8; i++)
            {
                var financeWorker = diagram.CreateShape("F" + i);
                financeWorker.Background = new SolidColorBrush(Colors.Orange);
                finance.AddItem(financeWorker);
            }
            diagram.Connect(finance.Items[0] as IShape, finance.Items[1] as IShape);
            diagram.Connect(finance.Items[0] as IShape, finance.Items[2] as IShape);
            diagram.Connect(finance.Items[7] as IShape, finance.Items[5] as IShape);
            diagram.Connect(finance.Items[0] as IShape, finance.Items[5] as IShape);
            #endregion

            #region External
            var external = this.diagram.CreateContainerShape("Offices");
            diagram.Connect(chiefs, external);
            #region Spain office
            var spain = this.diagram.CreateContainerShape("Spain");
            external.AddItem(spain);
            for (var i = 0; i < 8; i++)
            {
                var spanish = diagram.CreateShape("S" + i);
                spanish.Background = new SolidColorBrush(Colors.Gray);
                spain.AddItem(spanish);
            }
            diagram.Connect(spain.Items[0] as IShape, spain.Items[1] as IShape);
            diagram.Connect(spain.Items[0] as IShape, spain.Items[2] as IShape);
            diagram.Connect(spain.Items[3] as IShape, spain.Items[2] as IShape);
            diagram.Connect(spain.Items[2] as IShape, spain.Items[5] as IShape);
            diagram.Connect(spain.Items[0] as IShape, spain.Items[5] as IShape);
            diagram.Connect(spain.Items[6] as IShape, spain.Items[5] as IShape);
            #endregion

            #region Austria office
            var austria = this.diagram.CreateContainerShape("Austria");
            external.AddItem(austria);
            for (var i = 0; i < 9; i++)
            {
                var spanish = diagram.CreateShape("S" + i);
                spanish.Background = new SolidColorBrush(Colors.Cyan);
                austria.AddItem(spanish);
            }
            diagram.Connect(austria.Items[0] as IShape, austria.Items[1] as IShape);
            diagram.Connect(austria.Items[4] as IShape, austria.Items[2] as IShape);
            diagram.Connect(austria.Items[2] as IShape, austria.Items[5] as IShape);
            diagram.Connect(austria.Items[4] as IShape, austria.Items[5] as IShape);
            diagram.Connect(austria.Items[6] as IShape, austria.Items[5] as IShape);
            #endregion

            #endregion
            this.containerSampleRoots.Add(directors);
        }