Is it possible to add segment to the link? I want to click on the link to add segments from the spot…
Yes, set Link.resegmentable to true. For a discussion, see GoJS Tools -- Northwoods Software.
For an example, see Orthogonal Link Reshaping Tool.
I want to add segment to where I click on link segment. How can I do?
So using Link.resegmentable isn’t what you want. You could certainly implement something different, but it would be work to customize the LinkReshapingTool so that the resegmenting handle was where the user clicked rather than in the middle of the segment.
Or are you asking for some other difference in behavior?
Thank your answering. I know this tool. Can you send me an example about it?
All of the handles shown by the LinkReshapingTool are determined when the Link is selected, not necessarily when the user clicks on the Link. So I assume you understand that if the user didn’t click on a Link, it will get the standard reshaping handles as determined by the implementation of LinkReshapingTool.updateAdornments.
Or if the Link was already selected before the user clicks on the Link, you’ll need to call LinkReshapingTool.updateAdornments again to adjust a resegmenting handle to be near where the user clicked.
I don’t have time now to implement this. Basically what I would do is override LinkReshapingTool.updateAdornments to call the super method and then look to see if the last mouse point is near one of the segments of the link route by calling Link.findClosestSegment.
If the point is “close enough” to the returned link segment, then see if there’s already a resegmenting handle on that segment. It will have GraphObject.segmentIndex equal to the returned link segment index, and it will be a resegmenting handle if GraphObject.fromMaxLinks is 999. (That 999 value is an undocumented expediency to distinguish the kinds of handles.)
If there is such a handle, move it to be closest to the mouse point by changing its GraphObject.segmentFraction. By default this is always 0.5 – at the mid point of the segment.
We’ll see if we can come up with something close to what you’re looking for.
absolutely. Thank you
Just wanted to let you know we are still looking at this. It will probably require us to expose a new function on the LinkReshapingTool, so it will probably be ready with the next release.
Thank you Waiting Impatiently. when will the new version be released?
Probably some time next week.
Apologies for the delay, we had some other bugs we were also working on fixing.
GoJS 1.8.22 has been released, and includes the undocumented function LinkReshapingTool.getResegmentingPoint. This can be used so that when a resegmenting handle is clicked to start the tool, the user can control where the new link point gets added instead of always forcing it to be the middle of the segment.
An example usage is this custom LinkReshapingTool, which uses that function and resegmenting handles that cover whole segments:
// A custom LinkReshapingTool that places a resegment handle where the user clicks on the link
/**
* @constructor
* @extends LinkReshapingTool
* @class
* This ResegmentingLinkReshapingTool class allows for a Link's path to be modified by the user
* via the creating a resegmenting handle where the user clicks.
*/
function ResegmentingLinkReshapingTool() {
go.LinkReshapingTool.call(this);
}
go.Diagram.inherit(ResegmentingLinkReshapingTool, go.LinkReshapingTool);
/**
* @override
* Make the resegment handles into shapes that cover an entire link segment.
* @this {ResegmentingLinkReshapingTool}
* @param {Shape} pathshape
* @param {number} i
* @return {GraphObject}
*/
ResegmentingLinkReshapingTool.prototype.makeResegmentHandle = function(pathshape, i) {
var link = pathshape.part;
var a = link.getPoint(i);
var b = link.getPoint(i + 1);
var h = new go.Shape();
var geo = new go.Geometry()
.add(new go.PathFigure(a.x, a.y)
.add(new go.PathSegment(go.PathSegment.Line, b.x, b.y)));
h.position = geo.normalize();
h.geometry = geo;
h.stroke = 'orange';
h.strokeWidth = 3;
return h;
}
/**
* @override
* Remove the existing adornment so we can be sure the resegment handles get updated properly.
* @this {ResegmentingLinkReshapingTool}
* @param {Part} part
*/
ResegmentingLinkReshapingTool.prototype.updateAdornments = function(part) {
if (part === null || !(part instanceof go.Link)) return; // this tool only applies to Links
part.removeAdornment(this.name);
go.LinkReshapingTool.prototype.updateAdornments.call(this, part);
}; // end updateAdornments
/**
* @override
* When resegmenting, start from the clicked point on the link instead of the center of the resegment handle.
* @this {ResegmentingLinkReshapingTool}
* @return {Point} the point where resegmenting begins
*/
ResegmentingLinkReshapingTool.prototype.getResegmentingPoint = function() {
return this.diagram.firstInput.documentPoint;
};
The tool isn’t really designed for use with orthogonal links, so if you want that, you’ll need to make some customizations.
To prevent the link from being recalculated when moving a node, try setting Link.adjusting to End, Scale or Stretch.