Get center of node.port

Because our legacy UI only stored link midpoints in the database we have to calculate the start and end points for links. This code works but but the link centers on the entire node instead of the port.

        midpoints = change.midpoints;
        if (midpoints.length > 0) {
            points = new go.List(go.Point);
            link = diagram.goDiagram.findLinkForData(e.model.findLinkDataForKey(change.key));
            node = diagram.goDiagram.findNodeForKey(change.from);
            points.add(link.getLinkPointFromPoint(node, node.port,, midpoints[0], true));
            Ext.each(midpoints, function(midpoint)  {
                points.add(new go.Point(midpoint.x, midpoint.y));
            }, me);
            node = diagram.goDiagram.findNodeForKey(;
            points.add(link.getLinkPointFromPoint(node, node.port,, midpoints[midpoints.length - 1], false));
            link.points = points;

Here is what it looks like.

This code above link.getLinkPointFromPoint(node, node.port,, midpoints[0], true) returns this toString “Point(180.09090825612827,119.99986226116681)”

Changing it to link.getLinkPointFromPoint(node, node.port,, midpoints[0], true) returns this toString “Point(NaN,NaN)”

Any idea on what I’m doing wrong or suggestions on how to get link to center of port instead of node?

When are you evaluating that code? Perhaps the nodes haven’t had the chance to measure and arrange their innards yet.

I suggest that you do this stuff in an “InitialLayoutCompleted” DiagramEvent listener.

This is on a modelChangedEvent with propertyName === ‘CommittedTransaction’. Is this too early?

EDIT: Added InitialLayoutCompleted listener and it fires before modelChangedEvent so looks like that won’t help. Any other ideas?

That should be OK.

Actually, the problem is that you are using the wrong coordinate system. GraphObject.actualBounds (and most of the other measures) are in the coordinate system of the containing Panel, or of the document if there is no such panel because it is a Part.

So if node !== node.port, the port’s actualBounds will be in the coordinate system of the panel, not document coordinates.

Instead you should be evaluating node.port.getDocumentPoint(go.Spot.Center).

You better debug this so that you can see what Point values are being returned with your code and with the call to GraphObject.getDocumentPoint.

That worked - thx.