//todo removerandom internal void CreateRandom(int maxNestedCount,int maxChildCount) { int maxNestedCountCore = maxNestedCount; for(int i = 0; i <DiagramConstant.Random.Next(1,maxChildCount); i++) { GraphItem item = new GraphItem(Owner); if(maxNestedCountCore > 0) { maxNestedCountCore--; item.CreateRandom(maxNestedCountCore, maxChildCount); } ChildItems.Add(item); } }
internal void PrepareForBestFit(Size Size) { GraphProcessor processor = new GraphProcessor(DiagramItems, DiagramRelations); List<Graph> listGraph = processor.SearchConnectedComponents(); int x = 0; foreach(var item in listGraph) { List<DiagramRelation> relations = processor.GetMST(item.Edges); GraphItem rootGraphItem = null; foreach(var relation in relations) { if(relation.Item1 is GraphItem && relation.Item2 is GraphItem) continue; if(rootGraphItem == null) { rootGraphItem = new GraphItem(this); int indexToRemoveItem1 = relation.Item1.Id; DiagramItems.RemoveAt(indexToRemoveItem1); DiagramItems.Insert(indexToRemoveItem1, rootGraphItem); GraphItem childGraphItem = new GraphItem(this); int indexToRemoveItem2 = relation.Item2.Id; DiagramItems.RemoveAt(indexToRemoveItem2); DiagramItems.Insert(indexToRemoveItem2, childGraphItem); rootGraphItem.ChildItems.Add(childGraphItem); continue; } GraphItem parentItem; GraphItem childItem; int indexToRemove = -1; if(DiagramItems[relation.Item1.Id] is GraphItem) { parentItem = DiagramItems[relation.Item1.Id] as GraphItem; childItem = new GraphItem(this); indexToRemove = relation.Item2.Id; } else { parentItem = DiagramItems[relation.Item2.Id] as GraphItem; childItem = new GraphItem(this); indexToRemove = relation.Item1.Id; } DiagramItems.RemoveAt(indexToRemove); DiagramItems.Insert(indexToRemove, childItem); if(!parentItem.ChildItems.Contains(childItem)) { parentItem.ChildItems.Add(childItem); } } if(rootGraphItem != null) { rootGraphItem.DoBestFit(ref x, 100); x += rootGraphItem.grapWidth / 2; } } foreach(var item in DiagramRelations) { item.Item1 = DiagramItems[item.Item1.Id]; item.Item2 = DiagramItems[item.Item2.Id]; } x = 0; foreach(var item in DiagramItems) { if(!(item is GraphItem)) { item.Location = new PointF(x, 0); x += DiagramConstant.GraphWidth; } } }
private void generateGraph(object sender, EventArgs e) { clear(null, null); GraphItem graphItem = new GraphItem(helper); graphItem.CreateRandom(10,4); helper.AddGraphItem(graphItem); }
internal void AddGraphItem(GraphItem graphItem) { DiagramItems.Add(graphItem); foreach(var item in graphItem.ChildItems) { DiagramRelations.Add(new DiagramRelation() { Item1 = graphItem, Item2 = item }); AddGraphItem(item); } }