Hi Walter
I’d would like to know what is the most appropriate way to position a group node via code?
Consider the following method:
private void BuildDiagram()
{
var diagram = ctlDiagram;
diagram.StartTransaction("Test");
var group = new GraphLinksModelNodeData<string>();
group.IsSubGraph = true;
group.Key = "TheGroup";
group.Text = "Grouper";
diagram.Model.AddNode(group);
var n1 = new GraphLinksModelNodeData<string> { Key = "32", Location = new Point(250, 80), Text = "Accounts Payable", SubGraphKey = "TheGroup" };
var n2 = new GraphLinksModelNodeData<string> { Key = "10", Location = new Point(160, 210), Text = "Administration Expenses", SubGraphKey = "TheGroup" };
var n3 = new GraphLinksModelNodeData<string> { Key = "22", Location = new Point(330, 210), Text = "Cash", SubGraphKey = "TheGroup" };
var n4 = new GraphLinksModelNodeData<string> { Key = "16", Location = new Point(183, 329), Text = "Deprecitation", SubGraphKey = "TheGroup" };
diagram.Model.AddNode(n1);
diagram.Model.AddNode(n2);
diagram.Model.AddNode(n3);
diagram.Model.AddNode(n4);
diagram.Model.AddLink(n1, null, n2, "T");
diagram.Model.AddLink(n1, null, n3, "T");
diagram.Model.AddLink(n2, null, n4, "T");
<span =“Apple-tab-span” style=“white-space:pre”> //Option1
<span =“Apple-tab-span” style=“white-space:pre”> //group.Location = new Point(500, 300);
<span =“Apple-tab-span” style=“white-space:pre”> //Option2
//var part = diagram.PartManager.FindNodeForData(group, diagram.Model);
//part.Move(new Point(500, 300), false);
diagram.CommitTransaction("Test");
}
Option1
---------
group.Location = new Point(500, 300);
This seems to have no effect. The group node’s initial location is determined by it’s children.
Option 2
----------
var part = diagram.PartManager.FindNodeForData(group, diagram.Model);
part.Move(new Point(500, 300), false);
This sort of works but it produces the following strange behaviour:
The child links of the root node are no longer visible.
Here’s a breakdown of what I’m trying to achieve:
- I’ll be provided a collection of nodes from an external source, say a database for example. The nodes contain existing location data.
- I then want to add these nodes to a group node. The nodes should be laid out according to their associated location data.
- I then want to move the group to a specific location
Thanks
Justin