Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic OnCallback on server-side Unable to create diagramLink & Diagram Arrange (Read 5527 times)
henry k
Junior Member
**
Offline


I Love MindFusion!

Posts: 51
Location: Finland
Joined: Apr 4th, 2012
OnCallback on server-side Unable to create diagramLink & Diagram Arrange
Apr 24th, 2012 at 9:02am
Print Post  
Just noticed few cases in diagramView that:

{no problem case}
1) on init (first load or a postback) when you sample and create 2 nodes and after that you create link between them. Link is created and works perfect.

{problem case}
2) on callback, you have diagram object in session. You load the object and find target (A & B) nodes and you create link between them. The link is not created (failed to create one). The link object contains all necessary details and information that is set to it but when you debug the diagrams data and look for links (linkCollection) there is link count 0 [zero].... I have put a try-catch to get hold of possible problems, but result is without any errors... I find this as a bug... (or I'm missing something really important here...)

Any help would be great...

Br. Henry
« Last Edit: Apr 24th, 2012 at 12:59pm by henry k »  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: OnCallback on server-side Unable to create diagramLink
Reply #1 - Apr 24th, 2012 at 10:04am
Print Post  
What does the link creation code look like?
  
Back to top
 
IP Logged
 
henry k
Junior Member
**
Offline


I Love MindFusion!

Posts: 51
Location: Finland
Joined: Apr 4th, 2012
Re: OnCallback on server-side Unable to create diagramLink
Reply #2 - Apr 24th, 2012 at 10:39am
Print Post  
Like this:
Code
Select All
private bool _createLinkNode(string linkText, Color linkTextColor, string nodeTag, DiagramNode org, DiagramNode dest){
....
DiagramLink link = diagram.Factory.CreateDiagramLink(org, dest);
...
}
 



But I just resolved it... don't know why, but this works:

Code
Select All
private bool _createLinkNode(string linkText, Color linkTextColor, string nodeTag, DiagramNode org, DiagramNode dest){
....
DiagramLink link = diagram.Factory.CreateDiagramLink(diagram.GetNodeAt(org.Bounds.Location), diagram.GetNodeAt(dest.Bounds.Location));
....
}
 




But now I have sequel problem related to this.
Now on diagram arrange all nodes vanishes (only in case when a link is created || one or more)....
Also noticed that Diagram Bounds are messed because of this... default: (0,0, 2000, 1500)... after link creation + diagram_arrange (-23.3, -46.5, 2158, 1532). (note: this number is random, but mainly X & Y goes minus)....


Code
Select All
DiagramItemCollection childNodes = null;
LayeredLayout ll = null;

/* FROM HERE */
/* ** will arrange nodes in containers ** */
// get nodes collection in diagram
foreach (DiagramItem di in diagram.Nodes){
	Type t = di.GetType();

	// find node type "ContainerNode"
	if (t.Name.ToUpper() == "CONTAINERNODE"){
		// get all nodes in container nodes and set them to a node collection to be arranged.
		ContainerNode cn = di as ContainerNode;
		if (cn.SubordinateGroup != null){
			childNodes = new DiagramItemCollection();

			foreach (DiagramNode childNode in cn.SubordinateGroup.AttachedNodes){
				childNodes.Add(childNode);

				foreach (DiagramLink link in childNode.OutgoingLinks)
					childNodes.Add(link);
			}

			ll = new LayeredLayout();
			ll.LayerDistance = 50;
			ll.NodeDistance = 60;
			ll.Orientation = MindFusion.Diagramming.Layout.Orientation.Horizontal;

			ll.Arrange(diagram, childNodes);
			cn.UpdateBounds(true);
		}
	}
}
/* TO HERE */

ll = new LayeredLayout();
ll.LayerDistance = 50;
ll.NodeDistance = 100;
ll.SplitLayers = true;
ll.Orientation = MindFusion.Diagramming.Layout.Orientation.Horizontal;

ll.Arrange(diagram);

// ======================

public Diagram diagram
{
    get { return Session["diagram"] as Diagram; }
    set { Session["diagram"] = value; }
}
 

  
Back to top
 
IP Logged
 
henry k
Junior Member
**
Offline


I Love MindFusion!

Posts: 51
Location: Finland
Joined: Apr 4th, 2012
Re: OnCallback on server-side Unable to create diagramLink
Reply #3 - Apr 24th, 2012 at 12:59pm
Print Post  
henry k wrote on Apr 24th, 2012 at 10:39am:
Like this:
But now I have sequel problem related to this.
Now on diagram arrange all nodes vanishes (only in case when a link is created || one or more)....
Also noticed that Diagram Bounds are messed because of this... default: (0,0, 2000, 1500)... after link creation + diagram_arrange (-23.3, -46.5, 2158, 1532). (note: this number is random, but mainly X & Y goes minus)....


Code
Select All
DiagramItemCollection childNodes = null;
LayeredLayout ll = null;

/* FROM HERE */
/* ** will arrange nodes in containers ** */
// get nodes collection in diagram
foreach (DiagramItem di in diagram.Nodes){
	Type t = di.GetType();

	// find node type "ContainerNode"
	if (t.Name.ToUpper() == "CONTAINERNODE"){
		// get all nodes in container nodes and set them to a node collection to be arranged.
		ContainerNode cn = di as ContainerNode;
		if (cn.SubordinateGroup != null){
			childNodes = new DiagramItemCollection();

			foreach (DiagramNode childNode in cn.SubordinateGroup.AttachedNodes){
				childNodes.Add(childNode);

				foreach (DiagramLink link in childNode.OutgoingLinks)
					childNodes.Add(link);
			}

			ll = new LayeredLayout();
			ll.LayerDistance = 50;
			ll.NodeDistance = 60;
			ll.Orientation = MindFusion.Diagramming.Layout.Orientation.Horizontal;

			ll.Arrange(diagram, childNodes);
			cn.UpdateBounds(true);
		}
	}
}
/* TO HERE */

ll = new LayeredLayout();
ll.LayerDistance = 50;
ll.NodeDistance = 100;
ll.SplitLayers = true;
ll.Orientation = MindFusion.Diagramming.Layout.Orientation.Horizontal;

ll.Arrange(diagram);

// ======================

public Diagram diagram
{
    get { return Session["diagram"] as Diagram; }
    set { Session["diagram"] = value; }
}
 



This problem solved (loading saved string of diagram messed up the diagram some how; by skipping the load part and save the reconstructed one worked)...

Though I came with a new problem (I post this problem here because the structure is displayed here... otherwise I would make new post).

When arrange is done, containers size is expanded every time...:
First (W=300, H=120)
Second (W=550, H=280)
... and so on... do not understand why. I tried to add also autoShrink but this doesn't help me at all... actually for now, unknown reason..

Br. Henry
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: OnCallback on server-side Unable to create diagramLink & Diagram Arrange
Reply #4 - Apr 24th, 2012 at 5:09pm
Print Post  
Diagram.Factory.CreateDiagramLink might fail if the specified origin and destination nodes are not in that same diagram. I imagine this would cause the problem:

org = diagram.FindNode(...);
dest = diagram.FindNode(...);
diagram.LoadFromString(...);
// org and dest are no longer references to objects in diagram
_createLinkNode(org, dest);
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: OnCallback on server-side Unable to create diagramLink & Diagram Arrange
Reply #5 - Apr 24th, 2012 at 5:15pm
Print Post  
By the way, in C# you can replace

if (di.GetType().Name.ToUpper() == "CONTAINERNODE")

with

if (di is ContainerNode)

or combine it with the next typecast to just this:

ContainerNode cn = di as ContainerNode;
if (cn != null)
{
    // do stuff with cn
}
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: OnCallback on server-side Unable to create diagramLink & Diagram Arrange
Reply #6 - Apr 24th, 2012 at 5:28pm
Print Post  
I can reproduce containers expanding when AutoShrink is set to false - then UpdateBounds only grows a container to include the new positions of its child nodes (that were set by LayeredLayout), but will not reclaim any unoccupied space. If you set AutoShrink to true, containers shouldn't expand any longer.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
henry k
Junior Member
**
Offline


I Love MindFusion!

Posts: 51
Location: Finland
Joined: Apr 4th, 2012
Re: OnCallback on server-side Unable to create diagramLink & Diagram Arrange
Reply #7 - Apr 25th, 2012 at 5:59am
Print Post  
Stoyo wrote on Apr 24th, 2012 at 5:15pm:
By the way, in C# you can replace

if (di.GetType().Name.ToUpper() == "CONTAINERNODE")

with

if (di is ContainerNode)

or combine it with the next typecast to just this:

ContainerNode cn = di as ContainerNode;
if (cn != null)
{
// do stuff with cn
}


true, mine was quickly done test function... (I also have few other excuses  Grin )
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: OnCallback on server-side Unable to create diagramLink & Diagram Arrange
Reply #8 - Apr 25th, 2012 at 10:23am
Print Post  
Roll Eyes
  
Back to top
 
IP Logged
 
henry k
Junior Member
**
Offline


I Love MindFusion!

Posts: 51
Location: Finland
Joined: Apr 4th, 2012
Re: OnCallback on server-side Unable to create diagramLink & Diagram Arrange
Reply #9 - Apr 26th, 2012 at 6:08am
Print Post  
Stoyo wrote on Apr 24th, 2012 at 5:28pm:
I can reproduce containers expanding when AutoShrink is set to false - then UpdateBounds only grows a container to include the new positions of its child nodes (that were set by LayeredLayout), but will not reclaim any unoccupied space. If you set AutoShrink to true, containers shouldn't expand any longer.

I hope that helps,
Stoyan


You're correct. Autoshrink is needed to be set to true in the loop where containers are handled. As you described on previous post, the object(s) are no longer references to the objects in diagram. I changed my "coding style" and it works now. (solved some other issues)

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