Is there any way to get position of a port

use example as

I want to get the shortest distance of two ports. but the position of port is NAN.

click the example link href and open chrome console.

// {key: 1, name: "Unit One", loc: "101 204", leftArray: Array(1), topArray: Array(1), …}
let node = myDiagram.findNodeForKey(1)
let p = node.ports.first()
//H {x: NaN, y: NaN, s: true}

As you can see, the x and y of position is NAN

You could use GraphObject.getDocumentPoint. Note, the reason your call to getLocalPoint produced an error is that you didn’t provide the necessary first argument.

const portPoint = p.getDocumentPoint(go.Spot.Center);
1 Like

To explain further, part of the problem is that GraphObject.position, GraphObject.desiredSize and other such properties have coordinates in the containing Panel’s coordinate system. Read more about this at

That’s why you want to convert such coordinates of different Nodes into document coordinates: