Esempio n. 1
0
        /// <summary>
        /// Creates a specific diagram and highlight the longest path found through the graph analysis.
        /// </summary>
        /// <param name="diagram">The diagram.</param>
        /// <param name="specs">The specs.</param>
        private void LongestPath(RadDiagram diagram, GraphGenerationSpecifications specs)
        {
            diagram.Clear();
            Dictionary <Node, RadDiagramShape>      nodeMap;
            Dictionary <Edge, RadDiagramConnection> edgeMap;

            // this creates the specific graph
            var g = this.diagram.CreateDiagram(new List <string> {
                "1,2", "2,3", "2,4", "3,5", "4,5", "5,6", "2,7", "7,8", "8,9", "9,10", "10,6", "20,21", "21,22", "20,25"
            }, out nodeMap, out edgeMap, GraphExtensions.CreateShape, this.RandomSizeCheck.IsChecked.HasValue && this.RandomSizeCheck.IsChecked.Value);

            // note that this works on disconnected graphs as well as on connected ones
            var path = g.FindLongestPath();

            // highlight the longest path if one is found
            if (path != null)
            {
                this.Highlight(path, nodeMap, edgeMap, this.HighlighBrush);
            }

            // use a layout which displays the result best
            diagram.Layout(LayoutType.Tree, new TreeLayoutSettings
            {
                TreeLayoutType       = TreeLayoutType.TreeUp,
                VerticalSeparation   = 80d,
                HorizontalSeparation = 50d
            });
        }
Esempio n. 2
0
        /// <summary>
        /// Creates a specific graph which has some obvious cycles and lets the graph analysis highlight them, thus confirming the cycles
        /// which can be easily found manually. The analysis goes of course beyond what the human eye can see and would find cycles in an arbitrary graph.
        /// </summary>
        /// <param name="diagram">The diagram.</param>
        /// <param name="specs">The specs.</param>
        private void Cycles(RadDiagram diagram, GraphGenerationSpecifications specs)
        {
            diagram.Clear();
            Dictionary <Node, RadDiagramShape>      nodeMap;
            Dictionary <Edge, RadDiagramConnection> edgeMap;
            var g = diagram.CreateDiagram(new List <string> {
                "1,2", "3,1", "2,4", "4,3", "4,5", "10,11", "11,12", "12,10"
            }, out nodeMap,
                                          out edgeMap, specs.CreateShape, specs.RandomShapeSize);
            var cycles = g.FindCycles();

            if (cycles.Count > 0)
            {
                foreach (var cycle in cycles)
                {
                    var path = new GraphPath <Node, Edge>();
                    cycle.ToList().ForEach(path.AddNode);
                    this.Highlight(path, nodeMap, edgeMap, specs.HighlightBrush);
                }
            }
            diagram.Layout(LayoutType.Tree, new TreeLayoutSettings
            {
                TreeLayoutType       = TreeLayoutType.TreeRight,
                VerticalSeparation   = 50d,
                HorizontalSeparation = 80d
            });
        }
Esempio n. 3
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);
        }
Esempio n. 4
0
 private static void LoadSample(RadDiagram diagram, string name)
 {
     diagram.Clear();
     using (var stream = ExtensionUtilities.GetStream(string.Format("/Common/SampleDiagrams/{0}.xml", name)))
     {
         using (var reader = new StreamReader(stream))
         {
             var xml = reader.ReadToEnd();
             if (!string.IsNullOrEmpty(xml))
             {
                 diagram.Load(xml);
             }
         }
     }
     diagram.Dispatcher.BeginInvoke(new Action(() => diagram.AutoFit()), System.Windows.Threading.DispatcherPriority.Loaded);
 }
Esempio n. 5
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);
         }
     }
 }
Esempio n. 6
0
 private void Open(RadDiagram diagram, string Path)
 {
     if (diagram.GraphSource == null)
     {
         diagram.Clear();
     }
     using (var stream = System.IO.File.OpenRead(Path))
     {
         using (var reader = new System.IO.StreamReader(stream))
         {
             var xml = reader.ReadToEnd();
             if (!string.IsNullOrEmpty(xml))
             {
                 diagram.Load(xml);
             }
         }
     }
 }
        public void ConfigureTable(RadDiagram diagram, FilterStandardViewModel viewModel)
        {
            diagram.Clear();

            var table = new RadDiagramShape()
            {
                Background      = new ImageBrush(new BitmapImage(new Uri(BaseUriHelper.GetBaseUri(diagram), string.Format(BackgroundImage, seats)))),
                StrokeThickness = 0,
                IsEnabled       = false,
                Height          = TABLE_HEIGHT,
                Width           = TABLE_WIDTH,
                X = tablePosition.X,
                Y = tablePosition.Y
            };

            diagram.AddShape(table);

            CreatePlayerLabels(diagram, viewModel);
        }
        public void ConfigureTable(RadDiagram diagram, SettingsSiteViewModel viewModel, EnumTableType tableType)
        {
            diagram.Clear();

            var table = new RadDiagramShape()
            {
                Background      = new ImageBrush(new BitmapImage(new Uri(BaseUriHelper.GetBaseUri(diagram), GetBackgroundImage(tableType)))),
                StrokeThickness = 0,
                IsEnabled       = false,
                Height          = TABLE_HEIGHT,
                Width           = TABLE_WIDTH,
                X = tablePosition.X,
                Y = tablePosition.Y,
            };

            diagram.AddShape(table);

            CreatePlayerLabels(diagram, viewModel, (int)tableType);
        }
        private void CreateTable(RadDiagram diagram)
        {
            diagram.Clear();

            var seats = (int)CurrentCapacity;

            table = new RadDiagramShape()
            {
                Name            = "Table",
                Background      = new ImageBrush(new BitmapImage(new Uri(BaseUriHelper.GetBaseUri(diagram), BackgroundImage))),
                Height          = predefinedTableSizes[seats].Item1,
                Width           = predefinedTableSizes[seats].Item2,
                StrokeThickness = 0,
                IsEnabled       = false
            };

            table.X = DefaultTablePosition.X;
            table.Y = DefaultTablePosition.Y;

            diagram.AddShape(table);
        }
Esempio n. 10
0
        /// <summary>
        /// Creates a balanced radial forest.
        /// </summary>
        /// <param name="diagram">The diagram.</param>
        /// <param name="specs">The specs.</param>
        public static void BalancedRadialForest(this RadDiagram diagram, GraphGenerationSpecifications specs)
        {
            diagram.Clear();
            Dictionary <Node, RadDiagramShape>      nodeMap;
            Dictionary <Edge, RadDiagramConnection> edgeMap;
            var g        = diagram.CreateDiagram(CreateBalancedForest(), out nodeMap, out edgeMap, CreateShape, specs.RandomShapeSize);
            var settings = new TreeLayoutSettings
            {
                TreeLayoutType                  = specs.TreeType,
                HorizontalSeparation            = specs.HorizontalSeparation,
                VerticalSeparation              = specs.VerticalSeparation,
                UnderneathHorizontalOffset      = specs.UnderneathHorizontalOffset,
                UnderneathVerticalSeparation    = specs.UnderneathVerticalSeparation,
                KeepComponentsInOneRadialLayout = specs.KeepComponentsInOneRadialLayout
            };
            var center = g.FindNode(1);

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

            layout.Layout(diagram, settings);
            diagram.AutoFit();
        }
        public static void LoadDiagram(RadDiagram diagram, string name)
        {


            diagram.Clear();

            using (var stream = ExtensionUtilities.GetStream(string.Format("{0}.xml", name), "Procbel.Apps.Silverlight.Modules.Inicio"))
            {
                using (var reader = new StreamReader(stream))
                {
                    var xml = reader.ReadToEnd();
                    if (!string.IsNullOrEmpty(xml))
                    {
                        diagram.Load(xml);
                    }
                }
            }
#if WPF
            diagram.Dispatcher.BeginInvoke(new Action(() => diagram.AutoFit()), System.Windows.Threading.DispatcherPriority.Loaded);
#else
            diagram.Dispatcher.BeginInvoke(new Action(() => diagram.AutoFit()));
#endif
        }
Esempio n. 12
0
        public static void LoadSample(RadDiagram diagram, string name)
        {
            if (diagram.GraphSource == null)
            {
                diagram.Clear();
            }
            using (var stream = ExtensionUtilities.GetStream(string.Format("/View/Diagrams/Common/SampleDiagrams/{0}.xml", name)))
            {
                using (var reader = new StreamReader(stream))
                {
                    var xml = reader.ReadToEnd();
                    if (!string.IsNullOrEmpty(xml))
                    {
                        diagram.Load(xml);
                    }
                }
            }
#if WPF
            diagram.Dispatcher.BeginInvoke(new Action(() => diagram.AutoFit()), System.Windows.Threading.DispatcherPriority.ApplicationIdle);
#else
            diagram.Dispatcher.BeginInvoke(new Action(() => diagram.AutoFit()));
#endif
        }
Esempio n. 13
0
        /// <summary>
        /// Creates a specific diagram and highlight the longest path found through the graph analysis.
        /// </summary>
        /// <param name="diagram">The diagram.</param>
        /// <param name="specs">The specs.</param>
        private void LongestPath(RadDiagram diagram, GraphGenerationSpecifications specs)
        {
            diagram.Clear();
            Dictionary<Node, RadDiagramShape> nodeMap;
            Dictionary<Edge, RadDiagramConnection> edgeMap;

            // this creates the specific graph
            var g = this.diagram.CreateDiagram(new List<string> { "1,2", "2,3", "2,4", "3,5", "4,5", "5,6", "2,7", "7,8", "8,9", "9,10", "10,6", "20,21", "21,22", "20,25" }, out nodeMap, out edgeMap, GraphExtensions.CreateShape, this.RandomSizeCheck.IsChecked.HasValue && this.RandomSizeCheck.IsChecked.Value);

            // note that this works on disconnected graphs as well as on connected ones
            var path = g.FindLongestPath();

            // highlight the longest path if one is found
            if (path != null) this.Highlight(path, nodeMap, edgeMap, this.HighlighBrush);

            // use a layout which displays the result best
            diagram.Layout(LayoutType.Tree, new TreeLayoutSettings
            {
                TreeLayoutType = TreeLayoutType.TreeUp,
                VerticalSeparation = 80d,
                HorizontalSeparation = 50d
            });
        }
Esempio n. 14
0
 /// <summary>
 /// Creates a specific graph which has some obvious cycles and lets the graph analysis highlight them, thus confirming the cycles
 /// which can be easily found manually. The analysis goes of course beyond what the human eye can see and would find cycles in an arbitrary graph.
 /// </summary>
 /// <param name="diagram">The diagram.</param>
 /// <param name="specs">The specs.</param>
 private void Cycles(RadDiagram diagram, GraphGenerationSpecifications specs)
 {
     diagram.Clear();
     Dictionary<Node, RadDiagramShape> nodeMap;
     Dictionary<Edge, RadDiagramConnection> edgeMap;
     var g = diagram.CreateDiagram(new List<string> { "1,2", "3,1", "2,4", "4,3", "4,5", "10,11", "11,12", "12,10" }, out nodeMap,
         out edgeMap, specs.CreateShape, specs.RandomShapeSize);
     var cycles = g.FindCycles();
     if (cycles.Count > 0)
     {
         foreach (var cycle in cycles)
         {
             var path = new GraphPath<Node, Edge>();
             cycle.ToList().ForEach(path.AddNode);
             this.Highlight(path, nodeMap, edgeMap, specs.HighlightBrush);
         }
     }
     diagram.Layout(LayoutType.Tree, new TreeLayoutSettings
                                         {
                                             TreeLayoutType = TreeLayoutType.TreeRight,
                                             VerticalSeparation = 50d,
                                             HorizontalSeparation = 80d
                                         });
 }
        public static void LoadSample(RadDiagram diagram, string name)
        {
            if (diagram.GraphSource == null)
                diagram.Clear();
            using (var stream = ExtensionUtilities.GetStream(string.Format("/Common/SampleDiagrams/{0}.xml", name)))
            {
                using (var reader = new StreamReader(stream))
                {
                    var xml = reader.ReadToEnd();
                    if (!string.IsNullOrEmpty(xml))
                    {
                        diagram.Load(xml);
                    }
                }
            }
#if WPF
			diagram.Dispatcher.BeginInvoke(new Action(() => diagram.AutoFit()), System.Windows.Threading.DispatcherPriority.ApplicationIdle);
#else
            diagram.Dispatcher.BeginInvoke(new Action(() => diagram.AutoFit()));
#endif
        }
Esempio n. 16
0
		private static void LoadSample(RadDiagram diagram, string name)
		{
			diagram.Clear();
			using (var stream = ExtensionUtilities.GetStream(string.Format("/Common/SampleDiagrams/{0}.xml", name)))
			{
				using (var reader = new StreamReader(stream))
				{
					var xml = reader.ReadToEnd();
					if (!string.IsNullOrEmpty(xml))
					{
						diagram.Load(xml);
					}
				}
			}
			diagram.Dispatcher.BeginInvoke(new Action(() => diagram.AutoFit()));
		}
Esempio n. 17
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);
        }
 private static void LoadSample(RadDiagram diagram, string name)
 {
     diagram.Clear();
     using (var stream = FeatureUtilities.GetStream(string.Format("/SampleDiagrams/{0}.xml", name)))
     {
         using (var reader = new StreamReader(stream))
         {
             var xml = reader.ReadToEnd();
             if (!string.IsNullOrEmpty(xml))
             {
                 diagram.Load(xml);
             }
         }
     }
 }