Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Several text labels inside the diagram node (Read 4572 times)
Kostya
Junior Member
**
Offline


I Love MindFusion!

Posts: 59
Joined: Aug 5th, 2014
Several text labels inside the diagram node
Aug 8th, 2014 at 11:58am
Print Post  
Hi,

On my diagram I have three anchor points for each shape node. What is the best way to add a short text label near each point ("In", "Out" etc)? I would like to place them all inside the node.

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Several text labels inside the diagram node
Reply #1 - Aug 8th, 2014 at 1:24pm
Print Post  
Hi,

You could assign the text values to AnchorPoint.Tag, set nodes CustomDraw property to Additional, and draw labels from DrawNode event handler:

Code
Select All
private void diagram_DrawNode(object sender, DrawNodeEventArgs e)
{
	// draw anchor point labels
	const double margins = 10.0;
	var node = e.Node;
	var rect = node.GetBounds();
	var pattern = node.AnchorPattern;
	if (pattern != null)
	{
		foreach (var point in pattern.Points)
		{
			if (point.Tag == null)
				continue;
			string label = point.Tag.ToString();
			var x = point.X * rect.Width / 100;
			var y = point.Y * rect.Height / 100;
			var size = diagram.MeasureString(label, node, 1000);
			var labelRect = new Rect(
				x - size.Width / 2,
				y - size.Height / 2,
				size.Width + margins,
				size.Height + margins);
			if (labelRect.X < 0)
				labelRect.X = 0;
			if (labelRect.Y < 0)
				labelRect.Y = 0;
			if (labelRect.Right > rect.Width)
				labelRect.X = rect.Width - labelRect.Width;
			if (labelRect.Bottom > rect.Height)
				labelRect.Y = rect.Height - labelRect.Height;
			diagram.DrawStyledText(e.Graphics, label, node, labelRect);
		}
	}
} 



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


I Love MindFusion!

Posts: 59
Joined: Aug 5th, 2014
Re: Several text labels inside the diagram node
Reply #2 - Aug 10th, 2014 at 6:44am
Print Post  
Hi Stoyan,

Thanks! And great idea about the point.Tag using.

-Kostya
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint