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
onChangeprop 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
objectAn object describing the change.
objectContains the positions of all annotations in the chart.
booleanIndicates the current status of the hand mode option.
objectThe 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.
booleanIndicates the current status of the overview's visible option.
objectContains the positions of all nodes in the chart.
objectIndicates which items are currently selected.
objectThe current view settings.
Chart Mode
requiredunknown'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
requirednumberThe index of the button used.
defaultPrevented
requiredbooleanA read-only value indicating if the default action was prevented.
id
requiredstring | nullThe id of the target item.
itemType
required'node' | 'link' | 'annotation' | 'combo' | 'summaryLink' | 'aggregateLink' | nullThe type of the target item.
modifierKeys
requiredobjectA dictionary detailing which modifier keys were pressed when the event occurred. See Modifier Keys.
pointerId
requirednumberThe unique identifier of the pointer.
pointerType
requiredstringThe type of pointing device.
preventDefault
requiredfunctionCall to prevent the default action of the event.
subItem
requiredobjectAn object containing details of the target sub-item, if applicable. See Sub-item.
x
requirednumberThe x location of the pointer in view coordinates.
y
requirednumberThe 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
- summaryDefinition required
objectAn object describing the summary link and its contents.
id
requiredstringThe default id for this summary link. This can be overridden in the summary link setStyle function.
id1
requiredstringThe id at one end of the summary link. Note this can be the id of a combo or a node.
id2
requiredstringThe id at the other end of the summary link. Note this can be the id of a combo or a node.
links
requiredobjectA dictionary of objects describing the content links inside this summary link.
setStyle
requiredfunctionUse to specify the style of this summary link. See Summary link setStyle.
Invoked each time a combo is created or updated in one of the following ways:
- The
combineprop is set to a new object. - The
dataproperties used in thepropertiesarray change on any chart node. - A node with
dataproperties used in thepropertiesarray 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
- comboDefinition required
objectAn object describing the combo and its contents.
combo
requiredobjectAn 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
requiredstringThe 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
requiredobjectThe nodes belonging to this combo.
setStyle
requiredfunctionSpecifies 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
requirednumberThe index of the button used.
defaultPrevented
requiredbooleanA read-only value indicating if the default action was prevented.
id
requiredstring | nullThe id of the target item.
itemType
required'node' | 'link' | 'annotation' | 'combo' | 'summaryLink' | 'aggregateLink' | nullThe type of the target item.
modifierKeys
requiredobjectA dictionary detailing which modifier keys were pressed when the event occurred. See Modifier Keys.
pointerId
requirednumberThe unique identifier of the pointer.
pointerType
requiredstringThe type of pointing device.
preventDefault
requiredfunctionCall to prevent the default action of the event.
subItem
requiredobjectAn object containing details of the target sub-item, if applicable. See Sub-item.
x
requirednumberThe x location of the pointer in view coordinates.
y
requirednumberThe 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
requirednumberThe index of the button used.
id
requiredstring | nullThe id of the target item.
itemType
required'node' | 'link' | 'annotation' | 'combo' | 'summaryLink' | 'aggregateLink' | nullThe type of the target item.
modifierKeys
requiredobjectA dictionary detailing which modifier keys were pressed when the event occurred. See Modifier Keys.
pointerId
requirednumberThe unique identifier of the pointer.
pointerType
requiredstringThe type of pointing device.
subItem
requiredobjectAn object containing details of the target sub-item, if applicable. See Sub-item.
x
requirednumberThe x location of the pointer in view coordinates.
y
requirednumberThe y location of the pointer in view coordinates.
Invoked continuously while the cursor moves during a drag.
Parameters
- props required
object
button
requirednumberThe index of the button used.
draggedItems
requiredobjectIf the type is 'node' or 'annotation', contains the list of items being dragged.
id
requiredstring | nullThe id of the item under the pointer when dragging started.
itemType
required'node' | 'link' | 'annotation' | 'combo' | 'summaryLink' | 'aggregateLink' | nullThe type of the target item.
modifierKeys
requiredobjectA dictionary detailing which modifier keys were pressed when the event occurred. See Modifier Keys.
pointerId
requirednumberThe unique identifier of the pointer.
pointerType
requiredstringThe type of pointing device.
subItem
requiredobjectDetails of the sub-item under the pointer when dragging started.
type
required'pan' | 'marquee' | 'create-link' | 'slider' | 'overview' | 'node' | 'map' | 'annotation' | nullThe type of drag.
x
requirednumberThe x location of the pointer in view coordinates.
y
requirednumberThe 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
requirednumberThe index of the button used.
defaultPrevented
requiredbooleanA read-only value indicating if the default action was prevented.
draggedItems
requiredobjectIf the type is 'node' or 'annotation', contains the list of items being dragged.
id
requiredstring | nullThe id of the item the pointer is released on.
itemType
required'node' | 'link' | 'annotation' | 'combo' | 'summaryLink' | 'aggregateLink' | nullThe type of the target item.
modifierKeys
requiredobjectA dictionary detailing which modifier keys were pressed when the event occurred. See Modifier Keys.
pointerId
requirednumberThe unique identifier of the pointer.
pointerType
requiredstringThe type of pointing device.
preventDefault
requiredfunctionCall to prevent the default action of the event.
subItem
requiredobjectDetails of the sub-item the pointer is released on.
type
required'pan' | 'marquee' | 'create-link' | 'slider' | 'overview' | 'node' | 'map' | 'annotation' | nullThe type of drag.
x
requirednumberThe x location of the pointer in view coordinates.
y
requirednumberThe 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
requirednumberThe index of the button used.
draggedItems
requiredobjectThe list of items being dragged.
id
requiredstring | nullThe id of the item underneath the dragged item, or null if over the background.
itemType
required'node' | 'link' | 'annotation' | 'combo' | 'summaryLink' | 'aggregateLink' | nullThe type of the item underneath the dragged item, or null if over the background.
modifierKeys
requiredobjectA dictionary detailing which modifier keys were pressed when the event occurred. See Modifier Keys.
pointerId
requirednumberThe unique identifier of the pointer.
pointerType
requiredstringThe type of pointing device.
subItem
requiredobjectThe details of the sub-item underneath the dragged item.
'node' | 'annotation'The type of item dragged by the cursor.
x
requirednumberThe x location of the pointer in view coordinates.
y
requirednumberThe 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
requirednumberThe index of the button used.
defaultPrevented
requiredbooleanA read-only value indicating if the default action was prevented.
draggedItems
requiredobjectIf the type is 'node' or 'annotation', contains the list of items being dragged.
id
requiredstring | nullThe id of the item under the pointer when dragging started.
itemType
required'node' | 'link' | 'annotation' | 'combo' | 'summaryLink' | 'aggregateLink' | nullThe type of the target item.
modifierKeys
requiredobjectA dictionary detailing which modifier keys were pressed when the event occurred. See Modifier Keys.
pointerId
requirednumberThe unique identifier of the pointer.
pointerType
requiredstringThe type of pointing device.
preventDefault
requiredfunctionCall to prevent the default action of the event.
setDragOptions
requiredfunctionCall to set options for the drag. See setDragOptions.
subItem
requiredobjectDetails of the sub-item under the pointer when dragging started.
type
required'pan' | 'marquee' | 'slider' | 'overview' | 'node' | 'map' | 'annotation' | nullThe type of drag.
x
requirednumberThe x location of the pointer in view coordinates.
y
requirednumberThe 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
requirednumberThe index of the button used.
id
requiredstring | nullThe id of the target item.
itemType
required'node' | 'link' | 'annotation' | 'combo' | 'summaryLink' | 'aggregateLink' | nullThe type of the target item.
modifierKeys
requiredobjectA dictionary detailing which modifier keys were pressed when the event occurred. See Modifier Keys.
pointerId
requirednumberThe unique identifier of the pointer.
pointerType
requiredstringThe type of pointing device.
subItem
requiredobjectAn object containing details of the target sub-item, if applicable. See Sub-item.
x
requirednumberThe x location of the pointer in view coordinates.
y
requirednumberThe 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- items required
[id: string]: Node | Link | AnnotationA dictionary of items.
An object with node, link, or annotation properties to be applied.
objectInformation about the target aggregate link.
objectLists the combine properties of the target combo.
hovered
requiredbooleanTrue if the target is being hovered over.
id
requiredstringThe id of the target item.
item
requiredNode | Link | Annotation | ComboStyle | SummaryThe target item.
itemType
required'node' | 'link' | 'annotation' | 'combo' | 'summaryLink' | 'aggregateLink' | nullThe type of the target item.
objectLists the links inside the target summary link.
objectLists the nodes inside the target combo.
selected
requiredbooleanTrue if the target is selected.
signal
requiredobjectAn event signal that can be aborted by an AbortController to cancel the styling.
objectLists 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
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
- aggregateLinkDefinition required
objectAn object describing the aggregate link and its contents.
aggregateByDirection
required'none' | 'both' | 'from' | 'to' | undefinedThe arrow direction of the child links, when aggregateByDirection: true. Otherwise is undefined.
aggregateByValue
requiredstringThe 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
requiredstringThe id of this aggregate link.
id1
requiredstringThe 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
requiredstringThe 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.
links
requiredobjectA dictionary of objects describing the child links.
setStyle
requiredfunctionSpecifies 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
requirednumberThe index of the button used.
id
requiredstring | nullThe id of the target item.
itemType
required'node' | 'link' | 'annotation' | 'combo' | 'summaryLink' | 'aggregateLink' | nullThe type of the target item.
modifierKeys
requiredobjectA dictionary detailing which modifier keys were pressed when the event occurred. See Modifier Keys.
pointerId
requirednumberThe unique identifier of the pointer.
pointerType
requiredstringThe type of pointing device.
subItem
requiredobjectAn object containing details of the target sub-item, if applicable. See Sub-item.
x
requirednumberThe x location of the pointer in view coordinates.
y
requirednumberThe y location of the pointer in view coordinates.
Invoked continuously while the pointer moves on the chart surface.
Parameters
- props required
object
button
requirednumberThe index of the button used.
id
requiredstring | nullThe id of the target item.
itemType
required'node' | 'link' | 'annotation' | 'combo' | 'summaryLink' | 'aggregateLink' | nullThe type of the target item.
modifierKeys
requiredobjectA dictionary detailing which modifier keys were pressed when the event occurred. See Modifier Keys.
pointerId
requirednumberThe unique identifier of the pointer.
pointerType
requiredstringThe type of pointing device.
subItem
requiredobjectAn object containing details of the target sub-item, if applicable. See Sub-item.
x
requirednumberThe x location of the pointer in view coordinates.
y
requirednumberThe y location of the pointer in view coordinates.
Invoked when the pointer is released.
Parameters
- props required
object
button
requirednumberThe index of the button used.
id
requiredstring | nullThe id of the target item.
itemType
required'node' | 'link' | 'annotation' | 'combo' | 'summaryLink' | 'aggregateLink' | nullThe type of the target item.
modifierKeys
requiredobjectA dictionary detailing which modifier keys were pressed when the event occurred. See Modifier Keys.
pointerId
requirednumberThe unique identifier of the pointer.
pointerType
requiredstringThe type of pointing device.
subItem
requiredobjectAn object containing details of the target sub-item, if applicable. See Sub-item.
x
requirednumberThe x location of the pointer in view coordinates.
y
requirednumberThe y location of the pointer in view coordinates.
functionInvoked each time the chart has finished updating.
Invoked continuously when the chart view changes, e.g. during zooming or panning.
Parameters
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
defaultPrevented
requiredbooleanA read-only value indicating if the default action was prevented.
deltaMode
requirednumberThe unit of measurement for the delta value.
deltaX
requirednumberThe number of units that the wheel scrolled in the x direction.
deltaY
requirednumberThe number of units that the wheel scrolled in the y direction.
modifierKeys
requiredobjectA dictionary detailing which modifier keys were pressed when the event occurred. See Modifier Keys.
preventDefault
requiredfunctionCall to prevent the default action of the event.
x
requirednumberThe x location of the pointer in view coordinates.
y
requirednumberThe y location of the pointer in view coordinates.