I assumed that the Stretch property stretches elements inside of the Panel.Spot in a way that they won’t exceed size of the main element or that they will fit inside of the main element. But it doesn’t seem to work this way. How can I structure my template to ensure elements are contained inside of the main shape area?
I’m currently getting this:
But I need this:
Example:
<!doctype html>
<html lang="en">
<body>
<script src="https://gojs.net/latest/release/go.js"></script>
<div id="sample" style="display: flex">
<div
id="diagramDiv"
style="border: solid 1px black; width: 600px; height: 600px"
></div>
</div>
<script id="code">
const diagram = new go.Diagram("diagramDiv");
const $ = go.GraphObject.make;
const nodeTemplate = new go.Node("Spot", {
draggable: true,
resizable: true,
resizeObjectName: "EditableShape",
})
.bindTwoWay("location", "location", go.Point.parse, go.Point.stringify)
.add(
new go.Panel("Spot").add(
new go.Shape("Rectangle", {
name: "EditableShape",
fill: "yellow",
}).bindTwoWay(
"desiredSize",
"size",
go.Size.parse,
go.Size.stringify,
),
new go.Panel("Table", {
stretch: go.Stretch.Fill,
}).add(
new go.TextBlock({
name: "TextBlock",
font: "bold 14px sans-serif",
stroke: "#333",
text: "",
editable: true,
row: 0,
column: 0,
text: "row:0, col: 0",
textAlign: "center",
verticalAlignment: go.Spot.Center,
}),
new go.TextBlock({
name: "TextBlock",
font: "bold 14px sans-serif",
stroke: "#333",
text: "",
editable: true,
row: 0,
column: 1,
text: "row:0, col: 1",
textAlign: "center",
verticalAlignment: go.Spot.Center,
}),
new go.TextBlock({
name: "TextBlock",
font: "bold 14px sans-serif",
stroke: "#333",
text: "",
editable: true,
row: 1,
columnSpan: 2,
stretch: go.Stretch.Fill,
text: "row:1, colSpan: 2",
textAlign: "center",
verticalAlignment: go.Spot.Center,
}),
),
),
);
diagram.nodeTemplate = nodeTemplate;
const nodes = [
{
key: "N1",
text: "Some text",
color: "lightblue",
location: "100 100",
size: "200 200",
},
];
const links = [];
diagram.model = new go.GraphLinksModel(nodes, links);
window.diagram = diagram;
</script>
</body>
</html>


