private void CreateSubGraph(EntityEx group) { ISubGraphModel sgmodel = myDiagram.Model as ISubGraphModel; if (sgmodel == null) { return; } var nodes = MainDataCollection; if (group == null) { var rootCollection = nodes.Where(n => String.IsNullOrEmpty(n.RootName)); foreach (EntityEx entity in rootCollection) { entity.Color = String.Format("#{0:X}{1:X}{2:X}", 80 + rand.Next(100), 80 + rand.Next(100), 80 + rand.Next(100)); entity.IsSubGraph = true; if (group != null) { entity.SubGraphKey = group.Key; } sgmodel.AddNode(entity); } // GraphLinksModel<EntityEx, String, String, Relationship> model = myDiagram.Model as GraphLinksModel<EntityEx, String, String, Relationship>; // model.LinksSource = new ObservableCollection<Relationship>() { // new Relationship() { From="SVMEmailSignatureType", To="ASMComplexSystemType", Text="0..N", ToText="1" } //}; GraphLinksModel <EntityEx, String, String, Relationship> model = myDiagram.Model as GraphLinksModel <EntityEx, String, String, Relationship>; model.LinksSource = mainRelationCollection; } else { var rootCollection = nodes.Where(n => n.RootName.Equals(group.Key)); foreach (EntityEx entity in rootCollection) { entity.Color = String.Format("#{0:X}{1:X}{2:X}", 80 + rand.Next(100), 80 + rand.Next(100), 80 + rand.Next(100)); entity.IsSubGraph = false; if (group != null) { entity.SubGraphKey = group.Key; } sgmodel.AddNode(entity); } } myDiagram.InitialCenteredNodeData = sgmodel.NodesSource.OfType <EntityEx>().First(); }
// Create some member nodes, including nested subgraphs, for PARENTDATA. // PARENTDATA may be null when creating the initial, top-level nodes private int CreateSubGraph(SimpleData group) { ISubGraphModel sgmodel = myDiagram.Model as ISubGraphModel; if (sgmodel == null) { return(0); } myDiagram.StartTransaction("Add Group contents"); var nodes = new List <SimpleData>(); // this will contain all of the member nodes created int groupCount = myDiagram.Nodes.OfType <Group>().Count(); // create a random number of subgraphs // ensure there are at least 10 groups in the diagram var numgroups = rand.Next(2); if (groupCount < 10) { numgroups += 1; } for (int i = 0; i < numgroups; i++) { var g = new SimpleData(); g.Color = String.Format("#{0:X}{1:X}{2:X}", 80 + rand.Next(100), 80 + rand.Next(100), 80 + rand.Next(100)); g.Key = "group" + (i + groupCount).ToString(); g.IsSubGraph = true; if (group != null) { g.SubGraphKey = group.Key; // declare that it's a member of nodedata } sgmodel.AddNode(g); nodes.Add(g); } var numnodes = rand.Next(4) + 2; // create a random number of non-group nodes for (int i = 0; i < numnodes; i++) { var n = new SimpleData(); n.Color = String.Format("#{0:X}{1:X}{2:X}", 80 + rand.Next(100), 80 + rand.Next(100), 80 + rand.Next(100)); n.Key = n.Color; if (group != null) { n.SubGraphKey = group.Key; // declare that it's a member of nodedata } sgmodel.AddNode(n); nodes.Add(n); } // add at least one link from each node to another // this could result in clusters of nodes unreachable from each other, but no lone nodes nodes.Sort((x, y) => x.Color.CompareTo(y.Color)); for (int i = 0; i < nodes.Count; i++) { var d = nodes[i]; int from = rand.Next(nodes.Count - i) + i; if (from != i) { d.FromKeys.Add(nodes[from].Key); } } myDiagram.CommitTransaction("Add Group contents"); return(nodes.Count); }