ajainarayanan / react-dag

This is a base implementation of wrapping jsplumb with react to be more usable in a react based environment
MIT License
159 stars 39 forks source link
dag jsplumb react

React-dag

Imgur

React wrapper for jsplumb. Helps in rendering a Directed Acyclic Graph.

A demo of this module being used can be found here Demo.

Install

npm install react-dag

Usage

  import ReactDAG from "react-dag";
  class MyComponent extends Component {
    ...
    render() {
      return (
        <ReactDAG
          nodes={cloneDeep(this.state.nodes)}
          connections={cloneDeep(this.state.connections)}
          jsPlumbSettings={defaultSettings}
          connectionDecoders={[
            transformConnectionDecoder,
            conditionConnectionDecoder,
          ]}
          connectionEncoders={[
            transformConnectionEncoder,
            conditionConnectionEncoder,
          ]}
          onChange={({
            nodes: n,
            connections: c,
          }: {
            nodes: INode[];
            connections: IConnectionParams[];
          }) => {
            this.setState({ nodes: n, connections: c });
          }}
          eventListeners={eventListeners}
          registerTypes={registerTypes}
          zoom={this.state.zoom}
        >
          {this.state.nodes.map((node, i) => {
            const Component = getComponent(node.config ? node.config.type : "");
            return <Component key={i} id={node.id} />;
          })}
        </ReactDAG>
      );
    }
  }

Older version docs:

For older version (version 1.x) please follow the readme here README. Since this is a re-write the API is completely different and includes for a lot of additional functionality not available in the previous version

Props