Link aware of its nodes

Well what is the best way that link could know if its reshaping caused by change of position of fromNode or toNode? I need such information inside of my custom Link.computePoints method.

Thanks

Unless you are dynamically changing the values of fromSpot or toSpot or the various Link and GraphObject properties that affect standard link routing, it’s only the connected nodes/ports changing bounds that invalidate an existing link’s route.

In general there is no distinction made for any particular reason why a link’s route was invalidated.

Perhaps if you could precisely describe the circumstances in which you want to have different-than-normal behavior for Link.computePoints, I could give you better suggestions.

Well I was decided that for my purposes I want that user decide what geometry link would have. There is one situation when fromPoint of link is not on standard location and I want to avoid that link change that point to standard one when toPoint is changed because I changed toNode’s position. To prevent that one way is to know what part of link dependencies is caused this change and if I know that I can prevent calculation - change of fromPoint in such situation or vice versa.
For defining a link route after initial link creation I’m using a LinkShiftTool class. Mine BPMN.Link class looks like:

/**

  • Created by miroslav on 1/12/17.
    /
    /
    *
  • @constructor
  • @extends Link
  • @class
    */
    function BPMNLink() {
    go.Link.call(this);
    this.originalPoints = null;
    this.initialized = false;
    this.shifting = false;
    }
    go.Diagram.inherit(BPMNLink, go.Link);

// previously discussed, stop self-links from being orthogonal or bezier:
BPMNLink.prototype.computeCurve = function () {
return go.Link.None;
};

BPMNLink.prototype.makeGeometry = function () {
//console.log(this.pointsCount);
//console.log(this.points.toArray());
// check if number of points changed and try to remove from originlpoints too
console.log(this.points.toArray());
if (this.originalPoints === null || this.pointsCount > 2)
this.originalPoints = this.points;
return go.Link.prototype.makeGeometry.call(this);
};

// general routing computation
BPMNLink.prototype.computePoints = function () {
let fromport = this.fromPort;
let toport = this.toPort;
let num = this.originalPoints ? this.originalPoints.length : this.pointsCount;
//let previousPoints = this.points;
let ortho = false;
let fromnode = this.fromNode;
let fromspot = this.computeSpot(true);
let tonode = this.toNode;
let tospot = this.computeSpot(false);

let fromDir = this.getLinkDirection(fromnode, fromport, fromPoint, fromspot, true, ortho, tonode, toport);
let toDir = this.getLinkDirection(tonode, toport, toPoint, tospot, false, ortho, fromnode, fromport);
if (this.originalPoints && !this.initialized) {
    let nodeCentralPoint = BPMN.getPartCentralPoint2(fromnode);
    let dir = nodeCentralPoint.directionPoint(this.originalPoints.get(0));
    //console.log(`from dir: ${dir}`);
    if (dir >= 290 || dir <= 70) {
        this.fromSpot = new go.Spot(1, 0.5);
        fromDir = 0;
    } else if (dir < 290 && dir > 250) {
        this.fromSpot = new go.Spot(0.5, 0);
        fromDir = 270;
    } else if (dir <= 250 && dir >= 110) {
        this.fromSpot = new go.Spot(0, 0.5);
        fromDir = 180;
    } else {
        this.fromSpot = new go.Spot(0.5, 1);
        fromDir = 90;
    }
    //console.log(`from spot: ${this.fromSpot}`);
}
if (this.originalPoints && !this.initialized) {
    let nodeCentralPoint = BPMN.getPartCentralPoint2(tonode);
    let dir = nodeCentralPoint.directionPoint(this.originalPoints.get(num - 1));
    //console.log(`to dir: ${dir}`);
    if (dir > 290 || dir < 70) {
        this.toSpot = new go.Spot(1, 0.5);
        toDir = 0;
    } else if (dir < 290 && dir > 250) {
        this.toSpot = new go.Spot(0.5, 0);
        toDir = 270;
    } else if (dir <= 250 && dir >= 110) {
        this.toSpot = new go.Spot(0, 0.5);
        toDir = 180;
    } else {
        this.toSpot = new go.Spot(0.5, 1);
        toDir = 90;
    }
    //console.log(`to spot: ${this.toSpot}`);
}
console.log(num);
let fromPoint;
if (!this.initialized && this.originalPoints)
    fromPoint = this.originalPoints.get(0);
else if (this.shifting || !this.originalPoints)
    fromPoint = this.getLinkPoint(fromnode, fromport, fromspot, true, ortho, tonode, toport);
else if (this.originalPoints) {
    let point = this.getLinkPoint(fromnode, fromport, fromspot, true, ortho, tonode, toport);
    fromPoint = this.points.get(0);
    if (Math.abs(fromPoint.x - point.x) > 3 || Math.abs(fromPoint.y - point.y) > 3)
        fromPoint = point;
}
let fromSeg = this.computeEndSegmentLength(fromnode, fromport, fromspot, true);
let toPoint;
if (!this.initialized && this.originalPoints)
    toPoint = this.originalPoints.get(num - 1);
else if (this.shifting || !this.originalPoints)
    toPoint = this.getLinkPoint(tonode, toport, tospot, false, ortho, fromnode, fromport);
else if (this.originalPoints) {
    let point = this.getLinkPoint(tonode, toport, tospot, false, ortho, fromnode, fromport);
    toPoint = this.points.get(num - 1);
    if (Math.abs(toPoint.x - point.x) > 3 || Math.abs(toPoint.y - point.y) > 3)
        toPoint = point;
}
let toSeg = this.computeEndSegmentLength(tonode, toport, tospot, false);
//console.log(`from ${num}-${fromnode.data.key}-${fromPoint}-${fromDir}-${fromSeg}-${fromspot}-${fromport}`);
//console.log(`to ${tonode.data.key}-${toPoint}-${toDir}-${toSeg}-${tospot}-${toport}`);
this.clearPoints();
if (this.points.length === 0) { // when link is created
    if (this.originalPoints) {
        for (let p of this.originalPoints.toArray())
            this.addPoint(p);
        //console.log(this.originalPoints.toArray(), fromDir);
        this.setPoint(0, fromPoint);
        switch (fromDir) {
            case 90:
                this.setPoint(1, new go.Point(fromPoint.x, fromPoint.y + 10));
                break;
            case 180:
                this.setPoint(1, new go.Point(fromPoint.x - 10, fromPoint.y));
                break;
            case 270:
                this.setPoint(1, new go.Point(fromPoint.x, fromPoint.y - 10));
                break;
            default:
                this.setPoint(1, new go.Point(fromPoint.x + 10, fromPoint.y));
                break;
        }
        switch (toDir) {
            case 0: // right side
                this.setPoint(this.originalPoints.length - 2, new go.Point(toPoint.x + 10, toPoint.y));
                break;
            case 90: // bottom side
                this.setPoint(num - 2, new go.Point(toPoint.x, toPoint.y + 20));
                break;
            case 270: // top side
                this.setPoint(num - 2, new go.Point(toPoint.x, toPoint.y - 20));
                break;
            default: // left side 180
                this.setPoint(this.originalPoints.length - 2, new go.Point(toPoint.x - 10, toPoint.y));
                break;
        }
        this.setPoint(this.originalPoints.length - 1, toPoint);
        this.initialized = true;
    } else {
        this.insertPoint(0, fromPoint);
        this.insertPoint(1, new go.Point(fromPoint.x + 10, fromPoint.y));
        if (Math.abs(fromPoint.y - toPoint.y) > 5) {
            this.insertPoint(2, new go.Point(fromPoint.x + (toPoint.x - fromPoint.x) / 2, fromPoint.y));
            this.insertPoint(3, new go.Point(fromPoint.x + (toPoint.x - fromPoint.x) / 2, toPoint.y));
        }
        this.insertPoint(4, new go.Point(toPoint.x - 10, toPoint.y));
        this.insertPoint(5, toPoint);
    }
    //console.log(this.points.toArray());
}
return true;

};

Does the Link.adjusting property not help? Try setting it to go.Link.End.

No it does not. Just tried it but I got the same behavior of link when route is invalidated.

But when I rethink maybe there will be no need for that at all. Let leave this issue for now, and I will return to this topic if I find this issue bothers me again.