Dynamic Link templates based on the data of the Node object

Hi, I have an array of objects for the node, each node object has a linkType key. If link type is A I want the linkTemplate for that particular node to be A. If the link type is B I want the linkTemplate to be B for that particular node. I am able to achieve this with if and else in condition but the problem is whichever template us loaded latest. That template is used for each node. How can I control this?

Could you please show a small screenshot of what you want, and describe how you have set up your node and link templates? (Please skip the unimportant details inside the templates.) I don’t understand what you are talking about with respect to the order in which templates are defined.

Below are the two types of Links. I want to draw the link based the link type mention in the node object

One with wait icon

Another link without wait icon

This is my code

const waitLink= GJS(go.Link, 
        GJS(go.Shape, {fill: 'red' , stroke: 'red', strokeWidth: 2}),
        GJS(go.Shape, { toArrow: 'Triangle' , fill: 'red' , stroke: 'red'})));

const onlyLink = GJS(go.Link, 
        GJS(go.Shape, {fill: 'blue' , stroke: 'blue', strokeWidth: 2}),
        GJS(go.Shape, { toArrow: 'Triangle' , fill: 'blue' , stroke: 'blue'})));

  let linkTempMap = new go.Map();
        diagram.linkTemplateMap = linkTempMap;

And on NodeTemplate I have binded the data like this

diagram.nodeTemplate = GJS(go.Node, 'Spot', new go.Binding('category','linkType'));

Am I missing out something? To make the code short I have just changed the color of the links instead of picture.

I do not think you need to use different templates at all. Certainly not for nodes, and not for links either. Just have a Binding on the Shape.stroke or Picture.visible property where the source is the Link and the source property is “fromNode” and you use a conversion function to look at the Link.fromNode’s data.

An example is the link template used in this example: GoJS Validation -- Northwoods Software. You can ignore the stuff about link validation, although if you do not already know about validation, you might be interested in that topic for your app anyway.

Note that if the node data’s properties are changing values dynamically, only the Bindings on that Node are evaluated automatically. The Bindings on other Parts are not evaluated automatically. You’ll have to update them programmatically.

Thanks @walter it was great help!, Yes you are right I only set the
Picture.visible to true or false.
I am not using linking validation, But the explanation helped me to understand how to use it according to my needs.