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
-
object An object describing the change.
object 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.
object Contains the positions of all nodes in the chart.
object Indicates which items are currently selected.
object The current view settings.
Chart Mode
required unknown '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.
defaultPrevented
required 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.
modifierKeys
required 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.
preventDefault
required 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
- summaryDefinition required
-
object An object describing the summary link and its contents.
id
required string The default id for this summary link. This can be overridden in the summary link setStyle function.
id1
required string The id at one end of the summary link. Note this can be the id of a combo or a node.
id2
required string The id at the other end of the summary link. Note this can be the id of a combo or a node.
links
required object A dictionary of objects describing the content links inside this summary link.
setStyle
required function Use 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
-
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.
defaultPrevented
required 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.
modifierKeys
required 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.
preventDefault
required 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.
modifierKeys
required 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.
draggedItems
required 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.
modifierKeys
required 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.
defaultPrevented
required boolean A read-only value indicating if the default action was prevented.
draggedItems
required 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.
modifierKeys
required 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.
preventDefault
required 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.
draggedItems
required 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.
modifierKeys
required 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.
defaultPrevented
required boolean A read-only value indicating if the default action was prevented.
draggedItems
required 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.
modifierKeys
required 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.
preventDefault
required function Call to prevent the default action of the event.
setDragOptions
required 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.
modifierKeys
required 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 - items required
-
[id: string]: Node | Link | Annotation A dictionary of items.
An object with node, link, or annotation properties to be applied.
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.
item
required Node | Link | Annotation | ComboStyle | Summary 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.
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
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
-
object An object describing the aggregate link and its contents.
aggregateByDirection
required 'none' | 'both' | 'from' | 'to' | undefined The arrow direction of the child links, when aggregateByDirection: true. Otherwise is undefined.
aggregateByValue
required 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.
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.
modifierKeys
required 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.
modifierKeys
required 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.
modifierKeys
required 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.
function Invoked 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
required 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.
modifierKeys
required object A dictionary detailing which modifier keys were pressed when the event occurred. See Modifier Keys.
preventDefault
required 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.