OK, here’s both the original template, slightly updated, and a completely different way to try clipping.
myDiagram.nodeTemplate =
$(go.Node, "Auto",
$(go.Shape, // this is the normal border in an Auto Panel
{ portId: "" }, // links connect with edge of shape, not with rectangular Node
{ fill: null, stroke: "cyan", strokeWidth: 4 },
{ geometryString: "F1 M30 0 L60 60 0 60z" }, // default to a triangle
new go.Binding("geometryString", "geo")),
$(go.Panel, "Auto",
{ isClipping: true }, // cause the Shape's geometry to clip other element(s)
{ width: 100, height: 100 }, // bigger than the actual image, to demo stretch
$(go.Shape,
{ geometryString: "F1 M30 0 L60 60 0 60z" }, // default to a triangle
new go.Binding("geometryString", "geo")),
$(go.Picture,
{
stretch: go.GraphObject.Fill, // stretch picture to fill whole area of shape
imageStretch: go.GraphObject.UniformToFill // but don't distort the image within the picture
// alas there is no imageAlign property to control where the image is drawn within the picture
},
new go.Binding("source", "src"))
)
);
myDiagram.nodeTemplateMap.add("Position",
$(go.Node, "Position",
{
isClipping: true,
selectionObjectName: "BORDER"
}, // cause the main Shape's geometry to clip other element(s)
$(go.Shape, // this is the border
{
name: "BORDER",
portId: "", // links connect with edge of shape, not with rectangular Node
fill: null,
stroke: "cyan",
strokeWidth: 4,
geometry: go.Geometry.parse("F1 M27.5 0 L55 55 0 55z") // default to a triangle
},
new go.Binding("geometry", "geo", go.Geometry.parse)),
$(go.Shape,
{
isPanelMain: true, // this is the clipping shape
position: new go.Point(2, 2), // because border's strokeWidth: 4
geometry: go.Geometry.parse("F1 M27.5 0 L55 55 0 55z") // default to a triangle
},
new go.Binding("geometry", "geo", go.Geometry.parse)),
$(go.Picture,
{
position: new go.Point(2, 2), // because border's strokeWidth: 4
width: 60, // but leave desiredSize.height at the default value of NaN
imageStretch: go.GraphObject.UniformToFill
// alas there is no imageAlign property to control where the image is drawn within the picture
},
new go.Binding("source", "src"))
));
myDiagram.model = new go.GraphLinksModel([
{ key: "Alpha", src: "http://gojs.net/latest/samples/images/storage%20array.jpg" },
{
key: "Beta", src: "http://gojs.net/latest/samples/images/storage%20array.jpg",
geo: "F1 M20 0 L60 0 60 40 40 60 0 60 0 20z"
},
{
key: "Gamma", src: "http://gojs.net/latest/samples/images/storage%20array.jpg",
category: "Position"
},
{
key: "Delta", src: "http://gojs.net/latest/samples/images/storage%20array.jpg",
geo: "F1 M20 0 L55 0 55 40 40 55 0 55 0 20z",
category: "Position"
}
],[
{ from: "Alpha", to: "Beta" },
{ from: "Gamma", to: "Delta" }
]);
The Panel.isClipping feature is still experimental. Do you think we should have the clipping Shape also draw its stroke? What about its fill?