Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Dir Tree : How to extend links to same level (Read 3131 times)
Surya
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 2
Joined: Jul 10th, 2015
Dir Tree : How to extend links to same level
Jul 10th, 2015 at 5:11am
Print Post  
Hi,

Please explain how to add links to the same level.
Any new links added currently go to the next level.


Thanks,
Surya
  

forum_png_2.png (Attachment deleted)
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Dir Tree : How to extend links to same level
Reply #1 - Jul 10th, 2015 at 9:21am
Print Post  
Hi,

TreeLayout always places child nodes on level below their parent. If you need to place first leaf node to the right of its parent, you could implement it like this:

Code
Select All
using System.Linq;
...
CreateTree();

// set IgnoreLayout on first leaf node in branch
// so that TreeLayout does not reserve space for it
var firstLeaves = FirstLeafNodes();
foreach (var node in firstLeaves)
	node.IgnoreLayout = true;

var layout = new TreeLayout();
layout.Type = TreeLayoutType.Cascading;
layout.Direction = TreeLayoutDirections.LeftToRight;
layout.LinkStyle = TreeLayoutLinkType.Cascading2;
layout.Arrange(diagram);

// align ignored nodes to their parent vertically
foreach (var node in firstLeaves)
{
	var r = Parent(node).Bounds;
	r.Offset(r.Width + layout.LevelDistance, 0);
	node.Bounds = r;
	node.IncomingLinks[0].UpdateIntersections();
	node.IgnoreLayout = false;
}

List<DiagramNode> FirstLeafNodes()
{
	return diagram.Nodes.Where(
		n =>
			n.OutgoingLinks.Count == 0 &&  // a leaf node (no children)
			Parent(n) != null &&
			Parent(n).OutgoingLinks[0].Destination == n)  // first child of its parent
		.ToList();
}

DiagramNode Parent(DiagramNode node)
{
	if (node.IncomingLinks.Count == 0)
		return null;
	return node.IncomingLinks[0].Origin;
}

void CreateTree()
{
	var root = diagram.Factory.CreateShapeNode(defSize);
	var secondLevel = CreateBranch(root, 4);
	foreach (var node in secondLevel)
		CreateBranch(node, 2);
}

List<DiagramNode> CreateBranch(DiagramNode parent, int numChldren)
{
	var children = new List<DiagramNode>();
	for (int i = 0; i < numChldren; i++)
		children.Add(NewChild(parent));
	return children;
}

DiagramNode NewChild(DiagramNode parent)
{
	var child = diagram.Factory.CreateShapeNode(defSize);
	diagram.Factory.CreateDiagramLink(parent, child);
	return child;
}

RectangleF defSize = new RectangleF(0, 0, 20, 12); 





If you need to arrange whole branches in different direction than overall tree, you could achieve it by applying TreeLayout independently for these branches, grouping them, and running TreeLayout for the main tree using KeepGroupLayout option.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint