Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Diagram width issue (Read 2982 times)
jlj30
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 183
Joined: Sep 4th, 2011
Diagram width issue
Feb 5th, 2014 at 10:14pm
Print Post  
Hi,

I have employed several techniques that you have provided over the past year and they have all been very helpful.
One such method that I have adapted for my use seems to be causing a problem.

Have a look at the attached screenshots.
The only difference between the 2 diagrams is that the 2nd one (BAD) has links to some nodes in a second swim lane.

Why this would cause the overall diagram to be wider is a mystery to me.  I've been looking at this for too long.  It's time to get your help Smiley

Here's the code that attempts to align the nodes in the 2nd swim lane with their parent in the 1st lane.
It appears to do just what I want (thanks for that), except with the undesirable increase in the diagram width.

Code (C++)
Select All
protected void AlignNodeTo(DiagramNode node, DiagramNode relatedNode, Diagram diagram)
	{
		// Code provided by Mindfusion (Stoyan) on 05Jul2013 (with some minor modifications)
		// It ensures that IP and Data shapes are aligned under their parent task
        node.Move(relatedNode.Bounds.X + ((relatedNode.Bounds.Width - node.Bounds.Width) / 2), node.Bounds.Y);

		// find all nodes in the same lane as the aligned one
		var nodesInLane = new List<DiagramNode>();
		foreach (DiagramNode n in diagram.Nodes)
		{
			if (n.LayoutTraits[SwimlaneLayoutTraits.Lane] != null)
					if (n.LayoutTraits[SwimlaneLayoutTraits.Lane].Equals(node.LayoutTraits[SwimlaneLayoutTraits.Lane]))
						nodesInLane.Add(n);
		}

		// if a node intersects the aligned one, move it to the right of it
        foreach (DiagramNode n in nodesInLane)
        {
            if (n != node && n.Intersects(node))
                n.Move(node.Bounds.Right + 5, n.Bounds.Y);
        }

        // Sort the nodes based on their X (left) coordinate
        nodesInLane.Sort((n1, n2) =>
			n1.Bounds.X.CompareTo(n2.Bounds.X));

		// shift remaining nodes to the right to remove overlaps
		for (int i = 1; i < nodesInLane.Count; i++)
		{
			var n1 = nodesInLane[i - 1];
			var n2 = nodesInLane[i];
			if (n2.Bounds.Left <= n1.Bounds.Right)
			{
				n2.Move(n1.Bounds.Right + 5, n2.Bounds.Y);
			}
		}
	} 



Here's a bit more code that puts the above in perspective.
The above method is called from alignShapesWithTasks which just loops thru all nodes on the diagram that have one of the shapes in the 2nd swim lane linked to it.

Code
Select All
Header colHeader = grid.FindColumn(colTitle);
		if (colHeader.Width < 225)  // Ensure a minimum width
			colHeader.Width = 225;

		// The following code will try to ensure that Data, IP and Annotation shapes are positioned directly below the task to which they are related
        alignShapesWithTasks(diagram);
        System.Diagnostics.Debug.WriteLine("---> diagram.GetContentBounds after alignShapesWithTasks = " + diagram.GetContentBounds(false, false));

		SortRoutedLinksTaskRight(diagram); // helps to reduce overlapping connectors coming out of the right side of a task
		SortRoutedLinksTaskLeft(diagram); // helps to reduce overlapping connectors coming into the left side of a task ** New code from MF - 29Dec2013 **
        SortRoutedLinksTaskBottom(diagram);

        diagram.RouteAllLinks();  // Moved after the above link sorting functions - 27Dec2013

        RectangleF columnHeaderBounds = diagram.LaneGrid.GetColumnHeaderBounds();
        RectangleF rowHeaderBounds = diagram.LaneGrid.GetRowHeaderBounds();
        RectangleF laneGridBounds = RectangleF.Union(columnHeaderBounds, rowHeaderBounds);
        RectangleF itemsBounds = diagram.GetContentBounds(false, false);
        diagram.Bounds = RectangleF.Union(itemsBounds, laneGridBounds);
        diagram.Bounds = new RectangleF(0F, 0F, diagram.Bounds.Width + 2F, diagram.Bounds.Height + 5F);

		// The following ensures a minimum width diagram

        if (diagram.Bounds.Width < 225)
            diagram.Bounds = new RectangleF(0F, 0F, 225, diagram.Bounds.Height); 



Any suggestions?

Thanks

Jim

  

Diagram_Width_Issue_-_OK.png (Attachment deleted)
Diagram_Width_Issue_-_BAD.png (Attachment deleted)
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Diagram width issue
Reply #1 - Feb 6th, 2014 at 2:41pm
Print Post  
I think the Arrange method fills the entire shown width when distributing nodes on second lane by layout's NodeDistance. It also resizes the grid to fit the nodes, but then you move them back to the left when re-aligning and this creates empty space? Try also setting the grid's ColumnHeaders[0].Width to the maximum right coordinate of all nodes (+ some padding value) to fix that.

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


I love YaBB 1G - SP1!

Posts: 183
Joined: Sep 4th, 2011
Re: Diagram width issue
Reply #2 - Feb 10th, 2014 at 12:42pm
Print Post  
Hi,

Setting the ColumnHeaders[0].Width did the trick.
Surprisingly, I didn't have to add a "padding value", but I'm not complaining.

Thanks

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Diagram width issue
Reply #3 - Feb 10th, 2014 at 1:19pm
Print Post  
Ok, Grid.Columns[0].Width does not include the width of row headers, so I suppose you get their width added to the right side if you assign content rectangle's width to column's Width.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint