we implemented the LinkShiftingTool, it is working good But I need also a link was attached to the place where I placed it at first (when I draw it, not after drawing). with the following reference implemented the code below
https://forum.nwoods.com/t/linkshiftingtool-fromspot-tospot/10401
private SpotLinkingTool() {
return go.LinkingTool.call(this);
}
private SpotRelinkingTool() {
return go.RelinkingTool.call(this);
}
public initDiagram(): go.Diagram {
const that = this;
const $ = go.GraphObject.make;
this.dia = $(go.Diagram, {
"draggingTool.dragsLink": true,
"draggingTool.isGridSnapEnabled": true,
"linkingTool.isUnconnectedLinkValid": false,
"linkingTool.portGravity": 50,
"relinkingTool.isUnconnectedLinkValid": true,
"relinkingTool.portGravity": 50,
"relinkingTool.fromHandleArchetype":
$(go.Shape, "Diamond", { segmentIndex: 0, cursor: "pointer", desiredSize: new go.Size(8, 8), fill: "tomato", stroke: "darkred" }),
"relinkingTool.toHandleArchetype":
$(go.Shape, "Diamond", { segmentIndex: -1, cursor: "pointer", desiredSize: new go.Size(8, 8), fill: "darkred", stroke: "tomato" }),
"linkReshapingTool.handleArchetype":
$(go.Shape, "Diamond", { desiredSize: new go.Size(7, 7), fill: "lightblue", stroke: "deepskyblue" }),
"rotatingTool.handleAngle": 270,
"rotatingTool.handleDistance": 20,
"rotatingTool.snapAngleMultiple": 15,
"rotatingTool.snapAngleEpsilon": 15,
'undoManager.isEnabled': true,
linkingTool: $(this.SpotLinkingTool()),
relinkingTool: $(this.SpotRelinkingTool()),
allowDelete: true,
allowCopy: false,
model: $(go.GraphLinksModel,
{
copiesArrays: true,
copiesArrayObjects: true,
linkKeyProperty: 'key'
}
)
});
go.Diagram.inherit(this.SpotLinkingTool(), go.LinkingTool);
this.SpotLinkingTool().prototype.insertLink = ((fromnode, fromport, tonode, toport) => {
var link = go.LinkingTool.prototype.insertLink.call(this, fromnode, fromport, tonode, toport);
if (link !== null) {
var port;
if (link.isForwards) {
port = toport;
} else {
port = fromport;
}
var portb = new go.Rect(port.getDocumentPoint(go.Spot.TopLeft),
port.getDocumentPoint(go.Spot.BottomRight));
var lp = link.getLinkPointFromPoint(port.part, port, port.getDocumentPoint(go.Spot.Center),
this.dia.lastInput.documentPoint, !link.isForwards);
var spot = new go.Spot((lp.x - portb.x) / (portb.width || 1), (lp.y - portb.y) / (portb.height || 1));
if (link.isForwards) {
link.toSpot = spot;
} else {
link.fromSpot = spot;
}
}
return link;
})
go.Diagram.inherit(this.SpotRelinkingTool(), go.RelinkingTool);
this.SpotRelinkingTool().prototype.reconnectLink = ((link, newnode, newport, toend) => {
go.RelinkingTool.prototype.reconnectLink.call(this, link, newnode, newport, toend);
if (link !== null) {
var port = newport;
var portb = new go.Rect(port.getDocumentPoint(go.Spot.TopLeft),
port.getDocumentPoint(go.Spot.BottomRight));
var lp = link.getLinkPointFromPoint(port.part, port, port.getDocumentPoint(go.Spot.Center),
this.dia.lastInput.documentPoint, !toend);
var spot = new go.Spot((lp.x - portb.x) / (portb.width || 1), (lp.y - portb.y) / (portb.height || 1));
if (toend) {
link.toSpot = spot;
} else {
link.fromSpot = spot;
}
}
return link;
})
this is in typescript, getting issue here, i tried with created the global var for spotLiningTool and SpotRelinkingTool also
linkingTool: $(this.SpotLinkingTool()),
relinkingTool: $(this.SpotRelinkingTool())
- need to allow the user only one link between nodes is it possible to do like that?