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 1033 times)
reshma
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 48
Joined: Jan 16th, 2018
i want to restrict to move outside node inside scope and can not intersect with scope and vis-versa
Jul 29th, 2020 at 10:12am
Print Post  
In my diagram i have one scope node and inside that other node and other nodes are in outside scope.
So i want to restrict to move outside node inside scope and outside node can not intersect with scope and vis-versa .

below i have attached one image that contain large one is my scope and some node inside it and outside scope other nodes.
« Last Edit: Jul 29th, 2020 at 11:28am by reshma »  

diagram_B.png ( 23 KB | 9 Downloads )
diagram_B.png
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Online


tech.support

Posts: 2279
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 #1 - Jul 30th, 2020 at 8:00am
Print Post  
Set AllowAddChildren and AllowRemoveChildren properties of ContainerNode to false. You'll be able to add child nodes to the container only from code then.

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
reshma
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 48
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 #2 - Jul 30th, 2020 at 10:36am
Print Post  
But at the time of creation i have add some node in the scope but once i added after that for modifying i am trying to change width or move outside node to scope should not allow to even intersect
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Online


tech.support

Posts: 2279
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 #3 - Jul 30th, 2020 at 1:45pm
Print Post  
You can prevent nodes being dropped at position where they'd intersect with the container from nodeModifying validation event handler. Call node.getBounds().intersect(container.getBounds()) to find if current positions intersect.

Regards,
Slavcho
  
Back to top
 
IP Logged
 
reshma
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 48
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 #4 - Jul 31st, 2020 at 7:31am
Print Post  
1) How can i find node is intersect with left side,right ,top and bottom side?
2)How can i find on nodecreated event that added in container child or outside?
3)How to avoid node intersect with other in half and not part of the container child ?
4) how can we find out node is not created exactly in container child it's partially touched?

Finally i do not want overlap any node on other node i want to shift node from current node (for eg if my node is overlap on top side i want shift this node on top of other node so that this can not overlap)
Please let me know .
As i checked your solution with intersect but it is showing intersect even i am adding node in the containerchild so please suggest


« Last Edit: Jul 31st, 2020 at 3:31pm by reshma »  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Online


tech.support

Posts: 2279
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 #5 - Aug 3rd, 2020 at 8:15am
Print Post  
Quote:
1) How can i find node is intersect with left side,right ,top and bottom side?


Code
Select All
let nb = node.getBounds();
let cb = container.getBounds();
if (nb.intersectsWith(cb))
{
    if (nb.left() <= cb.left() && cb.left() <= nb.right())
        console.log("intersects left");
    ...
} 

  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Online


tech.support

Posts: 2279
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 #6 - Aug 3rd, 2020 at 8:35am
Print Post  
Quote:
2)How can i find on nodecreated event that added in container child or outside?


nodeCreated is raised before child node is added to container, and then followed by containerChildAdding / containerChildAdded events. So containerChildAdding is earliest point where you know child node is being added, and you can cancel from it by calling eventArgs.setCancel(true);
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Online


tech.support

Posts: 2279
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 #7 - Aug 3rd, 2020 at 8:50am
Print Post  
Quote:
3)How to avoid node intersect with other in half and not part of the container child ?


If you mean allow intersecting a bit but no more than half node's area, try something like

Code
Select All
function onNodeModifying(diagram, args)
{
	var nodes = diagram.getNodes();
	var b1 = args.getNode().getBounds();
	var area1 = b1.width * b1.height;
	for (var i = 0; i < nodes.length; i++)
	{
		if (nodes[i] == args.getNode())
			continue;
		var b2 = nodes[i].getBounds();
		if (b2.intersectsWith(b1))
		{
			var area2 = b2.width * b2.height;
			var bi = b1.intersect(b2);
			var areai = bi.width * bi.height;
			if (areai > area2 / 2 || areai > area1 / 2)
				args.setCancel(true);
		}
	}
} 



or otherwise a direct setCancel(true) to prevent any intersection

Code
Select All
if (b2.intersectsWith(b1))
    args.setCancel(true);
 

  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Online


tech.support

Posts: 2279
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 #8 - Aug 3rd, 2020 at 8:53am
Print Post  
Quote:
4) how can we find out node is not created exactly in container child it's partially touched?


run same loop as above from nodeCreated / nodeCreating handler to find any intersecting nodes. Add an extra check for nodes[i]' type if you need to avoid intersections only with containers.
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Online


tech.support

Posts: 2279
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 #9 - Aug 3rd, 2020 at 8:59am
Print Post  
Quote:
Finally i do not want overlap any node on other node i want to shift node from current node (for eg if my node is overlap on top side i want shift this node on top of other node so that this can not overlap)


If you mean allow dropping the node anywhere but then adjusting position, move that loop from nodeModifying / nodeCreating to nodeModified / nodeCreated, and instead setCancel(true), modify the node's bounds as desired. It's not as simple as just aligning the moved node to the intersected one because it might introduce new intersections with nearby nodes. Instead, you might have to loop and shift node by some step until you find unoccupied area. Overall better cancel from validation event and let users find position they like.
  
Back to top
 
IP Logged
 
reshma
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 48
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 #10 - Aug 3rd, 2020 at 2:07pm
Print Post  
i agree with your solution but i have problem is like i want to find only those intersect that are half part of node is inside and other is outside that means it's not part of container child only those overlap i have to find and for that i will do setcancel true not for all node intersect with(i mean if i am adding in the container child that time also showing intersect this node but that i do not want) .

I want only those overlapped node that are half portion of the node is outside (i mean it is not child of the node) but intersect with some portion of the node.
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Online


tech.support

Posts: 2279
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 #11 - Aug 3rd, 2020 at 3:12pm
Print Post  
the cancel condition should be containerRect.intersectsWith(nodeRect) && !containerRect.contains(nodeRect)
  
Back to top
 
IP Logged
 
reshma
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 48
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 #12 - Aug 13th, 2020 at 9:25am
Print Post  
Thank you,above all answers are useful for me.
i have one more question how to find node is intersect with left side or right side or top side or bottom side.
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Online


tech.support

Posts: 2279
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 #13 - Aug 13th, 2020 at 3:13pm
Print Post  
that was shown above, e.g. node intersects left side of container -

Code
Select All
let nb = node.getBounds();
let cb = container.getBounds();
if (nb.intersectsWith(cb))
{
    if (nb.left() <= cb.left() && cb.left() <= nb.right())
        console.log("intersects left");
    ...
}
 



Checks for other sides are analogous to left.
  
Back to top
 
IP Logged
 
reshma
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 48
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 #14 - Aug 17th, 2020 at 12:28pm
Print Post  
how to handle one more scenario for overlapping
suppose i have 3 nodes c1 is parent of c2 and c3 is near to C1 if i try to modify the node c2 then automatically C1 size is increased and C1 and C3 are intersect how to find this?
i have try to find it on containerchildadded event but it's already getting increasing some size so i am not getting exact intersect points .
How to handle both child as well as parent position at original when the parent intersect to other node?
  

Back to top
 
IP Logged
 
Page Index Toggle Pages: [1] 2 3 
Send TopicPrint