How to change ports color of two nodes as soon a link get connected between them?

Hi all.
I need to change the color of two ports which are endpoints of a link connected between two different nodes in Dynamic Ports Sample. My mean is that two endpoints ports color get changed as soon a link connected between them.
I applied a custom color on model.setDataProperty of portcolor in computeEndSegmentLength
event function as follow. But the problem is that after connecting two ports by a link, i need to select the nodes and change their position to changing portcolor get effect.

CustomLink.prototype.computeEndSegmentLength = function(node,port,spot,from) { var other = this.getOtherPort(port); . . . myDiagram.model.startTransaction("colorPort"); var color = "rgb(0,255,0)"; // get Green myDiagram.model.setDataProperty(other.data,"portColor",go.Brush.darken(color)); myDiagram.model.commitTransaction("colorPort"); . . . }

I appreciate any hint.
Thank you.

No, you do not want to be modifying any nodes while calculating the route of a link. Remove that override and instead put your functionality in the Node | GoJS API and Node | GoJS API event handlers.

So thank you walter. It worked greatly. I have another question. I tried to use addDiagramListener event as follow. It fires when links get connected, but i don’t know how get the related ports to change their color. How can solve the problem by

myDiagram.addDiagramListener("LinkDrawn",function(e){ //How get the related port? });

Thanks

You can access the ports via e.subject.fromPort and e.subject.toPort. You’ll probably want to call setDataProperty on the port.data and change the “portColor” property.

Thank you again for your help.