## ToolTips

GoJS provides a way to create customized tooltips for any object or for the diagram background.

A tooltip is an Adornment that is shown when the mouse hovers over an object that has its GraphObject.toolTip set. The tooltip part is bound to the same data as the part itself.

In this example each Node has its GraphObject.toolTip property set to a Part that shows the data.color property via a normal data binding. The diagram gets its own tooltip by setting Diagram.toolTip.

      diagram.nodeTemplate =
        $(go.Node, "Auto",
          $(go.Shape, "RoundedRectangle",
            { fill: "white" },
            new go.Binding("fill", "color")),
          $(go.TextBlock, { margin: 5 },
            new go.Binding("text", "key")),
          {
            toolTip:  // define a tooltip for each node that displays the color as text
              $(go.Adornment, "Auto",
                $(go.Shape, { fill: "#FFFFCC" }),
                $(go.TextBlock, { margin: 4 },
                  new go.Binding("text", "color"))
              )  // end of Adornment
          }
        );

      // a function that produces the content of the diagram tooltip
      function diagramInfo(model) {
        return "Model:\n" + model.nodeDataArray.length + " nodes, " +
                            model.linkDataArray.length + " links";
      }

      // provide a tooltip for the background of the Diagram, when not over any Part
      diagram.toolTip =
        $(go.Adornment, "Auto",
          $(go.Shape, { fill: "#CCFFCC" }),
          $(go.TextBlock, { margin: 4 },
            // use a converter to display information about the diagram model
            new go.Binding("text", "", diagramInfo))
        );

      var nodeDataArray = [
        { key: "Alpha", color: "lightblue" },
        { key: "Beta", color: "pink" }
      ];
      var linkDataArray = [
        { from: "Alpha", to: "Beta" }
      ];
      diagram.model = new go.GraphLinksModel(nodeDataArray, linkDataArray);

Try pausing the mouse over each of the nodes or in the background of the diagram. If you copy some parts, you will see that the tooltip for the diagram displays newer information about the diagram.

You can change how long for the mouse has to wait motionless before a tooltip appears by setting ToolManager.hoverDelay. For example: `myDiagram.toolManager.hoverDelay = 600;` changes the delay to be 6/10ths of one second.

#### Positioning

There are two ways to customize the positioning of the tooltip relative to the adorned GraphObject. One way is to override ToolManager.positionToolTip. Another way is to have the tooltip Adornment include a Placeholder. The Placeholder is positioned to have the same size and position as the adorned object.

      // this is a normal Node template that also has a toolTip defined for it
      diagram.nodeTemplate =
        $(go.Node, "Auto",
          $(go.Shape, "RoundedRectangle",
            { fill: "white" },
            new go.Binding("fill", "color")),
          $(go.TextBlock, { margin: 5 },
            new go.Binding("text", "key")),
          {
            toolTip:                       // define a tooltip for each node
              $(go.Adornment, "Spot",      // that has several labels around it
                { background: "transparent" },  // avoid hiding tooltip when mouse moves
                $(go.Placeholder, { padding: 5 }),
                $(go.TextBlock,
                  { alignment: go.Spot.Top, alignmentFocus: go.Spot.Bottom, stroke: "red" },
                  new go.Binding("text", "key", function(s) { return "key: " + s; })),
                $(go.TextBlock, "Bottom",
                  { alignment: go.Spot.Bottom, alignmentFocus: go.Spot.Top, stroke: "red" },
                  new go.Binding("text", "color", function(s) { return "color: " + s; }))
              )  // end Adornment
          }
        );
      diagram.initialContentAlignment = go.Spot.Center;
      var nodeDataArray = [
        { key: "Alpha", color: "lightyellow" },
        { key: "Beta", color: "orange" }
      ];
      var linkDataArray = [
        { from: "Alpha", to: "Beta" }
      ];
      diagram.model = new go.GraphLinksModel(nodeDataArray, linkDataArray);

Note how the Adornment implementing the tooltip uses a "transparent" background so that the tooltip is not automatically removed when the mouse moves.