Grid, node position origin

In some demo where the grid and snap features are enabled, the node position is in my opinion incorrect. In the case below, the “Step” should be on the point designed by the red cross.

In my case it’s the same thing, my node should be on the red cross and not between the two grid lines when snap and grid use the same size.

Is this possible to set which object is used to define the origin of the node (the rounded rectangle in my case) ?

Basically you need to set the Part.locationObjectName to refer to the object in your node’s visual tree that you want to be at the grid point.

In this case, I need to set the locationSpot on TopLeft to be aligned on a dot of the grid, but this spot is also the point used by the rotation. Is this possible to change the center of the rotation to be the center of the shape ? I dont thind a rotationSpot…

That’s been on the list of new features we should add some day.

I haven’t tried this, but you could try overriding RotatingTool.doActivate to call the base method and then set your own rotatePoint property to the point that you want to use. And override RotatingTool.computeRotate to compute the desired angle relative to that rotatePoint.

Walter, I tried a code like below but the rotatingPoint location is not changed. To be honest, I dont think my code is correct. The result is particulary “folklorique” (like we say in french… :) )

Note : RotatingPoint is a class with a simple constructor(x, y)

doActivate() {
  super.doActivate();
  const map = new go.Map(go.Part, RotatingPoint);
  this.diagram.selection.each((part) => {
    map.add(part, new RotatingPoint(part.actualBounds.centerX, part.actualBounds.y));
  });
  this.rotatingPoint = map;
}

rotate(newangle) {
  this.rotatingPoint.each((kvp) => {
    const part = kvp.key;
    if (part instanceof go.Link) return false;
    part.location = new go.Point(kvp.value.x, kvp.value.y);
    part.rotateObject.angle = newangle;  
    return true;
  });
}

computeRotate(newPoint) {
  const part = this.adornedObject.part;

  const rotationPoint = new go.Point(part.actualBounds.centerX, part.actualBounds.centerY);
  let angle = rotationPoint.directionPoint(newPoint);

  if (angle >= 360) angle -= 360;
  else if (angle < 0) angle += 360;
  return angle;
}

This is more than you need, but see this topic:

and in particular the GroupRotatingTool:
http://gojs.net/temp/GroupRotatingTool.js