Hi there!
Most of the question is already in the topic.
Basically my nodeTemplate looks like the one below, an image and a textbox below, with an arbitrary amount of contactpoints via binding + itemTemplate:
diagram.nodeTemplate =
$(go.Node, "Vertical",
new go.Binding("location", "loc", go.Point.parse).makeTwoWay(go.Point.stringify),
$(go.Panel, "Spot",
$(go.Picture,
new go.Binding("source", "imageUrl"),
{imageStretch: go.GraphObject.Uniform, maxSize: new go.Size(100, 100)},
new go.Binding("width"),
new go.Binding("height"),
),
new go.Binding("itemArray", "contactpoints"),
{
itemTemplate:
$(go.Panel,
new go.Binding("alignment", "", obj => new go.Spot(obj.x, obj.y)),
new go.Binding("portId", "id", id => "" + id),
{
margin: 0,
alignment: new go.Spot(0, 0, 0, 0),
toSpot: go.Spot.Top, fromSpot: go.Spot.Top
},
$(go.Shape, "Rectangle",
{
width: 4, height: 4, fill: "blue",
stroke: null, strokeWidth: 0,
fromLinkable: true, toLinkable: true, cursor: "pointer"
},
)
),
background: "lightgreen"
}
),
$(go.TextBlock, {
text: "Test",
textAlign: "center",
font: "10pt helvetica, arial, sans-serif",
stroke: "black",
background: "lightblue",
margin: new go.Margin(0, 0, 0, 0),
height: 18,
editable: false,
isMultiline: false
},
)
);
Test node:
{
key: "1", type: "", name: "", loc: "0 0", width: 445, height: 371, templateId: "", imageUrl: "/images/modules/unavailable.png",
contactpoints: [{type: "CanPort", in: Direction.Left, out: Direction.Right, x: 0.5, y: 0.0, name: "", id: "MYPORT"}]
}
The issue I have is that the node is bigger than the scaled image. I hoped it would behave like an html <img> with max-width and max-height where the whole image is scaled to respect both of the max-values while retaining its aspect ratio. In GoJs the image is scaled down but both maxWidth and maxHeight are preserved (or taken as the node’s size!?) and empty spaces remain right and left or above and below.
This image illustrates that:
Is there a way to achieve what I want to do?
Thank you in advance for your time and effort!
Florian