LinkingTool & findLinkablePort()

Hi,

We decide to update gojs from 1.6.22 to 1.7.2 and the we receive this error:
“Property ‘findLinkablePort’ is protected and only accessible within class ‘LinkingTool’ and its subclasses.”

With the new version, how can I get the “from node” when the event “linkingTool.canStart” is triggered??

Now, I get this information in this way:

private _diagram: go.Diagram;

ngAfterViewInit(): void {
let $ = go.GraphObject.make;
this._diagram = new go.Diagram(this.getContainer().nativeElement);
this._diagram.toolManager.linkingTool.canStart = this.linkingToolCanStart.bind(this);

}

linkingToolCanStart(): boolean {
    let linkingTool = this._diagram.toolManager.linkingTool;
    if (linkingTool.findLinkablePort() && linkingTool.findLinkablePort().part) {
        let fromNode = linkingTool.findLinkablePort().part.data;
        return this.canLinkFromThisNode(fromNode);
    }
    return false;
}

Thank you

I think that I’m not really clear…
I need to get the data of the from node to be able to make the desired validation.

Don’t you just want to override LinkingTool.findLinkablePort to return null if the particular GraphObject does not meet your criteria? In that case it makes sense that findLinkablePort is declared protected.

Hi,

I’m searching the best way to get the data of the “from node” when I’m starting a link.
With the version 1.6.22, it works well, but with the new version, I want to know how to get this information? The code above was mine with the version 1.6.22.

Do I have to use the linkingTool? If not, can you tell me how to get the node?

The function "this.canLinkFromThisNode(fromNode);" has the rules if the node can be linked.

Thank you

First, I hope it’s clear that we couldn’t specify protected until TypeScript version 1.3 came out, although in retrospect we should have added access modifiers before, after requiring other newer features of TypeScript in the go.d.ts file.

So the situation you are talking about is when the user starts interactively drawing a new Link via the LinkingTool, yes? If you are talking about other ways to draw a new link, you would not be using the LinkingTool.

What I was recommending is something like:

  class CustomLinkingTool extends go.LinkingTool  {
    findLinkablePort(): go.GraphObject {
      let result = super();
      if (result !== null && !canLinkFromThisNode(result.part)) return null;
      return result;
    }
  }

and then when initializing the Diagram:

    $(go.Diagram, . . .,
      { . . .,
        linkingTool: new CustomLinkingTool()
      })