Chart items such as nodes, links and annotations support a wide variety of customization options to make them suit your application. To do this, set properties on the item definitions in the items prop.
When you select a node or a link (default by clicking), it is styled with a selection style. This style is set using the selection chart option.
ReGraph Example
Explore various styles in the Node Gallery, Link Gallery and Advanced Annotation Gallery examples.
Sub-items
As well as customizing chart items, you can also specify various sub-items.
Sub-items are either decorations on chart items (such as labels or glyphs), or parts of chart items themselves (such as an annotation container). Sub-items can respond to events. The following sub-items can also have their own style rules:
- Halos - rings around nodes. The default node selection style uses halos. Each node support up to ten halos at any one time.
- Glyphs - decorations on nodes annotations, combos, or links. On nodes, annotations and combos, glyphs are placed around the border. On links, glyphs are placed next to the label at the link center or at link ends.
- Donuts - segmented borders around nodes which can indicate trends or relationships within that node, similar to a pie chart.
- Labels - additional information, such as text, font icons or images, to display with nodes, annotations or links.
The following example shows sub-items in action:
ReGraph Example
For more details and a full list of sub-item types, see the Sub-item section in the API Reference.
Interaction styling
Interaction styling applies when the user hovers over or selects an item or a sub-item. Once the pointer moves away or the the item is deselected, the styling reverts back to the values defined in the items prop.
You can also set selected items by passing their ids to the selection chart prop. Removing items from the prop deselects them and removes the selection styling.
There are two ways to set interaction styling - using the onItemInteraction event or the selection chart option.
The onItemInteraction event
The onItemInteraction event applies when specified items or sub-items are hovered or selected. It is best for adding more complex styling to a smaller number of items.
ReGraph Example
All items and sub-items in the event's item and subItem properties can be styled. Note that annotations and their sub-items ('container' and 'connection') are not selectable and can only be styled for hover interactions.
To apply interaction styling, pass the new styling to the event's setStyle function:
const interactionHandler = ({ selected, id, itemType, setStyle }) => {
let newStyle = { };
if ( selected && itemType === 'node' ) {
newStyle = {
...newStyle,
label: [{ text: 'selected' }],
};
}
setStyle({ [id]: newStyle });
};
return (
<Chart
// ...
onItemInteraction={interactionHandler}
/>
);If an item is styled by both the selection chart option and the onItemInteraction event, the selection option takes precedence. Set the option to false to override this.
See also the Interaction Styling example to learn more onItemInteraction.
Chart-wide selection
The properties available in the selection option are set for the whole chart. These properties apply to nodes, combos (open and closed), links (including summary and content links) and labels (including node, link and combo labels).
The color property applies a selection halo to a node, a background color to a label and a selection marker in the middle of a link. The labelColor property applies a font color to a label.
In these special cases related to node labels, properties are ignored:
color:
- When the label is defined as an array of objects and the
backgroundColoris set - When the label is defined as an object and both
backgroundColorandpositionare set
labelColor:
- When the label is defined as an array of objects and the
coloris set - When the label is defined as an object and both
colorandpositionare set
In these cases, use onItemInteraction instead.
