Color links based on attribule on node

I have nodes, that at a certain point I add a “dead”=true attribute to,
when I do that, I want to change the stroke color of all the link connected to it,
I have this for the link template:

$(go.Shape, { isPanelMain: true, strokeWidth: 2 },
new go.Binding(“stroke”, “fromNode”, function(n) { return n.data.dead ? “red” : “black”; }).ofObject(),
new go.Binding(“stroke”, “toNode”, function(n) { return n.data.dead ? “red” : “black”; }).ofObject(),
new go.Binding(“stroke”, “isHighlighted”, function (h) { return h ? “violet” : “black”; }).ofObject())

the highlight works perfectly, but when I add the dead attribute, nothing happens?
any ideas?

Yes, because you are not actually modifying any state on the link data, the Links do not know that they need to be updated.

I suppose you could do something like:

  myDiagram.links.each(function(l) { l.updateTargetBindings(); })

as part of the transaction where you are modifying the node data.

this works great, thanks
now the remaining question is: how do I make multiple binding on stroke work?
individually all of them work, but together, only the last one works.

there is probably something wrong with my syntax?

You first need to decide what you want. What color do you want the link to be when link.toNode.data.dead && link.isHighlighted? What you have written is basically a logical OR, and when more than one expression is true, the last one wins, although the order of evaluation is not guaranteed.

You can pass the empty string as the source property name in order to indicate that the Binding depends on more than one property of the source object, the Link in this case. The disadvantage is that the Binding will be evaluated whenever any source object property changes, which may be inefficient.

Hey

What I want is to have the link in one color when highlighted, and all the links in and out red when the node is dead.