use example as Dynamic Ports
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.
myDiagram.model.nodeDataArray[0]
// {key: 1, name: "Unit One", loc: "101 204", leftArray: Array(1), topArray: Array(1), …}
let node = myDiagram.findNodeForKey(1)
let p = node.ports.first()
p.position
//H {x: NaN, y: NaN, s: true}
As you can see, the x and y of position is NAN
jhardy
January 24, 2020, 2:49pm
2
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
walter
January 24, 2020, 3:03pm
3
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 GoJS Coordinate Systems-- Northwoods Software .
That’s why you want to convert such coordinates of different Nodes into document coordinates: GoJS Coordinate Systems-- Northwoods Software
2 Likes