Search

Styling Basics

Styling

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.

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:

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.

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 backgroundColor is set
  • When the label is defined as an object and both backgroundColor and position are set

labelColor:

  • When the label is defined as an array of objects and the color is set
  • When the label is defined as an object and both color and position are set

In these cases, use onItemInteraction instead.

Terms of use

These terms do not alter or supersede any existing agreements between you (or your employer) and us.

By accessing or using any Content you agree to be bound by these Terms of Use. Please review these terms carefully before using the website.

The contents of this website, including but not limited to any text, code samples, API references, schemas, interactive tools, and other materials (collectively, the 'Content'), are made available for informational and internal evaluation purposes only. All intellectual property rights in the Content are reserved. No licence is granted to use the Content for any commercial purpose, or to copy, distribute, modify, reverse-engineer, or incorporate any part of the Content into any product or service, without our prior written consent.

This Content is provided “as is” and “as available,” without any representations, warranties, or guarantees of any kind, whether express or implied, including but not limited to implied warranties of merchantability, fitness for a particular purpose, non-infringement, or accuracy. To the fullest extent permitted by applicable law, we expressly exclude and disclaim all implied warranties, conditions, and other terms that might otherwise be implied.

We disclaim all liability for any loss or damage, whether direct, indirect, incidental, consequential, or otherwise, arising from any reliance placed on the Content or from your use of it, to the fullest extent permitted by applicable law. By continuing to access or use the Content, you acknowledge and agree to these terms.