I have customised example at (Limited Group Resizing) and tried to modify my code according to the example for the node instead of group. Below is the code:
const partPadding = new go.Margin(1);
export class LimitedPartResizingTool extends go.ResizingTool {
_lastOK = new go.Rect(); // in document coordinates
computeMinSize() {
const minSize = super.computeMinSize();
const { part } = this.adornedObject;
if (part instanceof go.Part) {
this._lastOK = this.adornedObject.getDocumentBounds();
let bnds = part.getDocumentBounds();
if (!bnds.isReal()) {
bnds = new go.Rect(this._lastOK.position, minSize);
} else {
bnds.addMargin(partPadding);
bnds.unionPoint(this.oppositePoint);
}
return new go.Size(
Math.max(minSize.width, bnds.width),
Math.max(minSize.height, bnds.height),
);
}
return minSize;
}
_checkIntersections(r) {
const results = this.diagram.findObjectsIn(
r,
(obj) => obj.part,
(p) => p,
true,
);
return results.count > 0;
}
computeResize(newPoint, spot, min, max, cell, reshape) {
const newRect = super.computeResize(newPoint, spot, min, max, cell, reshape);
const { part } = this.adornedObject;
if (part instanceof go.Part) {
const tl = this.adornedObject.getDocumentPoint(newRect.position);
const br = this.adornedObject.getDocumentPoint(new go.Point(newRect.right, newRect.bottom));
const rrect = new go.Rect(tl, br).inflate(1, 1);
if (this._checkIntersections(rrect)) {
return this._lastOK; // too big! use last safe bounds
}
this._lastOK = newRect.copy(); // remember for future use
}
return newRect;
}
resize(newr) {
const { part } = this.adornedObject;
if (part instanceof go.Part) {
const obj = this.adornedObject;
obj.desiredSize = newr.size;
part.ensureBounds();
const pt = this.adornedObject.getDocumentPoint(this.handle.alignment.opposite());
part.location = part.location.copy().subtract(pt).add(this.oppositePoint);
} else {
super.resize(newr);
}
}
}
I have updated some parts against group templates. @walter can help me identify issue within code. When trying to resize it’s not limiting overlapping while resize.