Snapping to other objects

Hello

My diagram has gridsnapping enabled. However, there are objects with sizes that do not fit with the grid (grid has steps of 5… and the object has a width of 17 for example). Therefore, my company decided to get rid of grid snapping. That is, if there is a possibility to snap to other objects.

Refer to the image for better understanding:
Example

What I want to achieve: Moving the top right object by dragging it with the mouse to the left or down should make the object snap to the pink line, either vertically or horizontally, depending on which way it was moved.

I know that it is possible to write your custom moveParts etc. as I saw in this example:

https://gojs.net/latest/samples/pipes.html

My question is: Is there some premade functionality in GoJS to enable this kind of behaviour? I could alter the pipes sample but there would be no sense to it if there was this kind of functionality already (which I could not find in your docs yet).

Best regards
Martin

Have you seen https://gojs.net/latest/extensions/GuidedDragging.html ? It is implemented by https://gojs.net/latest/extensions/GuidedDraggingTool.js. You may have slightly different requirements, but you can adapt the code for your own purposes.

Thank you so much, it took me only 2 minutes to get exactly the behaviour I needed! :)

However, there is one more think I need, which is guided resizing. It should be possible to resize elements and snap them to otheres, so basically the same thing as in “GuidedDraggingTool”. I did not find anything under “ResizingTool” in the API. Does something like this exist too?

I guess there isn’t such a custom ResizingTool already. Sorry, but you will have to implement that yourself. I suggest that you read the implementation of the GuidedDraggingTool as a guide for how to implement such a custom ResizingTool.

Thank you, I will come back to this topic in case I fail to implement this functionality as intended.