Page Index Toggle Pages: 1 Send TopicPrint
Hot Topic (More than 10 Replies) Treelayout links to not begin in centre of node (Read 4356 times)
Rich Cassell
Junior Member
**
Offline


I Love MindFusion!

Posts: 63
Joined: Sep 19th, 2012
Treelayout links to not begin in centre of node
Oct 19th, 2012 at 2:01pm
Print Post  
Hi Stoyo,

I'm currently using a treeLayout with simple roundRects to produce a look and feel similar to a Windows Explorer List. I am using the following settings for the treeLayout

Code
Select All
treeLayout.Root = Nothing
treeLayout.Type = TreeLayoutType.Cascading
treeLayout.Direction = TreeLayoutDirections.LeftToRight
treeLayout.LinkStyle = TreeLayoutLinkType.Cascading2
treeLayout.LevelDistance = 6
treeLayout.NodeDistance = 1
treeLayout.KeepRootPosition = False
treeLayout.ReversedLinks = False
treeLayout.CompactAssistants = True 



The problem i have is that the links start from the centre-bottom of the parent node; meaning that i only need to go down 2 or 3 levels and the diagram is already quite deep...

I.e.

Parent
    |- Child
    |- Child

What i need, is the links to start further to the left, so the diagram is narrower.

I.e.

Parent
|- Child
|- Child

I figure this is something relating to the AnchorPoints of the nodes but i can't figure out how to change these and make it work.

Any suggestions please?

Thanks a lot,

Rich  Smiley
  
Back to top
 
IP Logged
 
Rich Cassell
Junior Member
**
Offline


I Love MindFusion!

Posts: 63
Joined: Sep 19th, 2012
Re: Treelayout links to not begin in centre of node
Reply #1 - Oct 19th, 2012 at 2:03pm
Print Post  
... Just a quick addition to this, i have tried changing the "LevelDistance" to be a negative number, and this puts the child nodes exactly where i'd like them:

treeLayout.LevelDistance = -30

However, The links still begin in the centre of the parent node so now cut through the children nodes... I need the link itself to start further to the left than the centre.

Cheers,

Rich Smiley
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Treelayout links to not begin in centre of node
Reply #2 - Oct 19th, 2012 at 2:24pm
Print Post  
Hi,

Check the "DirTree" sample project. It's achieving that by setting a negative LevelDistance and specifying custom anchor points for the links.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Rich Cassell
Junior Member
**
Offline


I Love MindFusion!

Posts: 63
Joined: Sep 19th, 2012
Re: Treelayout links to not begin in centre of node
Reply #3 - Oct 19th, 2012 at 2:38pm
Print Post  
Hi Stoyan,

Thanks for your reply. I can see from the "DirTree" sample project that the LevelDistance has been set to be negative; that does move my nodes to the left but leaves the links where they were. I can't find where the custom anchor points for the links are in the sample project code? It's the VB 4.0 one i'm looking at.

Cheers,
Rich Smiley
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Treelayout links to not begin in centre of node
Reply #4 - Oct 19th, 2012 at 2:45pm
Print Post  
Hi Rich,

Check the C# sample project, it seems we omitted setting the anchor points in VB.NET version.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Rich Cassell
Junior Member
**
Offline


I Love MindFusion!

Posts: 63
Joined: Sep 19th, 2012
Re: Treelayout links to not begin in centre of node
Reply #5 - Oct 19th, 2012 at 2:56pm
Print Post  
Hi Stoyan,

Sorry if i'm being very stupid - but i can't find anchor point references in the C# versions either  Huh

Cheers,
Rich Smiley
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Treelayout links to not begin in centre of node
Reply #6 - Oct 19th, 2012 at 3:03pm
Print Post  
What version of the control are you using? Here is the C# code from latest:

Code
Select All
public Window1()
{
	InitializeComponent();
	dirDiagram.ModificationStart = ModificationStart.AutoHandles;
	dirDiagram.Font.Size = 10.75;

	dirDiagram.ShowAnchors = ShowAnchors.Never;
	folderAnchors = new AnchorPattern(new[]
		{
			new AnchorPoint(10, 100, false, true),
			new AnchorPoint(0, 50, true, false)
		},
		"FolderAnchors");

	// set folder-like polygonal shape as default for nodes
	byte[] folderShape = { 0, 0, 40, 0, 55, 20, 100, 20, 100, 100, 0, 100 };
	dirDiagram.DefaultShape = new Shape(folderShape);
	dirDiagram.ShapeBrush = new LinearGradientBrush(new GradientStopCollection {
		new GradientStop(Colors.White, 0),
		new GradientStop(Colors.Yellow, 0.7),
		new GradientStop(Colors.Orange, 1)
	}, 10);

	Brush penBrush = new LinearGradientBrush(Colors.Bisque, Colors.OrangeRed, 0);
	dirDiagram.ShapePen = new Pen(penBrush, 1);

	// allow hierarchical expand/collapse
	dirDiagram.NodesExpandable = true;

	// all arrows should start with vertical segment
	dirDiagram.LinkCascadeOrientation = Orientation.Vertical;
	dirDiagram.LinkHeadShape = ArrowHeads.BowArrow;
	dirDiagram.LinkHeadShapeSize = 3;
	dirDiagram.LinkPen = new Pen(Brushes.Black, 0.41);

	// read some directories
	BuildTree();
}

int height = 0;
AnchorPattern folderAnchors;

private void BuildTree()
{
	// create a box that will be a root in our hierarchy
	ShapeNode root = new ShapeNode(dirDiagram);
	root.AnchorPattern = folderAnchors;
	root.Bounds = new RectangleF(23.04, 23.04, 99.84, 46.08);
	root.Text = "root";
	dirDiagram.Nodes.Add(root);

	height = 20;

	// read directories of all drives
	string[] drives = Environment.GetLogicalDrives();

	int skip = 0;
	if (drives.Length >= 2)
	{
		if (drives[0][0] == 'A') skip++;
		if (drives[1][0] == 'B') skip++;
	}

	DirectoryInfo[] di = new DirectoryInfo[drives.Length - skip];
	for (int i = 0; i < di.GetLength(0); ++i)
	{
		di[i] = new DirectoryInfo(drives[i + skip]);
	}
	BuildSubDirs(root, di, 1);

	LayoutTree();

	// after the whole tree is built adjust the document extents
	// to be as big as needed
	dirDiagram.ResizeToFitItems(5, true);
}

private void LayoutTree()
{
	TreeLayout tl = new TreeLayout();

	tl.Root = null; // automatically select root
	tl.Type = TreeLayoutType.Cascading;
	tl.Direction = TreeLayoutDirections.LeftToRight;
	tl.LinkStyle = TreeLayoutLinkType.Cascading2;
	tl.LevelDistance = -40;
	tl.NodeDistance = 15;
	tl.KeepRootPosition = true;
	tl.ReversedLinks = false;
	tl.Anchoring = Anchoring.Keep;

	tl.Arrange(dirDiagram);
}

private void BuildSubDirs(ShapeNode root, DirectoryInfo[] dirs, int level)
{
	foreach (DirectoryInfo dir in dirs)
	{
		// create a node for the subfolder
		ShapeNode folder = dirDiagram.Factory.CreateShapeNode(6 + level * 76.8, height, 99.84, 46.08);
		folder.AnchorPattern = folderAnchors;
		... 

  
Back to top
 
IP Logged
 
Rich Cassell
Junior Member
**
Offline


I Love MindFusion!

Posts: 63
Joined: Sep 19th, 2012
Re: Treelayout links to not begin in centre of node
Reply #7 - Oct 22nd, 2012 at 1:09pm
Print Post  
Hi Stoyo,

I mustn't have the most up to date version but the code you sent works a treat - thanks very much! Smiley

Rich
  
Back to top
 
IP Logged
 
Rich Cassell
Junior Member
**
Offline


I Love MindFusion!

Posts: 63
Joined: Sep 19th, 2012
Re: Treelayout links to not begin in centre of node
Reply #8 - Oct 23rd, 2012 at 2:29pm
Print Post  
Hi Stoyo,

My question is a new problem but related to this thread so i figured i'd add to it!

My question is regarding the use of "treeLayout.NodeDistance". I am setting this to 1 (As you can see from my first post in the thread), which means there is a single space between the nodes of one level and the node of the next level...

My problem is some of my nodes have their children sat next to them in the tree - i.e. on the same level; but it is still putting a full nodes-height worth of gap before the next level...

I.e. I want to acheive this:


-Top Node -
    |- Parent - Child - Child
    |- Parent - Child - Child


But what i'm getting is:


-Top Node -
    |- Parent - Child - Child


    |- Parent - Child - Child



I can see why it's doing it but can't find how to tell it not to!

Any ideas?

Cheers,
Rich  Smiley
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Treelayout links to not begin in centre of node
Reply #9 - Oct 23rd, 2012 at 4:24pm
Print Post  
Hi Rich,

How exactly are you placing child nodes on the same level as their parent in the tree?

Stoyan
  
Back to top
 
IP Logged
 
Rich Cassell
Junior Member
**
Offline


I Love MindFusion!

Posts: 63
Joined: Sep 19th, 2012
Re: Treelayout links to not begin in centre of node
Reply #10 - Oct 24th, 2012 at 7:02am
Print Post  
Hi Stoyan

I'm sort of cheating, to be honest, which is where i think i'm going wrong. Basically i'm running the arrange (treeLayout.arrange(doc)), and afterwards i'm then searching through the nodes and the ones that need moving i'm manually changing the bounds so that the "Y" matches the parent and the "X" is further across. It works fine, but that extra line it puts in stays there.

Cheers,
Rich Smiley
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Treelayout links to not begin in centre of node
Reply #11 - Oct 24th, 2012 at 7:37am
Print Post  
Hi Rich,

I think you can achieve that by moving the children alongside their parent *before* applying TreeLayout, calling their AttachTo method to group them with the parent node, and running the layout method with KeepGroupLayout property enabled. You can detach the children afterwards if you don't need the groups.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Rich Cassell
Junior Member
**
Offline


I Love MindFusion!

Posts: 63
Joined: Sep 19th, 2012
Re: Treelayout links to not begin in centre of node
Reply #12 - Oct 24th, 2012 at 8:53am
Print Post  
Hi Stoyan,

That's done the trick! Thanks very much  Cool

Cheers,
Rich Smiley
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint