When building ReGraph into your applications, you may be interested in automated integration testing. ReGraph has a number of helpful APIs available to give you information about the items in the chart.
Chart events
The onUpdateComplete event is invoked each time the chart has finished updating. Use this event e.g. to check when the chart animation is complete. This event is also suitable for production.
Chart instance methods
The following functions, currently all in beta, are particularly useful for use in integration tests. To use them, give access to the chart by exposing your chart's ref on the window:
const MyFunctionalComponent = (props) => {
const { items } = props;
const chartRef = React.useRef(null);
// expose the ref on the top-most window
window.top.chart = chartRef
return (
<Chart
ref={chartRef}
items={items}
/>
);
}; Then you can use them in your tests:
const item = window.chart.current.getItemInfo('node1'); See also Instance Methods for more information.
getItemAtViewCoordinates
The getItemAtViewCoordinates instance method returns an object with information about the item or sub-item at the specified view coordinates.
getItemInfo
The getItemInfo instance method returns a list of all chart items, or details of a specified item if a valid id is passed.
getViewCoordinatesOfItem
The getViewCoordinatesOfItem instance method returns an object with view coordinates of the specified item or sub-item.