Use go.Spot.TopLeft for snapping but go.Spot.Center for angle (rotate)

Hi There- I did not see this asked previously.

Is there an easy way to have a node snap to the topleft but rotate about its center when we change the angle property? Changing the locationSpot on the fly seems to have a lot of unintended consequences like causing the node to shift.

thanks,
Caleb

Yes. Specify a Part.rotateObjectName that refers to an object that is not the whole Part itself nor is the Part.locationObject. For example:

    myDiagram.nodeTemplate =
      $(go.Node,
        { rotatable: true, rotateObjectName: "BODY" },
        $(go.Panel, "Auto",
          { name: "BODY" },
          $(go.Shape,
            { fill: "white", portId: "", fromLinkable: true, toLinkable: true, cursor: "pointer" },
            new go.Binding("fill", "color")),
          $(go.TextBlock,
            { margin: 8, editable: true },
            new go.Binding("text").makeTwoWay())
          )
      );

Hi Walter-

Thanks for the response. How do I make it snap to the top left of the Shape now? if I do it something like this:

myDiagram.nodeTemplate =
  $(go.Node,
    { rotatable: true, rotateObjectName: "BODY", locationSpot: go.Spot.TopLeft },
    $(go.Panel, "Auto",
      { name: "BODY" },
      $(go.Shape,
        { fill: "white", portId: "", fromLinkable: true, toLinkable: true, cursor: "pointer" },
        new go.Binding('angle',makeTwoWay()),
      $(go.TextBlock,
        { margin: 8, editable: true },
        new go.Binding("text").makeTwoWay())
      )
  );

Rotating with the tool or changing the angle property still goes about the top left.

You need to fix the Binding that you added.

The default Part.locationSpot is go.Spot.TopLeft, so you don’t need to write it.

The RotatingTool keeps the Part.location the same as it rotates the Part.rotationObject. That means the top-left corner of the node stays at the same point in document coordinates. The object that is rotated, the Part.rotationObject rotates about its own axis – it does not revolve around the location point, which remains towards the top-left of the object being rotated.