Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic xml file to diagram with Layout problem (Read 6229 times)
esri_test
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 44
Joined: Aug 21st, 2013
xml file to diagram with Layout problem
Oct 29th, 2013 at 6:06pm
Print Post  
I have xml files defined node coordinates, link path coordinates. The link was always generated from the center of the node. I am trying to lay those out in a nice way.

The layout could be flowchart, could be branch, could be iteration, could be hierarchy.

I tried to use DiagramLink to define each path coordinate, but when it attached to the node, it is not go to the node center or not go to the node in the shortest path.

I tried to use OrthogonalRouter, but this layout only works best for flowchart.

How can I make layout arrangement well with my XML files?

Thanks,
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: xml file to diagram with Layout problem
Reply #1 - Oct 29th, 2013 at 7:02pm
Print Post  
Hi,

I could not understand are you trying to use coordinates from your xml files, or do you want to arrange the diagram automatically?

Links connect to centers of nodes if the nodes overlap at the time you create a link. You could try first moving the nodes to their expected positions before creating links, or otherwise if you first create all objects, try calling links' ReassignAnchorPoints method after moving the nodes.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
esri_test
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 44
Joined: Aug 21st, 2013
Re: xml file to diagram with Layout problem
Reply #2 - Oct 30th, 2013 at 2:19am
Print Post  
Hi, Stoyo,

I want to use coordinates from my xml files.
I tried to calculate SegmentCount of diagramLink and based on the nodes link attached to, calculate controlPoint, called UpdateFromPoints. Even I calculate the center of the node for the control points, it still attach to the anchor point as it shows in the first attachment. The second one is the desired diagram.

I also want to do branch and define my own path, so I think use coordinates might work. For the branch, I can do either two links branch out from the bottom of the node, or two links branch out from the sides of the node.
The xml file contains all the link path coordinates, but I don't know how to make them display correctly in the diagram.
  

Capture2.JPG (Attachment deleted)
Capture3.JPG (Attachment deleted)
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: xml file to diagram with Layout problem
Reply #3 - Oct 30th, 2013 at 11:51am
Print Post  
Hi,

If you keep the coordinates loaded from XML in a Point array or list, it should be enough to replace all ControlPoints and call UpdateFromPoints:

Code
Select All
private void OnLinkClicked(object sender, LinkEventArgs e)
{
	if (e.MouseButton == MouseButton.Right)
	{
		var points = new[]
		{
			new Point(10, 10),
			new Point(60, 10),
			new Point(60, 60),
			new Point(10, 60)
		};
		e.Link.ControlPoints.Clear();
		e.Link.ControlPoints.AddRange(points);
		e.Link.UpdateFromPoints(false, true);
	}
} 



Links could snap back to anchor points defined via AnchorPattern when you move a node, if either link.Dynamic is enabled, or if link.AutoRoute is set with RoutingOptions.Anchoring = Reassign. If Dynamic and AutoRoute are disabled, the end points should stick to the initial position along their node border you specify in ControlPoints. Links will snap to anchor points also if you set OriginAnchor and DestinationAnchor properties.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
esri_test
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 44
Joined: Aug 21st, 2013
Re: xml file to diagram with Layout problem
Reply #4 - Nov 1st, 2013 at 7:13pm
Print Post  
Hi Stoyo,I figured out how to do this by your instructions. I set link.AutoRoute = false, and use the defined ControlPoints. It solved the layout problem.

Due to my xml information, I need to calculate snap points for the begining and ending node for the link. I came across the method in Mindfusion as DiagramNode.GetNearestBorderPoint(Point), it came really close to what we want with one problem, the nearest border point of the node is not along the shape, but on the bounds of the shape.
Please find the attached images. This will happen most on the decision shape or oval shape, especially the link is not attached to the edge of the shape, not the anchor points.
Is there a better method to do what I want?
  

linkconnectioninMindfusion3.JPG (Attachment deleted)
linkconnectiondesired3.JPG (Attachment deleted)
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: xml file to diagram with Layout problem
Reply #5 - Nov 1st, 2013 at 7:39pm
Print Post  
Hi,

It works as expected in my test project. Are you sure the node's Shape property has already been set to a non-rectangular shape at the time you call GetNearestBorderPoint?

Stoyan
  
Back to top
 
IP Logged
 
esri_test
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 44
Joined: Aug 21st, 2013
Re: xml file to diagram with Layout problem
Reply #6 - Nov 1st, 2013 at 8:04pm
Print Post  
Yes, the node shape property has already been set to a non-rectangular shape at the time I call GetNearsetBorderPoint. I debug it on that GetNearestBorderPoint line, the node shape is displayed as right shape.

Here is my snippet,
var nodeMap = new Dictionary<string, DiagramNode>();

for each node in xml
var diagramNode = diagram.Factory.CreateShapeNode(pt, sz);
based on xml attribute, define node shape,
diagramNode.shape = Shapes.Decision;
nodeMap[node.Attribute("StepId").Value] = diagramNode;

for each link in xml
var diagramLink = diagram.Factory.CreateDiagramLink(nodeMap["sourceid"], nodeMap["destinationid"]);

calculate segment, set to diagramLink.SegmentCount,

int iCount = 0;
diagramLink.ControlPoints[iCount++] = nodeMap["sourceid"].GetCenter(); //this step might not be necessary

for each coordinate in link, create diagramLink.ControlPoint,

DiagramNode diagramNOut = nodeMap["sourceid"];
diagramLink.ControlPoints[0] = diagramNOut.GetNearestBorderPoint(diagramLink.ControlPoints[1]);

DiagramNode diagramNIn = nodeMap["destinationid"];
diagramLink.ControlPoints[iCount] = diagramNIn.GetNearestBorderPoint(diagramLink.ControlPoints[iCount-1]);

diagramLink.UpdateFromPoints(false, true);

It seems to me, the diagramNode.Shape is set properly and before I call GetNearestBorderPoint.

How did you do in your test project?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: xml file to diagram with Layout problem
Reply #7 - Nov 1st, 2013 at 8:59pm
Print Post  
I'm testing it by right-clicking around the target node of selected link with the following handler attached to diagram.Clicked:

Code
Select All
private void OnDiagramClicked(object sender, DiagramEventArgs e)
{
	var link = diagram.ActiveItem as DiagramLink;
	if (link != null)
	{
		link.EndPoint = link.Destination.GetNearestBorderPoint(e.MousePosition);
		link.UpdateFromPoints();
	}
} 



If calling GetNearestBorderPoint before showing the nodes, it might not work correctly because it enumerates the WPF visual tree, which might not be updated yet due to WPFs asynchronous layout. In such case try calling the UpdateLayout method of the diagram or nodes before looking for the nearest points.

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