Search

Events

Basics

ReGraph comes with a number of default behaviors built in to respond to common user gestures. For example, clicking on a node or a link selects that item (updating selection state and drawing a halo around the selected item).

By passing functions through to the event props, you can both hook in to chart events (to know which item was clicked) and override default behavior (to stop the selection changing).

Event handlers will be called by ReGraph and passed a single object containing all the details of the event. Calling the preventDefault() function in these handlers will override any default behavior.

For example, to respond to the onClick event:

const handleClick = ({ id, x, y, button, subItem }) => {
  // id: the node, link or navigation control that was clicked
  // x, y: the position of the item relative to the view
  // button: the logical mouse button that was clicked
  // subItem: the sub-item that was interacted with
};
<Chart items={items} onClick={handleClick} />;

To prevent an item from being selected on onClick:

const preventSelection = ({ preventDefault }) => {
  preventDefault();
};
<Chart items={items} onClick={preventSelection} />;

p#events-subitems.

Some items on the chart can include sub-items. When you click on a sub-item, like a label,

details about it will be passed to the event handler.

const handleClick = ({ id, x, y, button, subItem }) => {
  if (subItem && subItem.type === "label") {
    // Label was clicked
  }
};
<Chart items={items} onClick={handleClick} />;

Handle errors directly in the event listener:

const handleChange = (change) => {
  try {
    functionWhichMightThrow(change);
  } catch (e) {
    // handle the error
    console.error(e);
  }
};

The only exception to this are errors produced by onCombineNodes and onCombineLinks events. Their errors are logged to the console.

The firing order of chart pointer events is onPointerDown, onPointerMove, onPointerUp, onClick (updates selection), onChange (contains new selection).

See the API Reference for a complete list of events on the chart and time bar component. A detailed description of the sub-item type is available in the sub-item section of the API reference.

See also the interactive Interaction / Events and Time Bar / Events examples.

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.