Error incorporating dynamic ports error

EDIT: found the problem, the model needs to know the linkTo- and linkFromPortIdProperty names to compute the points. When i added these two lines after the graphlinksmodel declaration, it works:

diagram.model = new go.GraphLinksModel(nodes, links);
diagram.model.linkFromPortIdProperty = 'fromPort'; //this line
diagram.model.linkToPortIdProperty = 'toPort'; //and this line

Hi,

I’m trying to upgrade our functionality with the option to set the a port on a link, so you can decide from which side to which side on a node the link goes. I looked at the ‘Dynamic Ports’ example and copied most of the code. However when i run it i get an error:

Uncaught Error: getDocumentPoint:s Spot must be real: None

 CustomLink.prototype.computeCurviness = function() {
        if (isNaN(this.curviness)) {
          var fromnode = this.fromNode;
          var fromport = this.fromPort;
          var fromspot = this.computeSpot(true);
          var frompt = fromport.getDocumentPoint(fromspot); //this is where the error is thrown if i draw a link
          var tonode = this.toNode;
          ...
 }

CustomLink.prototype.computeEndSegmentLength = function(node, port, spot, from) {
    var esl = go.Link.prototype.computeEndSegmentLength.call(this, node, port, spot, from);
    var thispt = port.getDocumentPoint(this.computeSpot(from)); //this is where the error is thrown if i load a link from a json
    var otherpt = this.getOtherPort(port).getDocumentPoint(this.computeSpot(!from));
    ...
}

I used the node- and linktemplate from the example and copied the overrides for the customlink

the order of process in my code is as follows:

  • set the customlink function and overrides
  • get diagram template
  • add nodetemplatemap to diagram,
  • add linktemplatemap to diagram

Any idea why i get the error? It happens either when i load a json with specified links, or when i try to add a link manually

I’m glad you figured it out. If there’s any particular spot in the documentation where that information would have helped you, please tell us.

Hi Walter,

Since i used the code from the example i didn’t really searched the api. The example is pretty clear, but i overlooked the data in the json that sets the fromportids on the model. It would have been clearer if those properties would have been set in the code example.

Tim

Walter, i have a follow up question.

When the user relinks a link, i want to programmatically set to which ports it can relink. How can i find out which link is being relinked. I tried overriding the reconnectlink, but that only fires after the action. I also tried overriding the doActivate function, but i couldn’t get to the handle.

Hope you can help,
Tim

http://gojs.net/latest/intro/validation.html
tells you how to limit both drawing new links and reconnecting existing links.

Hi Walter,

Thanks for your reply, but i don’t think this covers the functionality i desire;

I have nodes which have ports on their sides (like in the example). An user must be able to reconnect a link to another port on the node (and in a later stage to other nodes that match validation). So my idea was to override the event that starts the relink action, and then programmatically set the linkableTo and From properties. I also want to display a new port when relinking, so an user can connect the link to the new port. So i was hoping for a way to find out which link is the subject when i activate the relinkingtool. i tried overriding the doActivate function but i couldn’t get to a handle/subject or something similar.

Tim

The LinkingBaseTool.linkValidation and Node.linkValidation predicate properties should cover everything that you might want to do. I don’t think you want to dynamically set the linkableTo and linkableFrom properties.

If your desired behavior isn’t handled by either of these customizations, please explain.

Hi Walter,

you’re right, the validation tools did handle everything i needed.

Thanks