Page Index Toggle Pages: 1 2 [3]  Send TopicPrint
Very Hot Topic (More than 25 Replies) i want to restrict to move outside node inside scope and can not intersect with scope and vis-versa (Read 1385 times)
reshma
Junior Member
**
Offline


I Love MindFusion!

Posts: 52
Joined: Jan 16th, 2018
Re: i want to restrict to move outside node inside scope and can not intersect with scope and vis-versa
Reply #30 - Oct 22nd, 2020 at 4:43am
Print Post  
ya i know with this union values considered but
i already used
if (nodes[i] !== container ) while checking in containerparent
still it is showing same result
but as in my case i am checking first selected node is intersect within parent with any child if it is not then i am checking for the parent suppose with crect my selected node moving and i am intersecting parent to that Parentcontainer child except same node as you mentioned once it is intersect i am return setcancancel(true) after that i am trying to move selected node still it is not moved beacuse it is checking for parent also and parent is already intersect if i removed that intersect it allows me to move
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 2300
Joined: Oct 19th, 2005
Re: i want to restrict to move outside node inside scope and can not intersect with scope and vis-versa
Reply #31 - Oct 22nd, 2020 at 3:40pm
Print Post  
You should use some punctuation here and there. This is how I imagine what you are describing -

Code
Select All
function onNodeModifying(diagram, args)
{
	var container = args.node.container;
	if (container)
	{
		var rect = args.node.getBounds();

		// prevent dragged node from intersecting with other nodes in same container
		for (var sibling of container.children)
		{
			if (args.node == sibling)
				continue;
			var siblingRect = sibling.getBounds();
			if (rect.intersectsWith(siblingRect))
			{
				args.setCancel(true);
				return;
			}
		}

		// calculate new container bounds if node dropped here
		var crect = container.getContentBounds(true);
		crect = crect.inflate(container.margin);
		crect.y -= container.captionHeight;
		crect.height += container.captionHeight;
		if (!container.allowShrink)
			crect = crect.union(container.bounds);

		// prevent container from intersecting with other nodes in parent container
		// this should be done recursively instead
		if (container.container)
		{
			for (var sibling of container.container.children)
			{
				if (container == sibling)
					continue;
				var siblingRect = sibling.getBounds();
				if (crect.intersectsWith(siblingRect))
				{
					args.setCancel(true);
					return;
				}
			}
		}
	}
} 



This does not handle the case of moving child node entirely outside of its current container. In this case crect would just follow the dragged node, even if container would not expand if you drop the child outside. If you need to prevent moving child outside of container, you could add an extra intersection check -

Code
Select All
function onNodeModifying(diagram, args)
{
	var container = args.node.container;
	if (container)
	{
		var rect = args.node.getBounds();

		// prevent dragged node from intersecting with other nodes in same container
		for (var sibling of container.children)
		{
			if (args.node == sibling)
				continue;
			var siblingRect = sibling.getBounds();
			if (rect.intersectsWith(siblingRect))
			{
				args.setCancel(true);
				return;
			}
		}

		// do we allow child moving outside container?
		if (!rect.intersectsWith(container.bounds))
		{
			args.setCancel(true);
			return;
		}

		// calculate new container bounds if node dropped here
		var crect = container.getContentBounds(true);
		crect = crect.inflate(container.margin);
		crect.y -= container.captionHeight;
		crect.height += container.captionHeight;
		if (!container.allowShrink)
			crect = crect.union(container.bounds);

		// prevent container from intersecting with other nodes in parent container
		// this should be done recursively instead
		if (container.container)
		{
			for (var sibling of container.container.children)
			{
				if (container == sibling)
					continue;
				var siblingRect = sibling.getBounds();
				if (crect.intersectsWith(siblingRect))
				{
					args.setCancel(true);
					return;
				}
			}
		}
	}
} 



If you do allow moving child outside of its container, then you will also need to check for intersections with its new siblings in container.container. There's also the possible case of moving the node to a container in a different level of the hierarchy - not just current container's parent, so you will need to code all that recursively.
  
Back to top
 
IP Logged
 
reshma
Junior Member
**
Offline


I Love MindFusion!

Posts: 52
Joined: Jan 16th, 2018
Re: i want to restrict to move outside node inside scope and can not intersect with scope and vis-versa
Reply #32 - Nov 9th, 2020 at 6:27am
Print Post  
Thank you now working for me Smiley
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1 2 [3] 
Send TopicPrint