Hello,
I am trying to add a context menu to groups with options like “add port on left”, “add a port on right”, etc. which adds the port to the respective side of the group boundary.
Here is my group template,
myDiagram.groupTemplate =
$(go.Group, "Auto",
{
selectionObjectName: "PANEL", // selection handle goes around shape, not label
ungroupable: true, // enable Ctrl-Shift-G to ungroup a selected Group
mouseDragEnter: (e, grp, prev) => highlightGroup(e, grp, true),
mouseDragLeave: (e, grp, next) => highlightGroup(e, grp, false),
computesBoundsAfterDrag: true,
mouseDrop: finishDrop,
handlesDragDropForMembers: true,
},
$(go.Shape, "RoundedRectangle",
{
fill: "rgba(128,128,128,0.2)",
strokeWidth: 3,
stroke: "gray",
strokeWidth: 3,
portId: "", cursor: "pointer", // the Shape is the port, not the whole Node
// allow all kinds of links from and to this port
fromLinkable: true, fromLinkableSelfNode: false, fromLinkableDuplicates: false,
toLinkable: true, toLinkableSelfNode: false, toLinkableDuplicates: false
},
// new go.Binding("stroke", "color"),
// new go.Binding("fill", "color", go.Brush.lighten)
),
$(go.TextBlock,
{
alignment: go.Spot.Top,
font: "bold 19px sans-serif",
margin: new go.Margin(4, 10, 0, 20),
isMultiline: false, // don't allow newlines in text
editable: true // allow in-place editing by user
},
new go.Binding("text", "text").makeTwoWay(),
new go.Binding("stroke", "color")
),
$(go.Placeholder, { alignment: go.Spot.TopLeft, padding: 50 }),
$("SubGraphExpanderButton", { alignment: go.Spot.TopLeft }),
{
minSize: new go.Size(50, 50),
subGraphExpandedChanged: function (grp) {
if (!grp.isSubGraphExpanded) return;
shiftNodes(grp);
},
selectionChanged: function (grp) {
grp.diagram.commit(function (diag) {
var lay = grp.isSelected ? "Foreground" : "";
grp.layerName = lay;
grp.findSubGraphParts().each(function (x) { x.layerName = lay; });
}, null);
},
toolTip:
$("ToolTip",
$(go.TextBlock, { margin: 14 },
// bind to tooltip, not to Group.data, to allow access to Group properties
new go.Binding("text", "", groupInfo).ofObject())
),
// the same context menu Adornment is shared by all groups
contextMenu: partContextMenu
}
);
Any help/suggestions are appreciated. Thanks in advance.