Highlighting
It is common to make a Node (or a part of a Node or a Link) stand out by "highlighting" it in some way. This happens with selection when a selection Adornment is shown. However one frequently wants to highlight Parts independently of selection. This can be done by changing the fill or stroke of a Shape, replacing a Picture source with another source, adding or removing a shadow, and so on.
Highlighting a Node upon mouse over
The most general kind of highlighting is to change appearance when an action occurs, such as mousing over a node. This can draw attention to interactive Nodes or Links or really any GraphObject, such as buttons. This is why the predefined buttons in GoJS highlight on mouse-over.
To achieve this effect you just need to define GraphObject.mouseEnter and GraphObject.mouseLeave event handlers.
Mouse-over nodes to see them highlight.
It is also commonplace to perform highlighting of stationary Parts during a drag, which is a different case of "mouse over". This can be implemented in a manner similar to the mouseEnter/mouseLeave events by implementing GraphObject.mouseDragEnter and GraphObject.mouseDragLeave event handlers. Several samples demonstrate this: Org Chart Editor, Planogram, Regrouping, and Seating Chart.
Highlighting Nodes and Links
It is common to want to show Nodes or Links that are related to a particular Node. Unlike the mouse-over scenarios, one may want to maintain the highlighting for many Parts independent of any mouse state or selection state.
Here is an example of highlighting all of the nodes and links that come out of a node that the user clicks. This example uses the Part.isHighlighted property and data binding of visual properties to that Part.isHighlighted property. Unlike the Part.isSelected property, there are no pre-defined appearance behaviors defined when a Part is highlighted or loses highlight.
Click on a node to highlight outbound connected links and nodes. Click in the diagram background to remove all highlights. Note that the highlighting is independent of selection.
The use of data binding to modify the Shape properties allows you to avoid specifying names for each Shape and writing code to find the Shape and modify its properties. Note how the call to establish a Binding where the source object is the whole Node instead of the node data is to GraphObject.bindObject instead of the usual GraphObject.bind.
However when the modifications you want to make are too complicated to implement using data binding, you can implement a Part.highlightedChanged event handler. Similar to the restrictions of the analogous Part.selectionChanged event handler, you must not change the highlighting of any other Parts, and we recommend against making any changes that would cause a layout to happen or any links to be rerouted.
Changing Node size When highlighting
You may want to increase the size of a node or of an element in a node in order to highlight it. For example you could have a Binding on GraphObject.scale or Shape.strokeWidth:
However, doing so will change the size of the object. That is likely to invalidate the route of any links that are connected with that node. That might not matter in many apps, but in some cases the routes of some links may have been reshaped by the user. Any recomputation of the route due to a connected node moving or changing size might lose that route.
If that is a consideration in your app, you might consider instead having each node hold an additional Shape that would provide the highlighting when shown and that would be unseen otherwise. But do not toggle the GraphObject.visible property, because that would cause the node to change size. Instead toggle the GraphObject.opacity property between 0.0 and 1.0.
In the below example, there is not a separate highlight shape
-- changes are made directly to the Node's content --
but rather an invisible (opacity: 0) placeholder Shape with a set width and height to keep the node's boundaries the same when the content is scaled up.
The placeholder Shape is always hidden by having zero opacity, and has GraphObject.pickable set to false so that the user can click outside the boundary of the visible node without clicking the node.