Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic While resizing need an event that tells if child is added or removed from container. (Read 4169 times)
Ankur shah
Junior Member
**
Offline


I Love MindFusion!

Posts: 63
Joined: Mar 16th, 2017
While resizing need an event that tells if child is added or removed from container.
Apr 10th, 2019 at 12:31pm
Print Post  
I am creating a container node on canvas through drag and drop. Lets say i have created ten container node separately none of them are linked. Now i have selected the of the container node resizing it through mouse while resizing it might be possible that some of other container node present in canvas get inside the resized container. My problem is that when we are resizing the container we don't know which all node becomes the child of that container. How can we handle this problem?
  
Back to top
 
IP Logged
 
Lyubo
God Member
*****
Offline


MindFusion team

Posts: 511
Joined: Jun 17th, 2010
Re: While resizing need an event that tells if child is added or removed from container.
Reply #1 - Apr 10th, 2019 at 1:48pm
Print Post  
Hi,

You could handle the containerChildAdding event to determine if you want the node to be added to the container's children collection, and cancel the action if needed.
Code (Javascript)
Select All
diagram.addEventListener(MindFusion.Diagramming.Events.containerChildAdding, function (sender, args)
{
	var node = args.getNode();
	var container = args.getContainer();

	// determine if the child node is a container or not.
	// or use other condition
	if (MindFusion.AbstractionLayer.isInstanceOfType(MindFusion.Diagramming.ContainerNode, node))
		args.setCancel(true);
}); 



Regards,
Lyubo
  
Back to top
 
IP Logged
 
Ankur shah
Junior Member
**
Offline


I Love MindFusion!

Posts: 63
Joined: Mar 16th, 2017
Re: While resizing need an event that tells if child is added or removed from container.
Reply #2 - Apr 11th, 2019 at 6:14am
Print Post  
Thanks for replying. But I am facing problem when resizing parent container node . My aim to enlarge the parent container node so that what ever area is covered by parent node under that area all other nodes become a child of parent.

What mind fusion library is doing is that when ever we enlarge the node via mouse what ever container node it touches. it creates enlarge container a child of touched container but what i need achieve opposite of this behavior.

As you can see in a attached pic. Over here i am expanding car container so what i am expecting that car container must add steering as a child itself. This just an example we can have n number or container so that it can be included as child
« Last Edit: Apr 11th, 2019 at 7:32am by Ankur shah »  

Expanding.PNG (Attachment deleted)
Back to top
 
IP Logged
 
Lyubo
God Member
*****
Offline


MindFusion team

Posts: 511
Joined: Jun 17th, 2010
Re: While resizing need an event that tells if child is added or removed from container.
Reply #3 - Apr 11th, 2019 at 8:33am
Print Post  
Hi,

Try this:
Code (Javascript)
Select All
diagram.addEventListener(MindFusion.Diagramming.Events.nodeModified, function (sender, args)
{
  var container = args.getNode();
  if (MindFusion.AbstractionLayer.isInstanceOfType(MindFusion.Diagramming.ContainerNode, container))
  {
    var containerBounds = container.getBounds();
    var nodeAdded = false;
    for (var i = 0; i < diagram.getNodes().length; i++)
    {
      var node = diagram.getNodes()[i];
      if (node === container || node.getContainer() != null)
        continue;

      var bounds = node.getBounds();
      if (containerBounds.contains(bounds))
      {
        nodeAdded = true;
        container.add(node);
      }
    }
    if (nodeAdded)
      container.resizeToFitChildren();
  }
}); 



Regards,
Lyubo
  
Back to top
 
IP Logged
 
Ankur shah
Junior Member
**
Offline


I Love MindFusion!

Posts: 63
Joined: Mar 16th, 2017
Re: While resizing need an event that tells if child is added or removed from container.
Reply #4 - Apr 11th, 2019 at 9:45am
Print Post  
This works to some extent. What if we are shrinking the size of container node then it should removed from container node.

One more query that when ever it touches the other container node but it is not fully inside the container node. How should we handle this as this is hiding the portion of container.
  
Back to top
 
IP Logged
 
Lyubo
God Member
*****
Offline


MindFusion team

Posts: 511
Joined: Jun 17th, 2010
Re: While resizing need an event that tells if child is added or removed from container.
Reply #5 - Apr 11th, 2019 at 10:56am
Print Post  
Replace the body of the for loop in the previous example with:
Code (Javascript)
Select All
var node = diagram.getNodes()[i];
if (node === container)
  continue;

var bounds = node.getBounds();

if (node.getContainer() === container)
{
  if (!containerBounds.intersectsWith(bounds))
  {
    nodeAdded = true;
    container.remove(node);
  }
}
else if (node.getContainer() != null)
  continue;
else
{
  if (containerBounds.intersectsWith(bounds))
  {
    nodeAdded = true;
    container.add(node);
  }
} 



Regards,
Lyubo
  
Back to top
 
IP Logged
 
Ankur shah
Junior Member
**
Offline


I Love MindFusion!

Posts: 63
Joined: Mar 16th, 2017
Re: While resizing need an event that tells if child is added or removed from container.
Reply #6 - Apr 11th, 2019 at 11:28am
Print Post  
Yes that's working fine but it regress the existing functionality i.e. when ever drag some node in to the container node. Dragged node become parent for container node. We need handle this also.
  
Back to top
 
IP Logged
 
Lyubo
God Member
*****
Offline


MindFusion team

Posts: 511
Joined: Jun 17th, 2010
Re: While resizing need an event that tells if child is added or removed from container.
Reply #7 - Apr 12th, 2019 at 11:07am
Print Post  
Hi,

You need some way to differentiate between the different user interactions - whether the user wants to add children via resize, or just to move a child node to a parent. One approach could be to add the children from the nodeModifed handler, only when it's a result of a 'resize' interaction, leaving the default behavior for 'move' actions. Another approach could be to run the code above only when the Ctrl is pressed (you can check for pressed keys via the MindFusion.Diagramming.Keyboard object).

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