Search

Chart Events

In 3.0 we deprecated the onChart- events.

Chart events notify you about:

  • Internal state changes - for example, when a layout is run and positions update. These are passed as an object to the onChange prop with details of the change.
  • User interactions - for example, when the user clicks on a node. User event handlers are passed a set of arguments with more information about the event.

If present, calling preventDefault() in an event's handler will prevent the default behavior.

Events generally occur on items (i.e., nodes, links and annotations), but they can can also be triggered against parts of items, or sub-items. See Styling Chart Items for more details about sub-items.

The chart also supports standard element events, including onKeyDown, onFocus etc.

<Chart
  items={{this.state.items}}
  onClick={({id}) => { console.log(`User clicked on ${id}`); }}
/>

Invoked whenever the chart triggers a change of state. Typically caused by layouts and user interactions.

Parameters

change
required
object

An object describing the change.

Contains the positions of all annotations in the chart.

boolean

Indicates the current status of the hand mode option.

object

The underlying Leaflet map object. The property is set to the Leaflet map object when the map is shown. When the map is hidden, the property is set to null.

boolean

Indicates the current status of the overview's visible option.

Contains the positions of all nodes in the chart.

Indicates which items are currently selected.

object

The current view settings.

Chart Mode

required
unknown
offsetX
required
number

The x-offset (horizontal pan).

offsetY
required
number

The y-offset (vertical pan).

zoom
required
number

The zoom level.

Map Mode

required
unknown
mapCenter
required
array of numbers

The latitude and longitude of the center point of the map, as an array of the form [lat, long].

mapZoom
required
number

The zoom level of the map.

'auto' | 'user'

Indicates whether the onChange event was triggered by user action or internal ReGraph state.

Invoked when the user clicks or taps on the chart surface.

Default actions depending on the clicked item:

  • Node or link: Selects the item (adds to selection if consistentCtrl is pressed).
  • Background: Deselects all.
  • Navigation controls: Performs the navigation action.
  • Overview icon: Opens or closes the overview window.

To listen for right click, use the onContextMenu event.

Parameters

props
required
object

button

required
number

The index of the button used.

boolean

A read-only value indicating if the default action was prevented.

id

required
string | null

The id of the target item.

itemType

required
'node' | 'link' | 'annotation' | 'combo' | 'summaryLink' | 'aggregateLink' | null

The type of the target item.

object

A dictionary detailing which modifier keys were pressed when the event occurred. See Modifier Keys.

pointerId

required
number

The unique identifier of the pointer.

pointerType

required
string

The type of pointing device.

function

Call to prevent the default action of the event.

subItem

required
object

An object containing details of the target sub-item, if applicable. See Sub-item.

x

required
number

The x location of the pointer in view coordinates.

y

required
number

The y location of the pointer in view coordinates.

Invoked each time a summary link is created or updated. You can adjust the style of the summary link by calling setStyle with an object with style information. You can optionally include a string id property if you wish to use your own identifiers instead of the default. These must be unique.

<Chart onCombineLinks={
  (summaryDefinition) => {
     const { links, id1, id2, id, setStyle } = summaryDefinition;
     setStyle({
       // insert any styling properties
       width: Math.sqrt(Object.keys(links).length)
     });
  }
}/>

Parameters

Invoked each time a combo is created or updated in one of the following ways:

  • The combine prop is set to a new object.
  • The data properties used in the properties array change on any chart node.
  • A node with data properties used in the properties array is added or removed from the chart.
  • A node change inside the combo triggers a combo resize (e.g. by node resize, node shape change or label change).
<Chart onCombineNodes={
  (comboDefinition) => {
     const { nodes, combo, id, setStyle } = comboDefinition;
     setStyle({
       // insert any styling properties
       open: false,
       label: {
         text: combo.country,
       }
     });
  }
}/>

Parameters

object

An object describing the combo and its contents.

combo

required
object

An object containing the specific values for the combine properties. For example, properties ['county', 'state'] could result in a combo object { county: ‘Cambridge’, state: ‘Massachusetts’ }.

id

required
string

The default combo id. You can set a custom id in the setStyle function. Note that custom ids don't persist when the combine prop is set to a new object.

nodes

required
object

The nodes belonging to this combo.

setStyle

required
function

Specifies the style of this combo. See Combo setStyle.

Invoked on a right click, long press or left click + Ctrl for MacOS.

Default action: Suppresses the onClick event.

Parameters

props
required
object

button

required
number

The index of the button used.

boolean

A read-only value indicating if the default action was prevented.

id

required
string | null

The id of the target item.

itemType

required
'node' | 'link' | 'annotation' | 'combo' | 'summaryLink' | 'aggregateLink' | null

The type of the target item.

object

A dictionary detailing which modifier keys were pressed when the event occurred. See Modifier Keys.

pointerId

required
number

The unique identifier of the pointer.

pointerType

required
string

The type of pointing device.

function

Call to prevent the default action of the event.

subItem

required
object

An object containing details of the target sub-item, if applicable. See Sub-item.

x

required
number

The x location of the pointer in view coordinates.

y

required
number

The y location of the pointer in view coordinates.

Invoked when the user double-clicks or double-taps on the chart surface.

Parameters

props
required
object

button

required
number

The index of the button used.

id

required
string | null

The id of the target item.

itemType

required
'node' | 'link' | 'annotation' | 'combo' | 'summaryLink' | 'aggregateLink' | null

The type of the target item.

object

A dictionary detailing which modifier keys were pressed when the event occurred. See Modifier Keys.

pointerId

required
number

The unique identifier of the pointer.

pointerType

required
string

The type of pointing device.

subItem

required
object

An object containing details of the target sub-item, if applicable. See Sub-item.

x

required
number

The x location of the pointer in view coordinates.

y

required
number

The y location of the pointer in view coordinates.

Invoked continuously while the cursor moves during a drag.

Parameters

props
required
object

button

required
number

The index of the button used.

object

If the type is 'node' or 'annotation', contains the list of items being dragged.

id

required
string | null

The id of the item under the pointer when dragging started.

itemType

required
'node' | 'link' | 'annotation' | 'combo' | 'summaryLink' | 'aggregateLink' | null

The type of the target item.

object

A dictionary detailing which modifier keys were pressed when the event occurred. See Modifier Keys.

pointerId

required
number

The unique identifier of the pointer.

pointerType

required
string

The type of pointing device.

subItem

required
object

Details of the sub-item under the pointer when dragging started.

type

required
'pan' | 'marquee' | 'create-link' | 'slider' | 'overview' | 'node' | 'map' | 'annotation' | null

The type of drag.

x

required
number

The x location of the pointer in view coordinates.

y

required
number

The y location of the pointer in view coordinates.

Invoked when the drag is finished and pointer is released, or when the drag is canceled.

Default actions depending on the drag type:

  • 'node' or 'link' - Moves selected items to their final positions. Prevent the default action to snap the drag back.
  • 'marquee' - Updates the chart selection.
  • 'pan' or 'overview' - Accepts the final viewport position.
  • 'create-link' - Creates the link.

Parameters

props
required
object

button

required
number

The index of the button used.

boolean

A read-only value indicating if the default action was prevented.

object

If the type is 'node' or 'annotation', contains the list of items being dragged.

id

required
string | null

The id of the item the pointer is released on.

itemType

required
'node' | 'link' | 'annotation' | 'combo' | 'summaryLink' | 'aggregateLink' | null

The type of the target item.

object

A dictionary detailing which modifier keys were pressed when the event occurred. See Modifier Keys.

pointerId

required
number

The unique identifier of the pointer.

pointerType

required
string

The type of pointing device.

function

Call to prevent the default action of the event.

subItem

required
object

Details of the sub-item the pointer is released on.

type

required
'pan' | 'marquee' | 'create-link' | 'slider' | 'overview' | 'node' | 'map' | 'annotation' | null

The type of drag.

x

required
number

The x location of the pointer in view coordinates.

y

required
number

The y location of the pointer in view coordinates.

Invoked when the cursor dragging a node or an annotation moves over another item during a drag. Switch animation off during drag events to ensure they complete before associated animations start.

Parameters

props
required
object

button

required
number

The index of the button used.

object

The list of items being dragged.

id

required
string | null

The id of the item underneath the dragged item, or null if over the background.

itemType

required
'node' | 'link' | 'annotation' | 'combo' | 'summaryLink' | 'aggregateLink' | null

The type of the item underneath the dragged item, or null if over the background.

object

A dictionary detailing which modifier keys were pressed when the event occurred. See Modifier Keys.

pointerId

required
number

The unique identifier of the pointer.

pointerType

required
string

The type of pointing device.

subItem

required
object

The details of the sub-item underneath the dragged item.

'node' | 'annotation'

The type of item dragged by the cursor.

x

required
number

The x location of the pointer in view coordinates.

y

required
number

The y location of the pointer in view coordinates.

Invoked when a drag is started. Switch animation off during drag events to ensure they complete before associated animations start.

Default action: Creates a dragger. Prevent the default action to disable dragging.

Parameters

props
required
object

button

required
number

The index of the button used.

boolean

A read-only value indicating if the default action was prevented.

object

If the type is 'node' or 'annotation', contains the list of items being dragged.

id

required
string | null

The id of the item under the pointer when dragging started.

itemType

required
'node' | 'link' | 'annotation' | 'combo' | 'summaryLink' | 'aggregateLink' | null

The type of the target item.

object

A dictionary detailing which modifier keys were pressed when the event occurred. See Modifier Keys.

pointerId

required
number

The unique identifier of the pointer.

pointerType

required
string

The type of pointing device.

function

Call to prevent the default action of the event.

function

Call to set options for the drag. See setDragOptions.

subItem

required
object

Details of the sub-item under the pointer when dragging started.

type

required
'pan' | 'marquee' | 'slider' | 'overview' | 'node' | 'map' | 'annotation' | null

The type of drag.

x

required
number

The x location of the pointer in view coordinates.

y

required
number

The y location of the pointer in view coordinates.

Invoked when the user hovers over an item for a specified time. You can modify the delay in the hoverDelay Chart option. Only invoked when the hover id changes. To apply custom styling when an item is hovered over, consider using onItemInteraction.

Parameters

props
required
object

button

required
number

The index of the button used.

id

required
string | null

The id of the target item.

itemType

required
'node' | 'link' | 'annotation' | 'combo' | 'summaryLink' | 'aggregateLink' | null

The type of the target item.

object

A dictionary detailing which modifier keys were pressed when the event occurred. See Modifier Keys.

pointerId

required
number

The unique identifier of the pointer.

pointerType

required
string

The type of pointing device.

subItem

required
object

An object containing details of the target sub-item, if applicable. See Sub-item.

x

required
number

The x location of the pointer in view coordinates.

y

required
number

The y location of the pointer in view coordinates.

Invoked each time an item or sub-item is hovered over or selected. Use hoverDelay to modify the event delay.

If both onItemInteraction and selection option are used to style an item, selection option takes precedence. Set it to false to override this.

The interaction styling set by the event's setStyle function only affects the properties/sub-properties specified and it is cleared once the user interaction is over.

See also Interaction styling docs.

onItemInteraction={({ id, setStyle, hovered }) => {
  if (hovered) {                        // when hovered by the user
    setStyle({
      [id]: {
        color: '#17BA99',               // node color changes
        label: [
          { text: 'hovered label 1' },  // label 1 text changes
          {},                           // label 2 does not change
          { text: 'hovered label 3' },
        ],
      },
    });
}}}/>

Parameters

props
required
object

Information about the target aggregate link.

object

Lists the combine properties of the target combo.

hovered

required
boolean

True if the target is being hovered over.

id

required
string

The id of the target item.

The target item.

itemType

required
'node' | 'link' | 'annotation' | 'combo' | 'summaryLink' | 'aggregateLink' | null

The type of the target item.

object

Lists the links inside the target summary link.

object

Lists the nodes inside the target combo.

selected

required
boolean

True if the target is selected.

signal

required
object

An event signal that can be aborted by an AbortController to cancel the styling.

subItem

required
object

Details of the sub-item interacted with. See Sub-item.

object

Lists the subjects of the target annotation.

Sets the interaction style of chart items specified by the function. See Data Formats for all item styles.

Setting fade to false in this function automatically backgrounds every other chart item that doesn't have fade set to false.

When styling node labels, the format of label specified in setStyle must follow the same format as the unstyled label.

Parameters

items
required
[id: string]: Node | Link | Annotation

A dictionary of items.

An object with node, link, or annotation properties to be applied.

Invoked each time an aggregate link is created, deleted or updated. The update occurs when a child link is added or removed, a child link's arrow changes, or when the custom property in data object used for aggregating links is changed. To style an aggregate link, call setStyle with an object with style information.

The onLinkAggregation event is in beta from v4.4.

<Chart onLinkAggregation={
  (aggregateLinkDefinition) => {
     const { links, id1, id2, id, aggregateByValue, change, setStyle } = aggregateLinkDefinition;
     setStyle({
       // insert any styling properties
       width: Math.sqrt(Object.keys(links).length)
     });
  }
}/>

Parameters

object

An object describing the aggregate link and its contents.

'none' | 'both' | 'from' | 'to' | undefined

The arrow direction of the child links, when aggregateByDirection: true. Otherwise is undefined.

string

The value of the property being used to group links into aggregate links. This is undefined when aggregateLinks prop is set to true.

change

required
'created' | 'updated' | 'deleted'

Describes the change occuring to the aggregate link.

id

required
string

The id of this aggregate link.

id1

required
string

The id of the node/combo at one end of the aggregate link that comes first in alphanumeric order. This order may be relevant when using aggregate links with sequential layout without top or level specified, or when setting arrows or flow on aggregate links. See Enabling aggregate links.

id2

required
string

The id of the node/combo at the other end of the aggregate link that comes second in alphanumeric order. This order may be relevant when using aggregate links with sequential layout without top or level specified, or when setting arrows or flow on aggregate links. See Enabling aggregate links.

required
object

A dictionary of objects describing the child links.

setStyle

required
function

Specifies the style to be used for this aggregate link. See Aggregate link setStyle.

Invoked when the pointer presses down on the chart surface.

Parameters

props
required
object

button

required
number

The index of the button used.

id

required
string | null

The id of the target item.

itemType

required
'node' | 'link' | 'annotation' | 'combo' | 'summaryLink' | 'aggregateLink' | null

The type of the target item.

object

A dictionary detailing which modifier keys were pressed when the event occurred. See Modifier Keys.

pointerId

required
number

The unique identifier of the pointer.

pointerType

required
string

The type of pointing device.

subItem

required
object

An object containing details of the target sub-item, if applicable. See Sub-item.

x

required
number

The x location of the pointer in view coordinates.

y

required
number

The y location of the pointer in view coordinates.

Invoked continuously while the pointer moves on the chart surface.

Parameters

props
required
object

button

required
number

The index of the button used.

id

required
string | null

The id of the target item.

itemType

required
'node' | 'link' | 'annotation' | 'combo' | 'summaryLink' | 'aggregateLink' | null

The type of the target item.

object

A dictionary detailing which modifier keys were pressed when the event occurred. See Modifier Keys.

pointerId

required
number

The unique identifier of the pointer.

pointerType

required
string

The type of pointing device.

subItem

required
object

An object containing details of the target sub-item, if applicable. See Sub-item.

x

required
number

The x location of the pointer in view coordinates.

y

required
number

The y location of the pointer in view coordinates.

Invoked when the pointer is released.

Parameters

props
required
object

button

required
number

The index of the button used.

id

required
string | null

The id of the target item.

itemType

required
'node' | 'link' | 'annotation' | 'combo' | 'summaryLink' | 'aggregateLink' | null

The type of the target item.

object

A dictionary detailing which modifier keys were pressed when the event occurred. See Modifier Keys.

pointerId

required
number

The unique identifier of the pointer.

pointerType

required
string

The type of pointing device.

subItem

required
object

An object containing details of the target sub-item, if applicable. See Sub-item.

x

required
number

The x location of the pointer in view coordinates.

y

required
number

The y location of the pointer in view coordinates.

Invoked each time the chart has finished updating.

Invoked continuously when the chart view changes, e.g. during zooming or panning.

Parameters

props
required
object

Chart Mode

required
unknown

offsetX

required
number

The x-offset (horizontal pan).

offsetY

required
number

The y-offset (vertical pan).

zoom

required
number

The zoom level.

Map Mode

required
unknown

mapCenter

required
array of numbers

The latitude and longitude of the center point of the map, as an array of the form [lat, long].

mapZoom

required
number

The zoom level of the map.

Invoked continuously while the user is rotating a mouse wheel or scrolling using a trackpad.

Default action: Animated zoom in or out.

Parameters

props
required
object
boolean

A read-only value indicating if the default action was prevented.

deltaMode

required
number

The unit of measurement for the delta value.

deltaX

required
number

The number of units that the wheel scrolled in the x direction.

deltaY

required
number

The number of units that the wheel scrolled in the y direction.

object

A dictionary detailing which modifier keys were pressed when the event occurred. See Modifier Keys.

function

Call to prevent the default action of the event.

x

required
number

The x location of the pointer in view coordinates.

y

required
number

The y location of the pointer in view coordinates.

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.