Group not containing the node at maxLocation

Hi,

I am having an issue with a group not containing the nodes which it visually does. I have set the maxLocation for my nodes equal to the size of the group. When I drag and drop the node to the bottom limit, to where it stopt dragging, the node has group element “undefined”, and the group does not contain said node. When nodes are not placed directly against the bottom border of the group, everything works as intended. I am wondering what I am doing wrong.

Example of maxLocation and minLocation of a node:

{ maxLocation: new go.Point(1000, 1000) , minLocation: new go.Point(50, 50) }

Thanks in advance.

Have you set the Node.locationSpot property?

Setting the Node.maxLocation to be the size of the Group means that by default (i.e. the Node.locationSpot == Spot.TopLeft) the Node can be moved so that only the very top-left corner of the node might be within the Group, and all of the rest of it is outside the Group.

Why did you choose minLocation == 50,50? You might need to do a similar accounting for a margin, based on the size of the Node, from the bounds of the Group.

By the way, note also that Part.minLocation and Part.maxLocation are in document coordinates. If the Group is moved away from 0,0, or if the Group changes size, the Nodes won’t be limited to the area of the Group.

I suggest that you instead implement a Part.dragComputation function, such as the stayInGroup function defined in the SwimLanes sample. You’ll want to adapt that code to your own app’s requirements.

Hello walter,

Thanks for your answer.
Currently I have made it so that when the group size changes, or the number of groups changes, I recalculate the max and minlocation for all nodes.
I read the stayInGroup example, but my only condition to my diagram is that every node should be contained in a group, in which group of the diagram, does not really matter. I have seen that in the stayInGroup example, you need to push down keys to be able to draw a node to a different group.

To summarize: all I want to achieve is to have nodes always on a group, new nodes can also only be added to a group. I was wondering what the best solution for me might be. Because the entire max/minLocation setup took me quite a while to develop.

Well, if you don’t want to allow the user to move a Node out of a Group, you can remove that code that checks for the Shift key in that stayInGroup function of that sample.

If you are supporting the resizing of Groups, I assume you either limit how small the group can be resized in order to make sure all member nodes are physically within the area of the group, or you move some member nodes so that they remain within the smaller group’s area. The Swim Lanes sample uses the former policy, by overriding the ResizingTool’s methods.