So you took that from Buttons that show on Hover, didn’t you? OK, let’s modify it to behave more like what I think you want:
// this is shown by the mouseHover event handler
var nodeHoverAdornment =
$(go.Adornment, "Spot",
{ pickable: false },
$(go.Placeholder),
$("Button",
{ alignment: go.Spot.Bottom, alignmentFocus: go.Spot.Bottom },
{ click: function(e, obj) { alert("Hi!"); } },
$(go.TextBlock, "Hi!"))
);
// define a simple Node template
myDiagram.nodeTemplate =
$(go.Node, "Auto", // the Shape will go around the TextBlock
$(go.Shape, "RoundedRectangle", { strokeWidth: 0, portId: "", fromLinkable: true, toLinkable: true, cursor: "pointer" },
// Shape.fill is bound to Node.data.color
new go.Binding("fill", "color")),
$(go.TextBlock,
{ margin: 8 }, // some room around the text
// TextBlock.text is bound to Node.data.key
new go.Binding("text", "key")),
{ // show the Adornment when a mouseHover event occurs
mouseHover: function(e, obj) {
var node = obj.part;
nodeHoverAdornment.adornedObject = node;
node.addAdornment("mouseHover", nodeHoverAdornment);
},
// hide the Adornment when the mouse leaves the area of the node,
// because the hover adornment is covers part of the node
mouseLeave: function(e, node) {
if (!node.actualBounds.containsPoint(e.documentPoint)) node.removeAdornment("mouseHover");
}
}
);
This uses one of the buttons from the original sample instead of a simple TextBlock as what you are using, but that doesn’t matter for demonstrating the behavior. Basically the Adornment is quite straight-forward.
The only tricky point is that there is a smarter GraphObject.mouseLeave event handler on the node. You don’t want to blindly call Part.removeAdornment when the mouse leaves the node, because it leaves the node when entering the Adornment! So I’ve added a check to make sure the mouse isn’t still within the bounds of the node.