Port and temporaryToPort not in same position when use margin, how to change it

  $(go.Panel, "Horizontal",
new go.Binding("itemArray", "topArray"),
{
    row: 0, column: 1,
    itemTemplate:
        $(go.Panel,
            {
                _side: "top",
                fromSpot: go.Spot.Top,
                toSpot: go.Spot.Top,
                fromLinkable: true,
                toLinkable: true,
                cursor: "crosshair",
                opacity: 0.0,
                // contextMenu: portMenu
            },
            new go.Binding("portId", "portId"),
            new go.Binding("name", "portId"),
            $(go.Shape, "Circle",
                {
                    fill: 'white',
                    stroke: colors.lightblue,
                    strokeWidth: 1,
                    desiredSize: portSize,
                    // margin: new go.Margin(0, 3)
                }
            )
        )  // end itemTemplate
}),  




function commonLinkingToolInit(tool) {
    // FROM
    tool.temporaryFromPort.figure = "Circle";
    tool.temporaryFromPort.fill = '#e9f8ff';
    tool.temporaryFromPort.stroke = "green";
    tool.temporaryFromPort.strokeWidth = 1;
    // tool.temporaryFromPort.desiredSize = portSize;
    ///// TO
    tool.temporaryToPort.figure = "Circle";
    tool.temporaryToPort.fill = '#e9f8ff';
    tool.temporaryFromPort.stroke = "green";
    tool.temporaryToPort.strokeWidth = 1;
    // tool.temporaryToPort.desiredSize = portSize;
}

commonLinkingToolInit(myDiagram.toolManager.linkingTool);
commonLinkingToolInit(myDiagram.toolManager.relinkingTool);

no margin
WX20200112-103254%402x

with margin, temporaryToPort position is wrong

I’m sorry, but there is not enough information to guess what is going on. The behavior you show does not follow from the code that you show.

Why do you set the temporaryFromPort.stroke twice?

it’s a mistike.

tool.temporaryToPort.figure = "Circle";
                    tool.temporaryToPort.fill = colors.green;
                    tool.temporaryToPort.stroke = null;
                    tool.temporaryToPort.strokeWidth = 0;
                    tool.temporaryToPort.desiredSize = new go.Size(20, 20); // change size
                    tool.temporaryToPort.minSize = new go.Size(20, 20);
                    tool.temporaryToPort.opacity = 0.35;