Dynamically change link visible property

Hi GoJS experts,

We would like to make a link change to invisible when fromPort and toPort is close to each other.

We could do that in our application by iterating over all the link and change the “visible” property.

But I am wondering could we config this in linkTempate so that GoJS take care of it.

Thanks

There are several ways to do that. I think you already have one solution.

Another solution is to define a subclass of Link and override Link.computePoints. Something like:

function UnseenShortLink() {
    go.Link.call(this);
}
go.Diagram.inherit(UnseenShortLink, go.Link);

UnseenShortLink.prototype.computePoints = function() {
    var result = go.Link.prototype.computePoints.call(this);
    if (result) {
        var first = this.getPoint(0);
        var last = this.getPoint(this.pointsCount-1);
        this.opacity = (first.distanceSquaredPoint(last) < 36) ? 0.0 : 1.0;
    }
    return result;
};

Use this class by replacing go.Link with UnseenShortLink in your Link template(s). Replace 36 with whatever value suits your needs.
Caution: I haven’t actually tried this code!

@walter it works! Thanks!