Page Index Toggle Pages: 1 Send TopicPrint
Hot Topic (More than 10 Replies) Attached node text clipping issue (Read 6217 times)
anurodhora
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 103
Joined: Jan 19th, 2009
Attached node text clipping issue
Mar 17th, 2009 at 4:59am
Print Post  
Hi,

I tried attached node method to move the label around the main node. see below code for example:

Code
Select All
ShapeNode mainNode = diagram.Factory.CreateShapeNode(
new Point(100, 100), new Size(45, 45));
Uri uri = new Uri(@"..\..\Test.png", UriKind.RelativeOrAbsolute);
mainNode.Image = new BitmapImage(uri);
mainNode.ImageAlign = ImageAlign.Center;
mainNode.Shape = Shapes.Decision;
mainNode.EnabledHandles = AdjustmentHandles.Move;

ShapeNode labelNode = diagram.Factory.CreateShapeNode(
mainNode.Bounds.X - 10, mainNode.Bounds.Y + mainNode.Bounds.Height,
mainNode.Bounds.Width + 20, 15);

labelNode.AttachTo(mainNode, AttachToNode.MiddleLeft);
labelNode.Locked = true;
labelNode.Transparent = true;
labelNode.Text = "This is a long text string";

labelNode.ResizeToFitText(FitSize.KeepHeight);

 



The problem is that the text is getting clipped along the width but when i change ResizeToFitText(FitSize.KeepHeight) to ResizeToFitText(FitSize.KeepWidth) full text can be seen as wrapped one along the height, but the problem is i want to keep text height as it is and the label node should resize in width.

Can you suggest. What i am missing here?

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Attached node text clipping issue
Reply #1 - Mar 17th, 2009 at 1:52pm
Print Post  
Hi,

While debugging this, our developer found and fixed a bug in the ResizeToFit(KeepHeight) algorithm when TextFormat.NoWrap is enabled:
https://mindfusion.eu/_beta/wpfdiag_fittext.zip

Anyway with your code it will still just return false, because the MeasureString method returns height larger than the node height. You should set the initial node size to be a millimeter or two higher for this to work.

Stoyan
  
Back to top
 
IP Logged
 
Anant_Shukla
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 36
Joined: Mar 16th, 2009
Re: Attached node text clipping issue
Reply #2 - Mar 18th, 2009 at 6:43am
Print Post  
Hi Stoyan,

I was also facing the same issue and I tried your suggestion from the last post. But still I am facing the text alignment issue for the attached node.

I need the text for attached node to be aligned center to the main node at present which is getting aligned to the left corner of the main node which is not desired it should be center aligned to the main node.

Any suggestions how can I accomplish this task.

Thanks and Regards,
Anant Shukla.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Attached node text clipping issue
Reply #3 - Mar 18th, 2009 at 9:39am
Print Post  
Hi Anant,

If you need it in the center, you could just set the main node's Text instead of using attached node. If you prefer using an attached node, set the Alignment and LineAlignment of its TextFormat both to center, and make sure the attached node is centered on the main node; for example:

Code
Select All
Rect r = mainNode.Bounds;
Point center = new Point(r.X + r.Width / 2, r.Y + r.Height / 2);
Rect l = labelNode.Bounds;
labelNode.Move(center.X - l.Width / 2, center.Y - l.Height / 2);
 



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


I love YaBB 1G - SP1!

Posts: 36
Joined: Mar 16th, 2009
Re: Attached node text clipping issue
Reply #4 - Mar 18th, 2009 at 10:18am
Print Post  
Hi Stoyan,

I have incorporated your suggestions but its not working as desired. Following your suggestion the attached node's text is getting placed over the main node at its center which is not desired.

I need the attached node's text to be displayed right below the main node and the complete text no matter how large should get aligned with the center of the main node but the text should not overlap the main node it should be below the main node.

Thanks and Regards,
Anant Shukla.
  
Back to top
 
IP Logged
 
Anant_Shukla
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 36
Joined: Mar 16th, 2009
Re: Attached node text clipping issue
Reply #5 - Mar 18th, 2009 at 10:38am
Print Post  
Thanks Stoyan,

Done with few modifications in your code from the last post.

Anant Shukla.
  
Back to top
 
IP Logged
 
anurodhora
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 103
Joined: Jan 19th, 2009
Re: Attached node text clipping issue
Reply #6 - Mar 23rd, 2009 at 8:51am
Print Post  
Hi,

With the attached node label method, code of which is presented above in the thread, I am facing a problem say i want to switch off the visibility of the node while adding it to the diagram nodes collection but doing it only hides the main node not the attached label node.

Code
Select All
ShapeNode mainNode = diagram.Factory.CreateShapeNode(
new Point(100, 100), new Size(45, 45));
Uri uri = new Uri(@"..\..\Test.png", UriKind.RelativeOrAbsolute);
mainNode.Image = new BitmapImage(uri);
mainNode.ImageAlign = ImageAlign.Center;
mainNode.Shape = Shapes.Decision;
mainNode.EnabledHandles = AdjustmentHandles.Move;

ShapeNode labelNode = diagram.Factory.CreateShapeNode(
mainNode.Bounds.X - 10, mainNode.Bounds.Y + mainNode.Bounds.Height,
mainNode.Bounds.Width + 20, 15);

labelNode.AttachTo(mainNode, AttachToNode.MiddleLeft);
labelNode.Locked = true;
labelNode.Transparent = true;
labelNode.Text = "This is a long text string";

mainNode.Visible = false;
 



But after adding it to the diagram and then switching off visibility works fine.
foreach (ShapeNode node in diagram.Nodes)
{
node.Visibility = false;
}

What should we do in such case if we want that while node creation the node should add to the diagram collection in hidden state.

Thanks,
Anurodh
« Last Edit: Mar 23rd, 2009 at 10:48am by anurodhora »  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Attached node text clipping issue
Reply #7 - Mar 23rd, 2009 at 12:47pm
Print Post  
Hi,

Instead of mainNode.Visible = false try setting mainNode.SubordinateGroup.Visible = false; this should hide all nodes in the group.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
anurodhora
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 103
Joined: Jan 19th, 2009
Re: Attached node text clipping issue
Reply #8 - Mar 23rd, 2009 at 1:23pm
Print Post  
Thanks Smiley
  
Back to top
 
IP Logged
 
anurodhora
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 103
Joined: Jan 19th, 2009
Re: Attached node text clipping issue
Reply #9 - Mar 27th, 2009 at 12:58pm
Print Post  
Hi,

On a button click i want to change the text of the attached issue but again the clipping issue is coming.

private void btnCnhgText_Click(object sender, RoutedEventArgs e)
       {

           foreach (ShapeNode node in diagram.Nodes)
           {
               if (node.SubordinateGroup != null && node.SubordinateGroup.AttachedNodes[0] != null)
               {
                ((ShapeNode)node.SubordinateGroup.AttachedNodes[0]).Text = "Long text string given";
               }
           }
       }

Upon using this code the text  definitely changes but the string assigned is not displayed completely. Only "Long text" is visible.

Please suggest how to resolve this issue.

Consider following code:
Code
Select All
ShapeNode mainNode = diagram.Factory.CreateShapeNode(
new Point(100, 100), new Size(45, 45));

node.EnabledHandles = AdjustmentHandles.Move;
node.HandlesStyle = HandlesStyle.MoveOnly;
Uri uri = new Uri(@"..\..\Test.png", UriKind.RelativeOrAbsolute);
mainNode.Image = new BitmapImage(uri);
mainNode.ImageAlign = ImageAlign.Center;
mainNode.Shape = Shapes.Decision;


labelNode = diagram.Factory.CreateShapeNode(
			  mainNode.Bounds.X, mainNode.Bounds.Y + mainNode.Bounds.Height,
			  mainNode.Bounds.Width, 20);
		    labelNode.AttachTo(mainNode, AttachToNode.BottomCenter);
labelNode.Locked = true;
labelNode.Transparent = true;
labelNode.Text = device.Name;
labelNode.Shape = Shapes.Rectangle;
labelNode.TextFormat.Alignment = StringAlignment.Center;
labelNode.TextFormat.LineAlignment = StringAlignment.Center;
		    labelNode.ResizeToFitText(FitSize.KeepHeight);
		    mainNode.SubordinateGroup.AutoDeleteItems = true;

 



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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Attached node text clipping issue
Reply #10 - Mar 27th, 2009 at 2:25pm
Print Post  
Also call ResizeToFitText. If you use the KeepHeight argument, the method might return false if the node is not high enough. In that case add a few points to the height and call ResizeToFit again.

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