I wanna define a custom adornment, which is not a tooltip nor a context menu nor a selection. I want this to be bound to the model data so if data.blah
is set to true it is shown.
I haven not been able to find a declarative way of defining this adornment on the node template. So what I have is this:
function labelAdornment() {
return new go.Adornment("Spot", {
name: "label_adornment",
})
.add(
new go.Placeholder({
isActionable: true,
})
)
.add(
new go.Shape("RoundedRectangle", {
alignment: go.Spot.TopLeft,
alignmentFocus: go.Spot.BottomLeft,
})
);
}
And then I turn this on this way:
nodeTemplate = new go.Node(go.Panel.Auto, {
resizable: true,
resizeObjectName: "box",
})
.add(
new go.Panel(go.Panel.Auto, {
alignment: go.Spot.TopLeft,
})
.add(
new go.Shape("RoundedRectangle", {
fill: "ghostwhite",
stroke: "lightgray",
})
)
)
.bind(
new go.Binding("visible", "", (data, obj: go.GraphObject) => {
if (data.blah) {
const adornment = labelAdornment();
adornment.adornedObject = obj?.part;
obj?.part?.addAdornment("label", adornment);
}
return true;
})
);
But this looks like a hack and I don’t like it. What’s a better way of doing this?