Need help to remove Vertex from link shape

I’m a bit struck trying to remove a Vertex, or link segment. I have captured the contextMenu event from the linkReshapingTool.handleArchetype:

myDiagram.toolManager.linkReshapingTool.isEnabled = true;<br />myDiagram.toolManager.linkReshapingTool.handleArchetype = $gojs(go.Shape, "Square", { width: 12, height: 12, fill: "cyan", isActionable: true, contextClick: showEdgeShaperContext });<br />
So I have a function removeVertex(vertex) {} where vertex is the Shape object for the handleArchtype. But I can’t figure out how to grab the Link and then remove the correct segment…

-Clive

The contextClick event handler takes two arguments: an InputEvent (“e”) and the GraphObject (“obj”) that has this event handler defined. You didn’t say how you defined your showEdgeShaperContext event handler, but given the second argument, the “obj.part” will be the Link.

You can then use link.findClosestSegment(e.documentPoint) to figure out which segment that particular handle is at. Removing the Point is just a matter of copying the Link.points List, modifying it, and setting it back. Something like:

function removePointFromLink(e, obj) { var link = obj.part; var diagram = link.diagram; var idx = link.findClosestSegment(e.documentPoint); var pts = link.points.copy(); if (idx > 0 && idx < pts.count - 1) { pts.removeAt(idx); diagram.startTransaction("remove Point"); link.points = pts; diagram.commitTransaction("remove Point"); } }
Caution: I haven’t actually tried this yet.

I see.
Yep this approach kinda works.
But whenever a connected Node is moved, the link segments get reset. It would be good if the Link Shape remained while the Node is moving and only the Last Segment changed. Ie, If it just change the closest segment to the Node while the node is moving.

But we’re actually just gonna let GoJS library do the link shapes automatically, and have realized the wisdom of this approach. Much easier.

-Clive

You could try setting Link.adjusting = go.Link.End, or maybe one of the other non-None values.