How to make link dynamic after set Spots for Individual Links?

Hi,

I’m following this code below:

diagram.nodeTemplate =
    $(go.Node, "Auto",
      $(go.Shape, "Rectangle", { fill: "lightgray" }),
      $(go.TextBlock,
        { margin: 5},
        new go.Binding("text", "key"))
    );

  diagram.linkTemplate =
    $(go.Link,
      // get the link spots from the link data
      new go.Binding("fromSpot", "fromSpot", go.Spot.parse),
      new go.Binding("toSpot", "toSpot", go.Spot.parse),
      $(go.Shape),
      $(go.Shape, { toArrow: "Standard" })
    );

  var nodeDataArray = [
    { key: "Alpha" }, { key: "Beta" }, { key: "Gamma" }, { key: "Delta" }
  ];
  var linkDataArray = [
    { from: "Alpha", to: "Beta", fromSpot: "TopRight", toSpot: "Left" },
    { from: "Alpha", to: "Gamma", fromSpot: "Left", toSpot: "Left" },
    { from: "Alpha", to: "Delta", fromSpot: "None", toSpot: "Top" }
  ];
  diagram.model = new go.GraphLinksModel(nodeDataArray, linkDataArray);

And by this way I calculated fromSpot and toSpot from beginning. But Issue here is: When i move node, the link not dynamic by location of nodes.
Is there anyway to make link dynamic in this case?

Sorry if the question not clear!

Thank you,

Under what circumstances would you want to change the link spot of connected links when a node is moved, and to what value?

It would help if you showed before-and-after screenshots.

I hope you have read all of GoJS Link Connection Points on Nodes -- Northwoods Software.

Hi Walter,
I’ve uploaded 3 images,
for pic1: when diagram loaded.( I’m set linkData is: {from: “Alpha”, to: “Delta”, fromSpot: “bottom”, toSpot: “Top”}
for pic2: when i move Alpha node to below Delta node.

And the question here is: When i move AlphaNode to below Delta node, how to make link like pic3( it be good if we can do that automatically)
pic1:

pic2:

pic3:

If you don’t set any Link.fromSpot or Link.toSpot at all, you will get that behavior.

I think it would benefit you if you read GoJS Link Connection Points on Nodes -- Northwoods Software.

Yes, I knew that.But in my diagram,
step1: I calculate location of each nodes
step2: I calculate Link.fromSpot and Link.toSpot links for avoids link crossing.

note: i don’t want use any layout of gojs because it is not matched with my scoping.

Well, you can either recompute and assign the desired link spots, or you can let it do its default routing behavior by setting the spots to go.Spot.None or go.Spot.Default.

Yes, i will try to recompute. But how to apply new link spots to diagram?
one more thing: Is posible to get all link from node? for example, i want get all link from the rightSide of node.

If you look at the Node class, Node | GoJS API, you will see one property and several methods that you can use. Node.linksConnected or Node.findLinksConnected() or Node.findLinksInto() or Node.findLinksOutOf().

For finding those that are connected on the right side, you’ll need to look at the Link.points to see how they are currently routed.

Thanks you, walter.