Example of go.Link.computePoints over-ride

Is there on in samples. I am over-riding but things aren’t working as expected. What I am trying to do is allow the link to acquire inital points collection from default and then over-ride compute points and immediately call it for a tweak. Perhaps there is something I need to do to have the change displayed?

This may be difficult to understand. NOTE: “$” is this example is jQuery and NOT GOJS. What I am trying to do is have all links headed to the same node make their x-crossover at the same y-point on the screen.

link.computePoints=$.proxy(function(link,arrayOfLinks){
link.startRoute();
link.xMove=null;
var trendSetter;
$.each(arrayOfLinks, $.proxy(function (index, link) {
link.xMove=null;
this.findXMoveForLink(link);
if (!trendSetter || link.xMove.altitude > trendSetter.xMove.altitude) {
trendSetter = link;
}
}, this));

        $.each(link.xMove.points, $.proxy(function (index, point) {
            var newPoint = new go.Point(point.x,trendSetter.xMove.altitude);
            var pointIndex = link.points.toArray().indexOf(point);
            if(pointIndex!=-1){
                link.setPoint(pointIndex,newPoint);
            }
            
            
        }, this));
        return true;

    },this,link,arrayOfLinks);

I’m not sure exactly what you’re trying to do, but I think it is much easier to override a Link method so that you don’t have to spend so much effort to try to fix the route.

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

  CustomLink.prototype.computeMidOrthoPosition = function(fromPosition, toPosition, vertical) {
    return fromPosition + 10;
  };

And use in your Link template(s):

    myDiagram.linkTemplate =
      $(CustomLink,
        { routing: go.Link.Orthogonal },
        $(go.Shape, { strokeWidth: 1.5 }) // the link shape, with the default black stroke
      );

thank you very much!

I am very close with the computePoints over-ride. As long as I don’t need any additional points than created by the inherited “createPoints”, everything works perfectly. ComputePoints is called multiple times. The first time it is called I pass it to the inherited method which I held a reference to before I did the override. The code in my computePoints is:

if(!this.passedToInherited){
this.passedToInherited=true;
return inheritedComputePoints.call(this);
}

else… do it myself

As I said, I can move preexisting points as much as I want. I can remove points, but as soon as I try to add a point like this:

    var newPoint = new go.Point(newCoords);
    this.addPoint(newPoint);

I get:

I have tried calling this.startRoute before I work with the points. It didn’t seem to help.

Thanks for your patience.

I can only guess. Maybe you should check that the return value from the base method call returned true.

What’s inheritedComputePoints? What’s newCoords?

Certainly it’s commonplace to call Link.addPoint or Link.addPointAt within overrides of Link.computePoints.

Thanks. I was sending the wrong info to the point constructor. It works now. Thank you for all your help.