Hi,
We haven’t customised the linkingtool. Our node template is kind of a collection.
Providing below how we have defined our node template and link templates.
Node
var templmap = new go.Map();
var texttemplate = $(go.Node, "Auto", {
locationSpot: go.Spot.TopCenter,
isShadowed: false,
selectable: true,
resizable: true,
desiredSize: new go.Size(120, 30),
layerName: "Background",
avoidable: false,
selectionAdorned: false,
rotatable: false
}, new go.Binding("desiredSize", "size", go.Size.parse).makeTwoWay(go.Size.stringify), new go.Binding("location", "loc", go.Point.parse).makeTwoWay(go.Point.stringify), new go.Binding("angle", "angle").makeTwoWay(), $(go.Panel, "Vertical", {
alignment: go.Spot.Center,
alignmentFocus: go.Spot.Center,
}, $(go.TextBlock, {
margin: 10,
editable: true,
font: '10pt sans-serif'
}, new go.Binding("text").makeTwoWay())));
var diamondtemplate = $(go.Node, "Auto", {
locationSpot: go.Spot.TopCenter,
isShadowed: false,
selectable: true,
resizable: true,
desiredSize: new go.Size(100, 100),
layerName: "Background",
avoidable: false,
selectionAdorned: false
}, new go.Binding("desiredSize", "size", go.Size.parse).makeTwoWay(go.Size.stringify), new go.Binding("location", "loc", go.Point.parse).makeTwoWay(go.Point.stringify), $(go.Shape, "Diamond", roundedBackgroundRectangleParams, {
name: "SHAPE",
fill: strokewhite,
strokeWidth: 1,
stroke: '#a6a6a6',
fromLinkable: false,
fromLinkableSelfNode: false,
fromLinkableDuplicates: false,
toLinkable: false,
toLinkableSelfNode: false,
toLinkableDuplicates: false,
}), $(go.Panel, "Vertical", {
alignment: go.Spot.Center,
alignmentFocus: go.Spot.Center,
}, $(go.TextBlock, {
margin: 10,
editable: true,
font: '10pt sans-serif'
}, new go.Binding("text").makeTwoWay())));
var diamonddotteddtemplate = $(go.Node, "Auto", {
locationSpot: go.Spot.TopCenter,
isShadowed: false,
selectable: true,
resizable: true,
desiredSize: new go.Size(100, 100),
layerName: "Background",
avoidable: false,
selectionAdorned: false
}, new go.Binding("desiredSize", "size", go.Size.parse).makeTwoWay(go.Size.stringify), new go.Binding("location", "loc", go.Point.parse).makeTwoWay(go.Point.stringify), $(go.Shape, "Diamond", roundedBackgroundRectangleParams, {
name: "SHAPE",
fill: "transparent",
strokeWidth: 1,
stroke: '#a6a6a6',
fromLinkable: false,
fromLinkableSelfNode: false,
fromLinkableDuplicates: false,
toLinkable: false,
toLinkableSelfNode: false,
toLinkableDuplicates: false,
}), $(go.Panel, "Vertical", {
alignment: go.Spot.Center,
alignmentFocus: go.Spot.Center,
}, $(go.TextBlock, {
margin: 10,
editable: true,
font: '10pt sans-serif'
}, new go.Binding("text").makeTwoWay())));
var circletemplate = $(go.Node, "Auto", {
locationSpot: go.Spot.TopCenter,
isShadowed: false,
selectable: true,
resizable: true,
desiredSize: new go.Size(100, 100),
layerName: "Background",
avoidable: false,
selectionAdorned: false
}, new go.Binding("desiredSize", "size", go.Size.parse).makeTwoWay(go.Size.stringify), new go.Binding("location", "loc", go.Point.parse).makeTwoWay(go.Point.stringify), $(go.Shape, "Circle", roundedBackgroundRectangleParams, {
name: "SHAPE",
fill: strokewhite,
strokeWidth: 1,
stroke: '#a6a6a6',
fromLinkable: false,
fromLinkableSelfNode: false,
fromLinkableDuplicates: false,
toLinkable: false,
toLinkableSelfNode: false,
toLinkableDuplicates: false,
}), $(go.Panel, "Vertical", {
alignment: go.Spot.Center,
alignmentFocus: go.Spot.Center,
}, $(go.TextBlock, {
margin: 10,
editable: true,
font: '10pt sans-serif'
}, new go.Binding("text").makeTwoWay())));
var circledottedtemplate = $(go.Node, "Auto", {
locationSpot: go.Spot.TopCenter,
isShadowed: false,
selectable: true,
resizable: true,
desiredSize: new go.Size(100, 100),
layerName: "Background",
avoidable: false,
selectionAdorned: false
}, new go.Binding("desiredSize", "size", go.Size.parse).makeTwoWay(go.Size.stringify), new go.Binding("location", "loc", go.Point.parse).makeTwoWay(go.Point.stringify), $(go.Shape, "Circle", roundedBackgroundRectangleParams, {
name: "SHAPE",
fill: "transparent",
strokeWidth: 1,
stroke: '#a6a6a6',
fromLinkable: false,
fromLinkableSelfNode: false,
fromLinkableDuplicates: false,
toLinkable: false,
toLinkableSelfNode: false,
toLinkableDuplicates: false,
}), $(go.Panel, "Vertical", {
alignment: go.Spot.Center,
alignmentFocus: go.Spot.Center,
}, $(go.TextBlock, {
margin: 10,
editable: true,
font: '10pt sans-serif'
}, new go.Binding("text").makeTwoWay())));
var triangleuptemplate = $(go.Node, "Auto", {
locationSpot: go.Spot.TopCenter,
isShadowed: false,
selectable: true,
resizable: true,
desiredSize: new go.Size(100, 100),
layerName: "Background",
avoidable: false,
selectionAdorned: false
}, new go.Binding("desiredSize", "size", go.Size.parse).makeTwoWay(go.Size.stringify), new go.Binding("location", "loc", go.Point.parse).makeTwoWay(go.Point.stringify), $(go.Shape, "TriangleUp", roundedBackgroundRectangleParams, {
name: "SHAPE",
fill: strokewhite,
strokeWidth: 1,
stroke: strokegray,
fromLinkable: false,
fromLinkableSelfNode: false,
fromLinkableDuplicates: false,
toLinkable: false,
toLinkableSelfNode: false,
toLinkableDuplicates: false,
}), $(go.Panel, "Vertical", {
alignment: go.Spot.Center,
alignmentFocus: go.Spot.Center,
}, $(go.TextBlock, {
margin: 10,
editable: true,
font: '10pt sans-serif'
}, new go.Binding("text").makeTwoWay())));
var triangledowntemplate = $(go.Node, "Auto", {
locationSpot: go.Spot.TopCenter,
isShadowed: false,
selectable: true,
resizable: true,
desiredSize: new go.Size(100, 100),
layerName: "Background",
avoidable: false,
selectionAdorned: false
}, new go.Binding("desiredSize", "size", go.Size.parse).makeTwoWay(go.Size.stringify), new go.Binding("location", "loc", go.Point.parse).makeTwoWay(go.Point.stringify), $(go.Shape, "TriangleDown", roundedBackgroundRectangleParams, {
name: "SHAPE",
fill: "transparent",
strokeWidth: 1,
stroke: '#a6a6a6',
fromLinkable: false,
fromLinkableSelfNode: false,
fromLinkableDuplicates: false,
toLinkable: false,
toLinkableSelfNode: false,
toLinkableDuplicates: false,
}), $(go.Panel, "Vertical", {
alignment: go.Spot.TopLeft,
alignmentFocus: go.Spot.TopLeft,
}, $(go.TextBlock, {
margin: 10,
editable: true,
font: '10pt sans-serif'
}, new go.Binding("text").makeTwoWay())));
var linehtemplate = $(go.Node, "Auto", {
locationSpot: go.Spot.TopCenter,
isShadowed: false,
selectable: true,
resizable: true,
desiredSize: new go.Size(100, 100),
layerName: "Background",
avoidable: false,
selectionAdorned: false
}, new go.Binding("desiredSize", "size", go.Size.parse).makeTwoWay(go.Size.stringify), new go.Binding("location", "loc", go.Point.parse).makeTwoWay(go.Point.stringify), $(go.Shape, "LineH", {
name: "SHAPE",
fill: "transparent",
strokeWidth: 1,
stroke: '#a6a6a6',
fromLinkable: false,
fromLinkableSelfNode: false,
fromLinkableDuplicates: false,
toLinkable: false,
toLinkableSelfNode: false,
toLinkableDuplicates: false,
}), $(go.Panel, "Horizontal", {
alignment: go.Spot.Center,
alignmentFocus: go.Spot.Center,
}, $(go.TextBlock, {
margin: 10,
editable: true,
font: '10pt sans-serif'
}, new go.Binding("text").makeTwoWay())));
var linevtemplate = $(go.Node, "Auto", {
locationSpot: go.Spot.TopCenter,
isShadowed: false,
selectable: true,
resizable: true,
desiredSize: new go.Size(100, 100),
layerName: "Background",
avoidable: false,
selectionAdorned: false
}, new go.Binding("desiredSize", "size", go.Size.parse).makeTwoWay(go.Size.stringify), new go.Binding("location", "loc", go.Point.parse).makeTwoWay(go.Point.stringify), $(go.Shape, "LineV", {
name: "SHAPE",
fill: "transparent",
strokeWidth: 1,
stroke: '#a6a6a6',
fromLinkable: false,
fromLinkableSelfNode: false,
fromLinkableDuplicates: false,
toLinkable: false,
toLinkableSelfNode: false,
toLinkableDuplicates: false,
}), $(go.Panel, "Vertical", {
alignment: go.Spot.Center,
alignmentFocus: go.Spot.Center,
angle: 90
}, $(go.TextBlock, {
margin: 10,
editable: true,
font: '10pt sans-serif'
}, new go.Binding("text").makeTwoWay())));
var backgroundtemplate = $(go.Node, "Auto", {
locationSpot: go.Spot.TopCenter,
isShadowed: false,
selectable: true,
resizable: true,
desiredSize: new go.Size(100, 100),
layerName: "Background",
avoidable: false,
selectionAdorned: false
}, new go.Binding("desiredSize", "size", go.Size.parse).makeTwoWay(go.Size.stringify), new go.Binding("location", "loc", go.Point.parse).makeTwoWay(go.Point.stringify), $(go.Shape, "RoundedRectangle", roundedBackgroundRectangleParams, {
name: "SHAPE",
fill: strokewhite,
strokeWidth: 1,
stroke: strokegray,
fromLinkable: false,
fromLinkableSelfNode: false,
fromLinkableDuplicates: false,
toLinkable: false,
toLinkableSelfNode: false,
toLinkableDuplicates: false,
}), $(go.Panel, "Vertical", {
alignment: go.Spot.TopLeft,
alignmentFocus: go.Spot.TopLeft,
}, $(go.TextBlock, {
margin: 10,
editable: true,
font: '10pt sans-serif'
}, new go.Binding("text").makeTwoWay())));
var backgrounddottedtemplate = $(go.Node, "Auto", {
locationSpot: go.Spot.TopCenter,
isShadowed: false,
selectable: true,
resizable: true,
desiredSize: new go.Size(100, 100),
layerName: "Background",
avoidable: false,
selectionAdorned: false
}, new go.Binding("desiredSize", "size", go.Size.parse).makeTwoWay(go.Size.stringify), new go.Binding("location", "loc", go.Point.parse).makeTwoWay(go.Point.stringify), $(go.Shape, "RoundedRectangle", roundedBackgroundRectangleParams, {
name: "SHAPE",
fill: "transparent",
strokeWidth: 1,
stroke: '#a6a6a6',
fromLinkable: false,
fromLinkableSelfNode: false,
fromLinkableDuplicates: false,
toLinkable: false,
toLinkableSelfNode: false,
toLinkableDuplicates: false,
}), $(go.Panel, "Vertical", {
alignment: go.Spot.TopLeft,
alignmentFocus: go.Spot.TopLeft,
}, $(go.TextBlock, {
margin: 10,
editable: true,
font: '10pt sans-serif'
}, new go.Binding("text").makeTwoWay())));
var externaltemplate = $(go.Node, "Auto", {
locationSpot: go.Spot.TopCenter,
isShadowed: true,
shadowBlur: 0,
shadowOffset: new go.Point(0, 0),
shadowColor: "rgba(0, 0, 0, 0)",
selectable: true,
resizable: false,
layerName: "",
cursor: "pointer",
selectionAdorned: false,
avoidable: false
},
new go.Binding("location", "loc", go.Point.parse).makeTwoWay(go.Point.stringify), $(go.Shape, "RoundedRectangle", roundedRectangleParams, {
name: "SHAPE",
fill: strokewhite,
strokeWidth: strokeWidthLink,
stroke: strokegray,
portId: "",
fromLinkable: true,
fromLinkableSelfNode: true,
fromLinkableDuplicates: true,
toLinkable: true,
toLinkableSelfNode: false,
toLinkableDuplicates: true,
cursor: "pointer",
}), $(go.Picture, {
name: "IMAGE",
visible: true,
margin: 10,
width: nodeWitdh,
height: nodeHeight,
cursor: "pointer",
opacity: 1
}, new go.Binding("source")),
// four small named ports, one on each side:
makePort("T", go.Spot.Top, false, true),
makePort("L", go.Spot.Left, true, true),
makePort("R", go.Spot.Right, true, true),
makePort("B", go.Spot.Bottom, true, false),
{ // handle mouse enter/leave events to show/hide the ports
mouseEnter: (e, node) => showSmallPorts(node, true),
mouseLeave: (e, node) => showSmallPorts(node, false),
});
var adaptertemplate = $(go.Node, "Auto", {
locationSpot: go.Spot.TopCenter,
isShadowed: true,
shadowBlur: 0,
shadowOffset: new go.Point(0, 1),
shadowColor: "rgba(0, 0, 0, .14)",
selectable: true,
resizable: false,
layerName: "",
cursor: "pointer",
selectionAdorned: false
},
new go.Binding("location", "loc", go.Point.parse).makeTwoWay(go.Point.stringify),
$(go.Shape, "RoundedRectangle", roundedRectangleParams, {
name: "SHAPE",
fill: strokewhite,
strokeWidth: strokeWidthLink,
stroke: strokelightgray,
portId: "",
fromLinkable: true,
fromLinkableSelfNode: true,
fromLinkableDuplicates: true,
toLinkable: true,
toLinkableSelfNode: true,
toLinkableDuplicates: true,
cursor: "pointer",
}),
$(go.TextBlock, { margin: 5 },
new go.Binding("text", "key")),
{
toolTip:
$(go.Adornment, "Spot",
$(go.TextBlock, "Bottom",
{ margin: 5,background:"white"},
new go.Binding("text", "appName"))
)
},
$(go.Picture, {
name: "IMAGE",
visible: true,
margin: 10,
width: nodeWitdh,
height: nodeHeight,
cursor: "pointer",
opacity: 1
}, new go.Binding("source")),
makePort("T", go.Spot.Top, false, true),
makePort("L", go.Spot.Left, true, true),
makePort("R", go.Spot.Right, true, true),
makePort("B", go.Spot.Bottom, true, false),
{
mouseEnter: (e, node) => showSmallPorts(node, true),
mouseLeave: (e, node) => showSmallPorts(node, false),
}
);
var connectiontemplate = $(go.Node, "Auto", {
locationSpot: go.Spot.TopCenter,
isShadowed: true,
shadowBlur: 0,
shadowOffset: new go.Point(0, 1),
shadowColor: "rgba(0, 0, 0, .14)",
selectable: true,
resizable: false,
layerName: "",
cursor: "pointer",
selectionAdorned: false,
click: nodeSelection,
},
new go.Binding("location", "loc", go.Point.parse).makeTwoWay(go.Point.stringify),
$(go.Shape, "RoundedRectangle", roundedRectangleParams, {
name: "SHAPE",
fill: strokewhite,
strokeWidth: strokeWidthLink,
stroke: strokegreen,
portId: "",
fromSpot: go.Spot.AllSides,
toSpot: go.Spot.AllSides,
fromLinkable: true,
fromLinkableSelfNode: true,
fromLinkableDuplicates: true,
toLinkable: true,
toLinkableSelfNode: true,
toLinkableDuplicates: true,
cursor: "pointer",
}),
$(go.Picture, {
name: "IMAGE",
visible: true,
margin: 10,
width: nodeWitdh,
height: nodeHeight,
cursor: "pointer",
opacity: 1
}, new go.Binding("source")),
$(go.TextBlock, { margin: 5 },
new go.Binding("text", "key")),
{
toolTip:
$(go.Adornment, "Spot",
$(go.TextBlock, "Bottom",
{ margin: 5,background:"white"},
new go.Binding("text", "connectionName"))
)
},
// four small named ports, one on each side:
makePort("T", go.Spot.Top, false, true),
makePort("L", go.Spot.Left, true, true),
makePort("R", go.Spot.Right, true, true),
makePort("B", go.Spot.Bottom, true, false),
{ // handle mouse enter/leave events to show/hide the ports
mouseEnter: (e, node) => showSmallPorts(node, true),
mouseLeave: (e, node) => showSmallPorts(node, false),
}
);
Link
var linktemplate = $(go.Link, {
name: "link",
routing: go.Link.AvoidsNodes,
smoothness: 0.9,
curve: go.Link.JumpOver,
corner: 20,
reshapable: true,
resegmentable: false,
relinkableFrom: false,
relinkableTo: false,
selectionAdorned: false,
adjusting: go.Link.Stretch,
layerName: "",
click: linkSelection,
cursor: "pointer",
},
new go.Binding("points").makeTwoWay(),
new go.Binding("desiredSize", "size", go.Size.parse).makeTwoWay(go.Size.stringify),
new go.Binding("fromSpot", "fromSpot", go.Spot.parse).makeTwoWay(go.Spot.stringify),
new go.Binding("toSpot", "toSpot", go.Spot.parse).makeTwoWay(go.Spot.stringify),
$(go.Shape, {
name: "SHAPE",
strokeWidth: strokeWidthLink
},
new go.Binding("stroke", "", function (link) {
return linkColor(link)
})),
$(go.Shape, {
name: "FROM",
scale: arrowScale
},
new go.Binding("stroke", "", function (link) {
return linkColor(link)
}),
new go.Binding("fill", "", function (link) {
return linkColor(link)
}),
new go.Binding("fromArrow", "", function (link) {
return linkArrow(link, "Backward")
})),
$(go.Panel, "Auto", {
name: "linkTextPanel",
_isLinkLabel: true,
segmentIndex: NaN,
segmentFraction: .5,
visible: true,
},
new go.Binding("segmentFraction").makeTwoWay(),
$(go.Shape, "RoundedRectangle", {
name: "linkTextBackGround",
fill: strokewhite,
strokeWidth: 1,
stroke: strokelightblue,
}),
$(go.TextBlock, {
name: "linkTextBlock",
textAlign: "center",
font: "9pt helvetica, arial, sans-serif",
background: strokewhite,
margin: 8,
visible: true,
maxSize: new go.Size(230, NaN)
},
new go.Binding("text", "linkText" ) ),
$(go.Picture, linkWarningImage, {
name: "linkError",
desiredSize: new go.Size(10, 10),
alignment: go.Spot.TopRight,
click: linkErrors,
visible: false,
cursor: "pointer"
})
),
$(go.Shape, {
name: "TO",
scale: arrowScale
},
new go.Binding("stroke", "", function (link) {
return linkColor(link)
}),
new go.Binding("fill", "", function (link) {
return linkColor(link)
}),
new go.Binding("toArrow", "", function (link) {
return linkArrow(link, "Standard")
}))
);
Diagram intialization with templates
templmap.add("external", externaltemplate);
templmap.add("connection", connectiontemplate);
templmap.add("adapter", adaptertemplate);
templmap.add("background", backgroundtemplate);
templmap.add("backgrounddotted", backgrounddottedtemplate);
templmap.add("circle", circletemplate);
templmap.add("circledotted", circledottedtemplate);
templmap.add("diamond", diamondtemplate);
templmap.add("diamonddotted", diamonddotteddtemplate);
templmap.add("triangleup", triangleuptemplate);
templmap.add("triangledown", triangledowntemplate);
templmap.add("lineh", linehtemplate);
templmap.add("linev", linevtemplate);
templmap.add("text", texttemplate);
myDiagram.nodeTemplateMap = templmap;
myDiagram.linkTemplate = linktemplate;