reaflow
🎯 React library for building workflow editors, flow charts and diagrams. Maintained by @goodcodeus.
Top Related Projects
🚀 JavaScript diagramming library that uses SVG and HTML for rendering.
a super simple, no-nonsense diagramming library written in react that just works
React Flow | Svelte Flow - Powerful open source libraries for building node-based UIs with React (https://reactflow.dev) or Svelte (https://svelteflow.dev). Ready out-of-the-box and infinitely customizable.
Directed graph layout for JavaScript
Graph theory (network) library for visualisation and analysis
mxGraph is a fully client side JavaScript diagramming library
Quick Overview
Reaflow is a React-based library for creating interactive and customizable flow diagrams. It provides a set of components and utilities to build complex flow-based applications, such as workflow management systems, process automation tools, and visual programming interfaces.
Pros
- Highly Customizable: Reaflow offers a wide range of customization options, allowing developers to tailor the appearance and behavior of the flow diagrams to their specific needs.
- Reactive and Interactive: The library uses a reactive approach, ensuring that the flow diagrams update in real-time as the underlying data changes.
- Comprehensive Feature Set: Reaflow includes a variety of features, such as node and edge editing, zooming, panning, and automatic layout algorithms.
- Extensible and Modular: The library is designed to be modular, making it easy to extend with custom components and functionality.
Cons
- Learning Curve: Reaflow has a relatively steep learning curve, especially for developers who are new to flow-based programming and visualization.
- Performance Concerns: Depending on the complexity of the flow diagrams, the library may experience performance issues, especially when dealing with large datasets.
- Limited Documentation: The project's documentation could be more comprehensive, making it challenging for new users to get started.
- Dependency on React: Reaflow is tightly coupled with the React ecosystem, which may be a limitation for developers working with other JavaScript frameworks or libraries.
Code Examples
Here are a few code examples demonstrating the usage of Reaflow:
import React from 'react';
import { Reaflow, Node, Edge } from 'reaflow';
const MyFlow = () => {
const nodes = [
{ id: 'node1', label: 'Start' },
{ id: 'node2', label: 'Process' },
{ id: 'node3', label: 'End' },
];
const edges = [
{ id: 'edge1', source: 'node1', target: 'node2' },
{ id: 'edge2', source: 'node2', target: 'node3' },
];
return (
<Reaflow
nodes={nodes}
edges={edges}
defaultZoom={1}
defaultPosition={{ x: 0, y: 0 }}
>
<Node />
<Edge />
</Reaflow>
);
};
export default MyFlow;
This example demonstrates the basic setup of a flow diagram using Reaflow, including the definition of nodes and edges.
import React from 'react';
import { Reaflow, Node, Edge, useZoomPan } from 'reaflow';
const MyCustomizedFlow = () => {
const { zoomIn, zoomOut, pan } = useZoomPan();
return (
<Reaflow
nodes={nodes}
edges={edges}
defaultZoom={1}
defaultPosition={{ x: 0, y: 0 }}
>
<Node
render={(props) => (
<rect
x={props.x}
y={props.y}
width={100}
height={50}
fill="#4CAF50"
stroke="#333"
strokeWidth={2}
/>
)}
/>
<Edge
render={(props) => (
<path
d={props.path}
fill="none"
stroke="#333"
strokeWidth={2}
markerEnd="url(#arrow)"
/>
)}
/>
<div style={{ position: 'absolute', top: 10, left: 10 }}>
<button onClick={zoomIn}>Zoom In</button>
<button onClick={zoomOut}>Zoom Out</button>
<button
onMouseDown={(e) => pan({ x: e.clientX, y: e.clientY })}
onMouseUp={() => pan(null)}
>
Pan
</button>
</div>
</Reaflow>
);
};
export default MyCustomize
Competitor Comparisons
🚀 JavaScript diagramming library that uses SVG and HTML for rendering.
Pros of X6
- More comprehensive and feature-rich, offering a wider range of graph types and customization options
- Better performance for large-scale graphs with thousands of nodes and edges
- Extensive documentation and examples, making it easier for developers to get started
Cons of X6
- Steeper learning curve due to its complexity and extensive API
- Larger bundle size, which may impact load times for web applications
- Less focused on React integration compared to Reaflow
Code Comparison
X6:
import { Graph } from '@antv/x6';
const graph = new Graph({
container: document.getElementById('container'),
width: 800,
height: 600,
});
graph.fromJSON(data);
Reaflow:
import { Canvas, Node, Edge } from 'reaflow';
<Canvas nodes={nodes} edges={edges}>
{nodes.map((node) => (
<Node key={node.id} {...node} />
))}
{edges.map((edge) => (
<Edge key={edge.id} {...edge} />
))}
</Canvas>
X6 uses a more imperative approach with a Graph instance, while Reaflow follows a declarative React-style syntax. X6 offers more flexibility but requires more setup, whereas Reaflow provides a simpler, React-centric implementation.
a super simple, no-nonsense diagramming library written in react that just works
Pros of react-diagrams
- More mature and feature-rich library with a larger community
- Offers advanced features like custom link routing and port management
- Provides a powerful engine for complex diagram interactions
Cons of react-diagrams
- Steeper learning curve due to its complexity
- Heavier bundle size, which may impact performance for simpler use cases
- Less frequent updates and maintenance compared to reaflow
Code Comparison
react-diagrams:
import { DiagramEngine, DiagramModel, DefaultNodeModel } from '@projectstorm/react-diagrams';
const engine = new DiagramEngine();
const model = new DiagramModel();
const node1 = new DefaultNodeModel('Node 1', 'rgb(0,192,255)');
node1.setPosition(100, 100);
model.addNode(node1);
reaflow:
import { Canvas, Node } from 'reaflow';
<Canvas>
<Node id="1" text="Node 1" />
</Canvas>
Summary
react-diagrams offers more advanced features and flexibility for complex diagram scenarios, while reaflow provides a simpler API and lighter weight solution for basic flowchart needs. The choice between the two depends on the specific requirements of your project and the level of complexity you need to handle.
React Flow | Svelte Flow - Powerful open source libraries for building node-based UIs with React (https://reactflow.dev) or Svelte (https://svelteflow.dev). Ready out-of-the-box and infinitely customizable.
Pros of xyflow
- More active development with frequent updates and releases
- Larger community and ecosystem, with more examples and third-party resources
- Better TypeScript support and type definitions
Cons of xyflow
- Steeper learning curve due to more complex API and features
- Larger bundle size, which may impact performance in some applications
Code Comparison
xyflow:
import ReactFlow from 'reactflow';
const elements = [
{ id: '1', type: 'input', data: { label: 'Node 1' }, position: { x: 250, y: 5 } },
{ id: '2', data: { label: 'Node 2' }, position: { x: 100, y: 100 } },
{ id: 'e1-2', source: '1', target: '2', animated: true },
];
function Flow() {
return <ReactFlow elements={elements} />;
}
reaflow:
import { Canvas, Node, Edge } from 'reaflow';
const nodes = [
{ id: '1', text: 'Node 1' },
{ id: '2', text: 'Node 2' },
];
const edges = [
{ id: 'e1-2', from: '1', to: '2' },
];
function Flow() {
return (
<Canvas nodes={nodes} edges={edges}>
{nodes.map((node) => (
<Node key={node.id} {...node} />
))}
{edges.map((edge) => (
<Edge key={edge.id} {...edge} />
))}
</Canvas>
);
}
Directed graph layout for JavaScript
Pros of dagre
- More mature and widely adopted project with a larger community
- Supports a broader range of graph layouts and algorithms
- Better performance for large and complex graphs
Cons of dagre
- Less active development and maintenance in recent years
- Steeper learning curve and more complex API
- Limited built-in interactivity features
Code Comparison
dagre:
var g = new dagre.graphlib.Graph();
g.setNode("a", { label: "A" });
g.setNode("b", { label: "B" });
g.setEdge("a", "b");
dagre.layout(g);
reaflow:
<Canvas
nodes={[
{ id: "1", text: "Node 1" },
{ id: "2", text: "Node 2" }
]}
edges={[{ id: "1-2", from: "1", to: "2" }]}
/>
reaflow offers a more React-friendly approach with declarative syntax, while dagre provides a lower-level API for graph manipulation and layout. reaflow is better suited for React applications with interactive graph requirements, whereas dagre is more flexible and powerful for complex graph layouts and algorithms across various JavaScript environments.
Graph theory (network) library for visualisation and analysis
Pros of Cytoscape.js
- More mature and feature-rich library with extensive documentation
- Supports a wider range of graph types and layouts
- Larger community and ecosystem with numerous extensions
Cons of Cytoscape.js
- Steeper learning curve due to its complexity
- Heavier library size, which may impact performance for simpler use cases
- Less focused on React integration compared to Reaflow
Code Comparison
Reaflow (React-based):
import { Canvas, Node, Edge } from 'reaflow';
<Canvas
nodes={[{ id: '1' }, { id: '2' }]}
edges={[{ id: 'e1-2', from: '1', to: '2' }]}
/>
Cytoscape.js (Vanilla JavaScript):
const cy = cytoscape({
container: document.getElementById('cy'),
elements: [
{ data: { id: '1' } },
{ data: { id: '2' } },
{ data: { id: 'e1-2', source: '1', target: '2' } }
]
});
Both libraries offer powerful graph visualization capabilities, but Reaflow is more tailored for React applications with a simpler API, while Cytoscape.js provides a more comprehensive set of features for complex graph scenarios across various JavaScript environments.
mxGraph is a fully client side JavaScript diagramming library
Pros of mxgraph
- More mature and feature-rich library with extensive documentation
- Supports a wider range of graph types and layouts
- Offers both client-side and server-side rendering options
Cons of mxgraph
- Larger file size and potentially slower performance
- Steeper learning curve due to its complexity
- Less modern API and syntax compared to React-based libraries
Code Comparison
mxgraph:
var graph = new mxGraph(container);
var parent = graph.getDefaultParent();
graph.getModel().beginUpdate();
try {
var v1 = graph.insertVertex(parent, null, 'Hello,', 20, 20, 80, 30);
var v2 = graph.insertVertex(parent, null, 'World!', 200, 150, 80, 30);
var e1 = graph.insertEdge(parent, null, '', v1, v2);
} finally {
graph.getModel().endUpdate();
}
reaflow:
import { Canvas, Node, Edge } from 'reaflow';
const MyGraph = () => (
<Canvas>
<Node id="1" text="Hello," x={20} y={20} />
<Node id="2" text="World!" x={200} y={150} />
<Edge from="1" to="2" />
</Canvas>
);
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
REAFLOW is a modular diagram engine for building static or interactive editors. The library is feature-rich and modular allowing for displaying complex visualizations with total customizability.
ð Quick Links
- Checkout the docs and demos
- Learn about updates from the Changelog
ð Other Projects
- Reagraph - Open-source library for large webgl based network graphs.
- Reablocks - Open-source component library for React based on Tailwind.
- Reaviz - Open-source library for data visulizations for React.
- Reachat - Open-source library for building LLM/Chat UIs for React.
⨠Features
- Complex automatic layout leveraging ELKJS
- Easy Node/Edge/Port customizations
- Zooming / Panning / Centering controls
- Drag and drop Node/Port connecting and rearranging
- Nesting of Nodes/Edges
- Proximity based Node linking helper
- Node/Edge selection helper
- Undo/Redo helper
ð¦ Usage
Install the package via NPM:
npm i reaflow --save
Install the package via Yarn:
yarn add reaflow
Import the component into your app and add some nodes and edges:
import React from 'react';
import { Canvas } from 'reaflow';
export default () => (
<Canvas
maxWidth={800}
maxHeight={600}
nodes={[
{
id: '1',
text: '1'
},
{
id: '2',
text: '2'
}
]}
edges={[
{
id: '1-2',
from: '1',
to: '2'
}
]}
/>
);
ð Development
If you want to run reaflow locally, its super easy!
- Clone the repo
npm i
npm start
- Browser opens to Storybook page
â¤ï¸ Contributors
Thanks to all our contributors!
Top Related Projects
🚀 JavaScript diagramming library that uses SVG and HTML for rendering.
a super simple, no-nonsense diagramming library written in react that just works
React Flow | Svelte Flow - Powerful open source libraries for building node-based UIs with React (https://reactflow.dev) or Svelte (https://svelteflow.dev). Ready out-of-the-box and infinitely customizable.
Directed graph layout for JavaScript
Graph theory (network) library for visualisation and analysis
mxGraph is a fully client side JavaScript diagramming library
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot