GuidedDragging and SelectionObject

Hi.
i try to use the guidedDragging tool.
https://gojs.net/latest/extensions/GuidedDragging.html

It works fine. But i don’t want to use the actualBound of the parts, but of the selectionObject of the parts. So i don’t know how to change the methods “showHorizontalMatches” and “showVerticalMatches”.
Please help me. Thx.

In those methods you can see where it is using the actualBounds property of the Parts. Instead you want to use the bounds of the Part.selectionObject. But since the selectionObject is different from the whole Part, you first need to convert those coordinates into document coordinates.

You can do that by calling GraphObject.getDocumentPoint. Something like:

function getDocumentBounds(obj) {
  var tl = obj.getDocumentPoint(go.Spot.TopLeft);
  var br = obj.getDocumentPoint(go.Spot.BottomRight);
  return new go.Rect(tl, br);
}

In version 2.0 we are introducing a GraphObject.getDocumentBounds method which can be more efficient than the above code. Until then I suggest you make do with it.

Great. But the snap is not working.

Can i move the selectionObject with part.selectionObject.move();
My part is higher than the selectionObject. So i have to calculate the y coordinate new?!

Ah, yes, that snapping code needs to be adapted to understand that the selectionObject is not the same as the whole Part. I think you just need to offset the move by the difference between the position of the selectionObject and the position of the Part.

Like

const diffx = part.selectionObject.x - part.x; const diffy = part.selectionObject.y - part.y; part.move(new go.Point(partBounds.x - diffx, (bestPoint.y - partBounds.height / 2) - diffy));

That doesn’t look right to me – does it work for you?

First, there’s no GraphObject.x or GraphObject.y property.

Second, you need to subtract values in the same coordinate system – i.e. call getDocumentBounds.

It work for me ? I don’t know why.
But i subtract now the values…