Below is the code related to node creation and adding ports during node creation
`protected createActivityNodeTemplate():any{
let _this:any=this;
let activityNodeTemplate:any =
goObj(go.Node, “Spot”,_this.nodeStyle(_this),
{
locationObjectName: “SHAPE”, locationSpot: go.Spot.Center,
resizable: true, resizeObjectName: “PANEL”,
selectionAdorned: false, // use a Binding on the Shape.stroke to show selection
contextMenu: _this.activityNodeMenu,
itemTemplate: _this.boundaryEventItemTemplate
},
new go.Binding(“itemArray”, “boundaryEventArray”),
new go.Binding(“location”, “loc”, go.Point.parse).makeTwoWay(go.Point.stringify),
// move a selected part into the Foreground layer, so it isn"t obscured by any non-selected parts
new go.Binding(“layerName”, “isSelected”, function(s:any) { return s ? “Foreground” : “”; }).ofObject(),
goObj(go.Panel, “Auto”,
{
name: “PANEL”,
minSize: new go.Size(_this.ActivityNodeWidth, _this.ActivityNodeHeight),
desiredSize: new go.Size(_this.ActivityNodeWidth, _this.ActivityNodeHeight)
},
new go.Binding(“desiredSize”, “size”, go.Size.parse).makeTwoWay(go.Size.stringify),
goObj(go.Panel, “Spot”,
goObj(go.Shape, “RoundedRectangle”, // the outside rounded rectangle
{
name: “SHAPE”,
fill: _this.ActivityNodeFill, stroke: _this.ActivityNodeStroke,
parameter1: 10 // corner size
},
new go.Binding(“fill”, “color”),
new go.Binding(“strokeWidth”, “isCall”,
function(s:any)
{
return s ? _this.ActivityNodeStrokeWidthIsCall : _this.ActivityNodeStrokeWidth;
}
)
),
// task icon
goObj(go.Shape, “BpmnTaskScript”, // will be None, Script, Manual, Service, etc via converter
{
alignment: new go.Spot(0, 0, 5, 5), alignmentFocus: go.Spot.TopLeft,
width: 22, height: 22
},
new go.Binding(“fill”, “taskType”, _this.nodeActivityTaskTypeColorConverter),
new go.Binding(“figure”, “taskType”, _this.nodeActivityTaskTypeConverter)
), // end Task Icon
_this.makeMarkerPanel(false, 1,_this) // sub-process, loop, parallel, sequential, ad doc and compensation markers
), // end main body rectangles spot panel
goObj(go.TextBlock, // the center text
{
alignment: go.Spot.Center, textAlign: “center”, margin: 12,
editable: true,
font:_this.defaultFont
},
new go.Binding(“text”).makeTwoWay()
)
), // end Auto Panel
_this.makePort(“T”, go.Spot.Top, true, true),
_this.makePort(“L”, go.Spot.Left, false, true),
_this.makePort(“R”, go.Spot.Right, true, false),
_this.makePort(“B”, go.Spot.Bottom, true, true)
); // end go.Node, which is a Spot Panel with bound itemArray
return activityNodeTemplate;
}
Below is the Item Template that adds a port on custom right click menu action
`protected createBoundaryEventItemTemplate():any{
let _this:any=this;
let boundaryEventItemTemplate:any =
goObj(go.Panel, “Spot”,
{
contextMenu: _this.boundaryEventMenu,
alignmentFocus: go.Spot.Center,
fromLinkable: true, toLinkable: false,
cursor: “pointer”, fromSpot: go.Spot.Bottom,
fromMaxLinks: 1, toMaxLinks: 0
},
new go.Binding(“portId”, “portId”),
new go.Binding(“alignment”, “alignmentIndex”, ((s:any)=>_this.nodeActivityBESpotConverter(s))),
goObj(go.Shape, “Circle”,
{
margin:2,desiredSize: new go.Size(_this.EventNodeSize0.5, _this.EventNodeSize0.5)
},
new go.Binding(“strokeDashArray”, “eventDimension”, function(s:any){ return (s === 6) ? [4, 2] : null;}),
new go.Binding(“stroke”, “stroke”),
new go.Binding(“fromSpot”, “alignmentIndex”,
function(s:any) {
// nodeActivityBEFromSpotConverter, 0 & 1 go on bottom, all others on top of activity
if (s < 2)
return go.Spot.Bottom;
return go.Spot.Top;
}
),
new go.Binding(“fill”, “color”)
),
goObj(go.Shape, “Circle”,
{
alignment: go.Spot.Center,
desiredSize: new go.Size(_this.EventNodeInnerSize0.5, _this.EventNodeInnerSize0.5), fill: null
},
new go.Binding(“strokeDashArray”, “eventDimension”, function(s:any){ return (s === 6) ? [4, 2] : null; })
),
goObj(go.Shape, “NotAllowed”,
{
alignment: go.Spot.Center,
desiredSize: new go.Size(_this.EventNodeSymbolSize0.5, _this.EventNodeSymbolSize0.5), fill: “white”
},
new go.Binding(“figure”, “eventType”, _this.nodeEventTypeConverter)
)
);
return boundaryEventItemTemplate;
}``
When I inspected diagram data found that ports added during node creation are not added to “itemArray” and are only shown as node.ports iterator. I am not able to figure out a way to not to remove these ports on right click menu action which initializes the “itemArray” data(old ports are removed during this time) if it is null and add new port to “itemArray” data
Note: During node creation I need to add the ports because I am showing the ports on mouse hover of 4 sides of the node