Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Can I ensure that each link uses a different anchor point on a node? (Read 4406 times)
Dan Beet
YaBB Newbies
*
Offline



Posts: 3
Joined: Oct 31st, 2012
Can I ensure that each link uses a different anchor point on a node?
Oct 31st, 2012 at 10:12am
Print Post  
We are currently evaluating the DiagramLite control, to show what is effectively a UML class diagram (generated from some external metadata). We would like to auto arrange the diagram and have the links display separate from each other. When we use the OrthogonalLayout (the only layout that seems to work well in our scenario) all the links overlap and their text becomes unreadable.

Is there something we can do to solve this? We have tried creating our own Anchor pattern and calling ReassignAnchorPoints() on each node after we have created the links, but this does not seem to help our issue.

We do not allow users to rearrange the diagram at the moment, as it is read-only.

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Can I ensure that each link uses a different anchor point on a node?
Reply #1 - Oct 31st, 2012 at 12:05pm
Print Post  
Could you attach a sample xml file showing what kind of diagrams you need to arrange?
  
Back to top
 
IP Logged
 
Dan Beet
YaBB Newbies
*
Offline



Posts: 3
Joined: Oct 31st, 2012
Re: Can I ensure that each link uses a different anchor point on a node?
Reply #2 - Oct 31st, 2012 at 1:12pm
Print Post  
I have attached an exported XML from the control (using diagram.SaveToXml(Stream)). We generate the nodes and links in code, but I assume that the export will have all the properties you need?

The custom shape is simply there so that I could use a templated control with bindings to the data context to our model objects - maybe we can do the same thing with a ControlNode?

public class DataTypeNode : ShapeNode {
           public DataTypeNode(Diagram parent) : base(parent) {
                 DefaultStyleKey = typeof (DataTypeNode);
           }

           public DataTypeNode(ShapeNode prototype) : base(prototype) {
                 DefaultStyleKey = typeof (DataTypeNode);
           }

           public DataTypeNode() {
                 DefaultStyleKey = typeof (DataTypeNode);
           }
     }


The diagram XAML is:
<mfd:Diagram x:Name="_modelDiagram" MinWidth="200" MinHeight="200" AutoSnapLinks="False" AutoScroll="True"
                       ShowGrid="False" AutoAlignNodes="False" ShapeBrush="White" LinkBrush="Black" AlignToGrid="False"
                       Behavior="Modify" AllowUnconnectedLinks="False" AllowInplaceEdit="False" RouteLinks="True"
                       DynamicLinks="True" ModificationStart="AutoHandles" LinkCrossings="Arcs" BackBrush="White"
                             FontSize="12" ShapeHandlesStyle="EasyMove" />


With the following set in the code behind constructor:
                 _modelDiagram.AdjustmentHandlesSize = 10;
                 _modelDiagram.DynamicLinks = true;
                 _modelDiagram.LinkStyle = LinkStyle.Cascading;
                 _modelDiagram.RoutingOptions.Anchoring = Anchoring.Reassign;
                 _modelDiagram.RoutingOptions.TriggerRerouting = RerouteLinks.WhenModified;

I have disabled node/link creation and deletion using the *Creating/*Deleting events and args.CancelDrag().

The custom anchor pattern is created like this:
AnchorPattern = new AnchorPattern("DataTypeAnchorPattern");
                 for (var x = 20; x <= 80; x += 10) {
                       AnchorPattern.Points.Add(new AnchorPoint(x, 0, true, true, MarkStyle.Cross));
                       AnchorPattern.Points.Add(new AnchorPoint(x, 100, true, true, MarkStyle.Cross));
                 }
                 for (var y = 20; y <= 80; y += 10) {
                       AnchorPattern.Points.Add(new AnchorPoint(0, y, true, true, MarkStyle.Cross));
                       AnchorPattern.Points.Add(new AnchorPoint(100, y, true, true, MarkStyle.Cross));
                 }


To arrange the diagram I have used:

var layout = new OrthogonalLayout {
     Anchoring = Anchoring.Reassign,
     KeepGroupLayout = true,
     MultipleGraphsPlacement = MultipleGraphsPlacement.VerticalSortDescending,
     Refine = true,
     Padding = 150,
     Margins = new Size(100, 100),
}
layout.Arrange(_diagram)
_diagram.ResizeToFitItems(100);
_diagram.RouteAllLinks();
_diagram.UpdateLayout();
  

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Can I ensure that each link uses a different anchor point on a node?
Reply #3 - Oct 31st, 2012 at 8:09pm
Print Post  
Check if this approach will work for you, without using anchor points. The code runs OrthogonalRouter to distribute links after applying the layout, and then rotates labels of vertical links to prevent them from overlapping with adjacent links between the same pair of nodes.

Code
Select All
var layout = new OrthogonalLayout
{
	Anchoring = Anchoring.Reassign,
	KeepGroupLayout = true,
	MultipleGraphsPlacement = MultipleGraphsPlacement.VerticalSortDescending,
	Refine = true,
	Padding = 150,
	Margins = new Size(100, 100),
};
layout.Arrange(diagram);

new OrthogonalRouter().Arrange(diagram);

foreach (var link in diagram.Links)
{
	if (link.StartPoint.X == link.EndPoint.X)
		link.TextBlock.RenderTransform = new RotateTransform
		{
			Angle = 90,
			CenterX = link.TextBlock.ActualWidth / 2 + 10,
			CenterY = link.TextBlock.ActualHeight / 2
		};
} 



I hope that helps,
Stoyan
  

layout_test.png (Attachment deleted)
Back to top
 
IP Logged
 
Dan Beet
YaBB Newbies
*
Offline



Posts: 3
Joined: Oct 31st, 2012
Re: Can I ensure that each link uses a different anchor point on a node?
Reply #4 - Nov 1st, 2012 at 5:48pm
Print Post  
That worked perfectly. Thank you very much for your help.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint