Page Index Toggle Pages: [1] 2  Send TopicPrint
Hot Topic (More than 10 Replies) Positioning labels optimally (Read 9999 times)
DavidZ
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 22
Joined: Jun 15th, 2013
Positioning labels optimally
Jun 26th, 2013 at 11:34am
Print Post  
I am working with a flowchart part of which is shown below.

I am not using the flowchart layout but positioning the shapes myself. I then use the orthogonal router to arrange the links.

I have a couple of problems with the labels.

I would like them to be close to the link origin and always horizontal. I don't really want them to touch the link.

Quite often I get the issue outlined in red where a the link that a label belongs to is quite ambiguous.

I have tried adjusting the various settings

e.g.
link.Labels(0).RelativeTo = RelativeToLink.Segment
link.Labels(0).SetSegmentPosition(0, 5, 5)

but it has not really helped. I am assuming that there is more flexibility referring to labels rather than the link's "text" property.

Thanks

David
  

labelissue.PNG (Attachment deleted)
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Positioning labels optimally
Reply #1 - Jun 26th, 2013 at 12:24pm
Print Post  
Quote:
I would like them to be close to the link origin and always horizontal. I don't really want them to touch the link.


SetSegmentPosition is relative to the middle of segments, and could be quite far from the origin if the first segment is a long one. Try aligning the label to the first control point instead; I think it should also have higher probability to be far from crossing points with other links:


Code
Select All
var label = link.AddLabel("test");
label.RelativeTo = RelativeToLink.ControlPoint;
label.Index = 0;
label.AutoArrange = true;
label.Margin = 5; 



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


I Love MindFusion!

Posts: 22
Joined: Jun 15th, 2013
Re: Positioning labels optimally
Reply #2 - Jun 26th, 2013 at 2:20pm
Print Post  
Thank you for that. It seems to have helped with the first shape and I guess we are on the right track for the others.

The image below shows that the labels are now too close to the shape. Is this because the control points are not at the edges of the shape? If so is the way to fix this to move the control points? When I use the factory method to create a link where is the control point created by default?

Thanks

David

  

labelissue_001.PNG (Attachment deleted)
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Positioning labels optimally
Reply #3 - Jun 26th, 2013 at 3:47pm
Print Post  
Have you enabled labels' AutoArrange property for all links? It should move the labels outwards from nodes even if the first control point does not lie exactly on node borders.
  
Back to top
 
IP Logged
 
DavidZ
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 22
Joined: Jun 15th, 2013
Re: Positioning labels optimally
Reply #4 - Jun 26th, 2013 at 5:02pm
Print Post  
Yes, I did. I used the code that you supplied above exactly.

David
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Positioning labels optimally
Reply #5 - Jun 27th, 2013 at 7:39am
Print Post  
Please call diagram.SaveToXml and attach the file here.

Stoyan
  
Back to top
 
IP Logged
 
DavidZ
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 22
Joined: Jun 15th, 2013
Re: Positioning labels optimally
Reply #6 - Jun 27th, 2013 at 8:13am
Print Post  
Thanks for taking a look.

David
  

diagram_001.txt (Attachment deleted)
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Positioning labels optimally
Reply #7 - Jun 27th, 2013 at 10:34am
Print Post  
If I reset the AutoArrange property after loading the file, the labels seem to move to correct positions, so I suppose the control does not detect that it should update their positions from some API functions you are using during your custom layout. Could you post a list of all methods and properties you are using to arrange the nodes? For the time being you could rearrange labels after the custom layout:

Code
Select All
// force labels layout
foreach (DiagramLink link in diagram.Links)
{
	link.Labels[0].AutoArrange = false;
	link.Labels[0].AutoArrange = true;
}

// invalidated labels are arranged on first redraw
diagram.Draw(new GdiGraphics(), new RenderOptions(), diagram.Bounds, false); 



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


I Love MindFusion!

Posts: 22
Joined: Jun 15th, 2013
Re: Positioning labels optimally
Reply #8 - Jun 27th, 2013 at 10:45am
Print Post  
Thanks. I will try that code and see how it goes. In the meantime I am attaching my code that lays out the shapes.

I managed to update it so that the labels are moved into place as a post processing measure but your code is much more concise so if it works I will replace it with that.

Thanks

David
  

layoutcode.txt (Attachment deleted)
Back to top
 
IP Logged
 
DavidZ
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 22
Joined: Jun 15th, 2013
Re: Positioning labels optimally
Reply #9 - Jun 27th, 2013 at 10:52am
Print Post  
So I added your code and it works for all of the boxes except for one (very odd). Please see image attached.

I should add for the code in the previous section you can ignore the method UpdateLinkControlPoints as this is the post processing I added in order to get the labels into a good position.

There is no urgency as far as I am concerned with this as this last method does solve the labels issue for me but if I can be of any help is solving this issue then I am happy to help.

Thanks

David
  

labelissues.png (Attachment deleted)
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Positioning labels optimally
Reply #10 - Jun 27th, 2013 at 11:03am
Print Post  
Try resetting AutoArrange and calling the diagram.Draw method after ResizeToFitItems(5) to force refreshing the labels' layout for the last nodes too. I suppose ResizeToFitItems is one of the places we omit updating the labels; our developer will check it in the next couple of days.
  
Back to top
 
IP Logged
 
DavidZ
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 22
Joined: Jun 15th, 2013
Re: Positioning labels optimally
Reply #11 - Jun 27th, 2013 at 11:38am
Print Post  
Thanks, that does work now.

Can you please let me know if this is fixed in a future release so that I can remove this extra code?

Thanks

David
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Positioning labels optimally
Reply #12 - Jun 28th, 2013 at 8:30am
Print Post  
You can find a fixed version at the personal messages page (linked from top of the forum). It also adds a Diagram.ArrangeLinkLabels method that will let you rearrange AutoArrange labels, in case we omit updating them in some other scenario.

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


I Love MindFusion!

Posts: 22
Joined: Jun 15th, 2013
Re: Positioning labels optimally
Reply #13 - Jul 2nd, 2013 at 12:05pm
Print Post  
Thank you so much for this!

I have updated the code with this new method. Unfortunately I am still getting one situation where the label is covered slightly by the box. When the box has been made large due to more text using box.ResizeToFitText(FitSize.KeepRatio)

The label is covered slightly by the box. This was happening before the updated code too. In the new code I added the new method Diagram.ArrangeLinkLabels at the very end but it does not seem to help.

Sorry. I really appreciate your effort in getting this sorted.

Is there anything else that can be done? If you need an image then please let me know.

David
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Positioning labels optimally
Reply #14 - Jul 2nd, 2013 at 1:10pm
Print Post  
ResizeToFitText rearranges labels correctly in our tests. What are the initial node.Bounds coordinates and Text and Font values before you call the resize method? Is that node connected to the link whose label gets overlapped?

Stoyan
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: [1] 2 
Send TopicPrint