Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Database layout (Read 3581 times)
Michael
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 17
Joined: Nov 9th, 2012
Database layout
Nov 16th, 2015 at 4:24pm
Print Post  
Hi All,
I'm trying to write a Diagram that can Display Database Tables but as you can see in the Image draws the Nodes on the wrong Position.

I create the links like this:

Code
Select All
            MindFusion.Diagramming.Wpf.DiagramLink link = d.Factory.CreateDiagramLink(table, table2);
            link.RetainForm = true;
            link.DrawCrossings = true;
            link.HeadPen = new System.Windows.Media.Pen(new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromRgb(0, 0, 0)), 0.2f);
            link.HeadShape = MindFusion.Diagramming.Wpf.ArrowHeads.Triangle;
            link.HeadShapeSize = 10;
            link.Brush = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromRgb(0, 0, 0));
            link.Text = "1-n";
            link.TextAlignment = TextAlignment.Center;
            link.Shape = MindFusion.Diagramming.Wpf.LinkShape.Cascading; 



and the use the layouter like this
Code
Select All
            var layout = new MindFusion.Diagramming.Wpf.Layout.AnnealLayout();

            layout.SplitGraph = true;
            layout.Randomize = false;
            layout.MultipleGraphsPlacement = MindFusion.Diagramming.Wpf.Layout.MultipleGraphsPlacement.MinimalArea;
            layout.Margins = new System.Windows.Size(100, 100);
            layout.Arrange(d); 



Any ideas what I'm doing wrong?
regards Michael
  

layout.png ( 11 KB | 90 Downloads )
layout.png
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Database layout
Reply #1 - Nov 17th, 2015 at 9:03am
Print Post  
Hi,

None of the layout classes treat table row connections differently from regular node-to-node connections, so in this case the Arrange method places nodes in a column (which would look good enough for regular ShapeNodes), and than just realigns links' ends to their rows. You will get better results if you apply layouts that support horizontal orientation, where realigning links to rows would not displace them much. For example:

Code
Select All
private void OnLayoutLayered(object sender, RoutedEventArgs e)
{
	var layout = new LayeredLayout();
	layout.Orientation = MindFusion.Diagramming.Wpf.Layout.Orientation.Horizontal;
	layout.IgnoreNodeSize = false;
	layout.Arrange(diagram);

	diagram.RouteAllLinks();

	diagram.ResizeToFitItems(10);
} 





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


I Love MindFusion!

Posts: 17
Joined: Nov 9th, 2012
Re: Database layout
Reply #2 - Nov 17th, 2015 at 9:03pm
Print Post  
Hi Stoyan
thx this works. But now I have the Problem the Diagramm to big! My Layouting is the same then yours:
Code
Select All
private void Layout()
        {
            var layout = new MindFusion.Diagramming.Wpf.Layout.LayeredLayout();
            layout.Orientation = MindFusion.Diagramming.Wpf.Layout.Orientation.Horizontal;
            layout.IgnoreNodeSize = false;
            layout.Arrange(d);
            d.RouteAllLinks();
            d.ResizeToFitItems(1);
        } 


do you have an Idea how I can solve this?
Regards
  

size.png ( 25 KB | 90 Downloads )
size.png
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Database layout
Reply #3 - Nov 18th, 2015 at 8:54am
Print Post  
Hi Michael,

As your diagram contains many connections, I suppose it's getting big because LayeredLayout distributes crossing points of links with layers at NodeDistance too. You can verify that by removing the RouteAllLinks call.

You could still compact the nodes after calling LayeredLayout.Arrange and before the RouteAllLinks call as in these posts, showing both vertical and horizontal compaction (the code starting with var layers = ... ):

http://mindfusion.eu/Forum/YaBB.pl?num=1358765932/5#5
http://mindfusion.eu/Forum/YaBB.pl?num=1366076038/1#1

Use the vertical compaction code when applying Horizontal layout orientation, which creates vertical layers.

edit: looking at the old posts, they are intended to use with IgnoreNodeSize enabled. Either set it to true, or remove the if (node.Bounds.Top <= prev.Bounds.Bottom) condition to place all nodes from the layer at equal distances.

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


I Love MindFusion!

Posts: 17
Joined: Nov 9th, 2012
Re: Database layout
Reply #4 - Nov 19th, 2015 at 12:43pm
Print Post  
Hi Stoyan
sorry it is not completly working Sad!
When I have a bigger diagram with more tables on it I have the some problem to the right side!
I'm already tried to calculate the X value my self after the Y values have been calculated, but the diagramm ignors this.
Code
Select All
            foreach (var layer in layers.Values)
            {
                layer.Sort((n1, n2) => n1.Bounds.Y.CompareTo(n2.Bounds.Y));
                for (int i = 1; i < layer.Count; i++)
                {
                    var node = layer[i];
                    var prev = layer[i - 1];
                    if (node.Bounds.Top <= prev.Bounds.Bottom)
                        node.Move(node.Bounds.X, prev.Bounds.Bottom + 5);
                }
            }

            foreach (var layer in layers.Values)
            {
                layer.Sort((n1, n2) => n1.Bounds.X.CompareTo(n2.Bounds.X));
                for (int i = 1; i < layer.Count; i++)
                {
                    var node = layer[i];
                    var prev = layer[i - 1];
                    //if (node.Bounds.Left <= prev.Bounds.Right)
                        node.Move(prev.Bounds.Right-150, node.Bounds.Y);
                }
            }
 



Do you have and Idea how I can fix this?

Regards Michael
« Last Edit: Nov 19th, 2015 at 2:51pm by Michael »  

size_001.png ( 81 KB | 92 Downloads )
size_001.png
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Database layout
Reply #5 - Nov 20th, 2015 at 9:42am
Print Post  
Hi,

Please attach the saved diagram file. I suppose it grows to the right because LayeredLayout places connected nodes in separate layers (and we've selected it for this reason, to avoid the column layout from your first image). So, many connections between the tables will create additional layers requiring more horizontal space. You might try the different values of LayeredLayout.EnforceLinkFlow, as they apply different layering algorithms. Alternatively, you might try excluding some links from the layout (set their IgnoreLayout property) for tables with many connections to avoid them creating additional layers.

If you don't mind connected nodes sharing X positions, you could try another layout class to get more compact arrangement (e.g. AnnealLayout again) combined with link routing.

Regards,
Stoyan
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint