Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic FlowchartLayout and ContainerNode together (Read 1259 times)
crydust
YaBB Newbies
*
Offline



Posts: 1
Joined: Jun 21st, 2011
FlowchartLayout and ContainerNode together
Jun 21st, 2011 at 9:24am
Print Post  
Hello,

I'm trying to use ContainerNodes in a FlowchartLayout.
But FlowchartLayout doesn't seem to work well.
Does anyone know what I'm doing wrong?
Screenshots and full code are included below.

Without using containers.
This is pretty much what I want, but I'd like containers around groups of centered ShapeNodes.
[img]http://dl.dropbox.com/u/2199036/mindfusion/noContainer.png[/img]

With containers, but arranging before adding containers.
This is pretty much what I want, but the containers overlap.
[img]http://dl.dropbox.com/u/2199036/mindfusion/withContainer.png[/img]

With containers, arranging after adding containers.
Here everything seems to go wrong.
[list]
[*] The right node is off to the far right.
[*] The center ShapeNodes overlap.
[/list]
[img]http://dl.dropbox.com/u/2199036/mindfusion/withContainer-arrangeAfter.png[/img]

Code

[code]
using System;
using System.Windows.Forms;
using System.Drawing;
using MindFusion.Diagramming.Layout;
using MindFusion.Diagramming;

namespace MindFusionProject
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
InitializeDiagram(true, false);
}

private void InitializeDiagram(Boolean useContainer, Boolean arrangeAfterContainer)
{
var leftNode1 = CreateShapeNode("left 1");
var leftNode2 = CreateShapeNode("left 2");
var leftNode3 = CreateShapeNode("left 3");
var leftNode4 = CreateShapeNode("left 4");
var leftNode5 = CreateShapeNode("left 5");
var centerNode1 = CreateShapeNode("center 1");
var centerNode2 = CreateShapeNode("center 2");
var centerNode3 = CreateShapeNode("center 3");
var centerNode4 = CreateShapeNode("center 4");
var rightNode = CreateShapeNode("right");

CreateDiagramLink(leftNode1, centerNode1);
CreateDiagramLink(leftNode2, centerNode1);
CreateDiagramLink(leftNode3, centerNode2);
CreateDiagramLink(leftNode4, centerNode3);
CreateDiagramLink(leftNode5, centerNode4);
CreateDiagramLink(centerNode1, rightNode);
CreateDiagramLink(centerNode2, rightNode);
CreateDiagramLink(centerNode3, rightNode);
CreateDiagramLink(centerNode4, rightNode);

if (!arrangeAfterContainer)
{
Arrange();
}

if (useContainer)
{
CreateContainer("container with 2 center blocks", new[] { centerNode1, centerNode2 });
CreateContainer("container with 2 center blocks", new[] { centerNode3, centerNode4 });
}

if (arrangeAfterContainer)
{
Arrange();
}

RouteAllLinks();
}

private void Arrange()
{
var layout = new FlowchartLayout();
layout.Orientation = MindFusion.Diagramming.Layout.Orientation.Horizontal;
layout.Margins = new SizeF(10, 20);
layout.Arrange(diagram1);
}

private void RouteAllLinks()
{
var router = new QuickRouter(diagram1);
router.RouteAllLinks();

foreach (DiagramLink link in diagram1.Links)
{
link.ReassignAnchorPoints();
link.SegmentCount = 1;
}
}

private ContainerNode CreateContainer(string caption, ShapeNode[] nodes)
{
var result = diagram1.Factory.CreateContainerNode(RectangleF.Empty);
result.Caption = caption;
var rect = nodes[0].Bounds;
foreach (var node in nodes)
{
result.Add(node);
rect = RectangleF.Union(rect, node.Bounds);
}
result.SetBounds(rect, false, false);
result.UpdateBounds(false);
return result;
}

private ShapeNode CreateShapeNode(string text)
{
var result = diagram1.Factory.CreateShapeNode(new RectangleF(0, 0, 40, 10));
result.Text = text;
var left = new AnchorPoint(0, 50);
var right = new AnchorPoint(100, 50);
result.AnchorPattern = new AnchorPattern(new [] { left, right });
return result;
}

private DiagramLink CreateDiagramLink(DiagramNode origin, DiagramNode destination)
{
var result = diagram1.Factory.CreateDiagramLink(origin, destination);
result.OriginAnchor = 1;
result.DestinationAnchor = 0;
return result;
}
}
}

[/code]
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: FlowchartLayout and ContainerNode together
Reply #1 - Jun 21st, 2011 at 1:29pm
Print Post  
FlowchartLayout can't handle containers on its own, and non of the leveled layout algorithms guarantee that nodes from the same container will be placed together anyway.

Assuming your diagram is a tree, copy the code from this file and call ArrangeTreeWithContainers(rightNode):
http://www.mindfusion.eu/_samples/TreeWithContainers.cs

If you need to handle containers for arbitrary graphs, use the code here, but you might have to modify your diagram temporarily so that links connect to the containers instead of their children:
http://mindfusion.eu/Forum/YaBB.pl?board=fcnet_disc;action=display;num=127351559...

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