Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Text on anchor point? (Read 4483 times)
Erik
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 6
Joined: Dec 11th, 2012
Text on anchor point?
Dec 11th, 2012 at 8:06pm
Print Post  
Im am using the layered layout to generate a diagram from data in a sql database. My nodes have multiple ports (variables). Each port of a node is linked to a port of another node (like a circuit diagram).

So my question is: How can I display the name of the port at the origin and end of a link?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Text on anchor point?
Reply #1 - Dec 12th, 2012 at 7:56am
Print Post  
You could display the port names on the links themselves using the AddLabel method. If the names should be visible even without links, you will need to draw them by the nodes; e.g. set node.CustomDraw = Additional and call DrawString for each port from the DrawNode event handler.

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


I Love MindFusion!

Posts: 6
Joined: Dec 11th, 2012
Re: Text on anchor point?
Reply #2 - Dec 12th, 2012 at 10:14am
Print Post  
Thank you for your quick reply Smiley

I tried the approach with CustomDraw like you suggested, but it seems like the text is only drawn on the first node in the diagram ?? Also, it seems difficult to get the alignment of the text the way I like it.

The look I am striving for is like attached picture. Do you think I would be better of trying container nodes, instead of shape nodes?
  

example.jpg (Attachment deleted)
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Text on anchor point?
Reply #3 - Dec 12th, 2012 at 11:41am
Print Post  
Try this code,  assuming point labels are stored as values of AnchorPoint.Tag, and anchor points are only on the left and right sides of nodes:

Code
Select All
private void diagram_DrawNode(object sender, DrawNodeEventArgs e)
{
	DiagramNode node = e.Node;
	RectangleF rect = e.Bounds;
	foreach (AnchorPoint point in node.AnchorPattern.Points)
	{
		// convert from anchorpoint percent coordinates
		float x = rect.X + point.X * rect.Width / 100;
		float y = rect.Y + point.Y * rect.Height / 100;

		StringFormat format = new StringFormat();
		format.LineAlignment = StringAlignment.Center;
		if (point.X == 100)
		{
			// point on right side of node
			format.Alignment = StringAlignment.Far;
			x -= 1;
		}
		else
		{
			// point on right side of node
			format.Alignment = StringAlignment.Near;
			x += 1;
		}

		e.Graphics.DrawString((string)point.Tag,
			node.EffectiveFont, Brushes.Black, x, y, format);
	}
} 



You might find this easier to implement using TableNodes; see the Entities sample project for an example similar to your scenario.

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


I Love MindFusion!

Posts: 6
Joined: Dec 11th, 2012
Re: Text on anchor point?
Reply #4 - Dec 13th, 2012 at 8:42am
Print Post  
Thank you Smiley The code you sent works fine.
  
Back to top
 
IP Logged
 
Erik
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 6
Joined: Dec 11th, 2012
Re: Text on anchor point?
Reply #5 - Dec 13th, 2012 at 8:46am
Print Post  
Now I am trying to figure out how to set the vertical aligment of text in the shape node. I find only the TextFormat for horizontal aligment, but nothing for vertical alignment of the text?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Text on anchor point?
Reply #6 - Dec 13th, 2012 at 8:59am
Print Post  
Vertical alignment is set via StringFormat.LineAlignment.

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


I Love MindFusion!

Posts: 6
Joined: Dec 11th, 2012
Re: Text on anchor point?
Reply #7 - Dec 13th, 2012 at 1:25pm
Print Post  
Thanks alot Smiley

Another question: I can't seem to get the link to connect to the anchors, instead they connect anywhere on the boundaries of the shapeNode.

I am using the method:

public DiagramLink CreateDiagramLink (
    ShapeNode origin,
    int originAnchor,
    ShapeNode destination,
    int destAnchor
)

Is there some other property I have to set to get the link to connect to the anchor?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Text on anchor point?
Reply #8 - Dec 13th, 2012 at 2:09pm
Print Post  
That should be the correct method. You might as well set the links' OriginAnchor and DestinationAnchor properties after creating links. Note that LayeredLayout ignores anchor points by default; set its Anchoring property to Keep to preserve the links initial anchor points.

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


I Love MindFusion!

Posts: 6
Joined: Dec 11th, 2012
Re: Text on anchor point?
Reply #9 - Dec 13th, 2012 at 3:07pm
Print Post  
Setting Anchoring to keep did the trick. Thanks alot!
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint