Top Related Projects
A graph node engine and editor written in Javascript similar to PD or UDK Blueprints, comes with its own editor in HTML5 Canvas2D. The engine can run client side or server side using Node. It allows to export graphs as JSONs to be included in applications independently.
JavaScript framework for visual programming
a super simple, no-nonsense diagramming library written in react that just works
Websockets for Laravel. Done right.
The minimal javascript library to create flowcharts ✨
Quick Overview
Drawflow is a simple JavaScript library for creating interactive node-based flow diagrams. It allows users to create, connect, and manipulate nodes in a visual interface, making it ideal for building workflow editors, data flow diagrams, or visual programming tools.
Pros
- Lightweight and easy to integrate into existing projects
- Highly customizable with support for custom node templates and styles
- Responsive design that works well on both desktop and mobile devices
- Supports exporting and importing of flow diagrams
Cons
- Limited built-in node types, requiring custom implementation for complex scenarios
- Documentation could be more comprehensive, especially for advanced features
- Lacks some advanced features found in more complex graph libraries
- May require additional work to implement undo/redo functionality
Code Examples
Creating a new Drawflow instance:
const drawflow = new Drawflow(document.getElementById('drawflow'));
drawflow.start();
Adding a new node to the diagram:
drawflow.addNode('my-node', 1, 1, 100, 200, 'my-node', { name: 'Node 1' }, 'Node 1');
Connecting two nodes:
drawflow.addConnection(1, 2, 'output_1', 'input_1');
Exporting the current diagram:
const exportedData = drawflow.export();
console.log(JSON.stringify(exportedData));
Getting Started
- Include the Drawflow library in your HTML:
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/jerosoler/Drawflow/dist/drawflow.min.css">
<script src="https://cdn.jsdelivr.net/gh/jerosoler/Drawflow/dist/drawflow.min.js"></script>
- Create a container element for the diagram:
<div id="drawflow"></div>
- Initialize Drawflow in your JavaScript:
const container = document.getElementById('drawflow');
const drawflow = new Drawflow(container);
drawflow.start();
// Add nodes and connections
drawflow.addNode('my-node', 1, 1, 100, 200, 'my-node', { name: 'Node 1' }, 'Node 1');
drawflow.addNode('my-node', 2, 1, 400, 200, 'my-node', { name: 'Node 2' }, 'Node 2');
drawflow.addConnection(1, 2, 'output_1', 'input_1');
This will create a basic Drawflow diagram with two connected nodes. You can further customize the appearance and behavior of the nodes and connections using the library's API.
Competitor Comparisons
A graph node engine and editor written in Javascript similar to PD or UDK Blueprints, comes with its own editor in HTML5 Canvas2D. The engine can run client side or server side using Node. It allows to export graphs as JSONs to be included in applications independently.
Pros of litegraph.js
- More feature-rich with advanced node types and complex graph operations
- Better performance for large-scale graphs with many nodes and connections
- Supports subgraphs and nested nodes for more complex workflows
Cons of litegraph.js
- Steeper learning curve due to more complex API and features
- Less modern UI design compared to Drawflow's sleek interface
- Requires more setup and configuration for basic use cases
Code Comparison
Drawflow basic node creation:
editor.addNode('hello', 1, 1, 100, 200, 'hello', {}, 'Hello');
litegraph.js basic node creation:
var node = LiteGraph.createNode("basic/const");
node.pos = [100,200];
graph.add(node);
Both libraries offer straightforward node creation, but litegraph.js provides more options for customization and advanced node types. Drawflow's API is generally simpler and more intuitive for basic use cases, while litegraph.js offers more flexibility and power for complex graph scenarios.
JavaScript framework for visual programming
Pros of Rete
- More extensive documentation and examples
- Larger community and ecosystem of plugins
- Better support for complex node-based editors
Cons of Rete
- Steeper learning curve
- Heavier and more complex codebase
- May be overkill for simpler flow diagram needs
Code Comparison
Drawflow:
import Drawflow from 'drawflow'
const editor = new Drawflow(document.getElementById('drawflow'));
editor.addNode('hello', 1, 1, 150, 100, 'hello', {}, 'Hello');
Rete:
import { NodeEditor, Engine } from 'rete';
const editor = new NodeEditor('demo@0.1.0', container);
const engine = new Engine('demo@0.1.0');
await editor.fromJSON(data);
await engine.process(editor.toJSON());
Both libraries offer node-based editing capabilities, but Rete provides a more robust framework for complex scenarios. Drawflow is simpler to set up and use for basic flow diagrams, while Rete offers more flexibility and power for advanced use cases. The code comparison shows that Drawflow has a more straightforward initialization process, whereas Rete requires more setup but offers additional features like data processing with its Engine component.
a super simple, no-nonsense diagramming library written in react that just works
Pros of react-diagrams
- Built specifically for React, offering seamless integration with React applications
- Provides a more extensive and flexible API for customizing diagram behavior
- Supports TypeScript out of the box, enhancing type safety and developer experience
Cons of react-diagrams
- Steeper learning curve due to its more complex architecture and API
- Requires more setup and configuration compared to Drawflow's simpler approach
- Less suitable for quick prototyping or simple diagram needs
Code Comparison
Drawflow:
const drawflow = new Drawflow(document.getElementById("drawflow"));
drawflow.start();
drawflow.addNode('hello', 1, 1, 100, 100, 'hello', {}, 'Hello');
react-diagrams:
const engine = new DiagramEngine();
engine.installDefaultFactories();
const model = new DiagramModel();
const node1 = new DefaultNodeModel('Node 1', 'rgb(0,192,255)');
model.addAll(node1);
Summary
Drawflow is simpler to set up and use, making it ideal for quick prototyping and basic diagram needs. react-diagrams offers more flexibility and integration with React applications but requires more setup and has a steeper learning curve. The choice between the two depends on the specific project requirements and the developer's familiarity with React and TypeScript.
Websockets for Laravel. Done right.
Pros of Laravel WebSockets
- Seamless integration with Laravel framework, providing a native WebSocket server solution
- Built-in authentication and authorization mechanisms for secure WebSocket connections
- Supports horizontal scaling and load balancing for high-traffic applications
Cons of Laravel WebSockets
- Limited to Laravel ecosystem, not suitable for non-Laravel projects
- Requires more server resources compared to lightweight JavaScript-based solutions
- Steeper learning curve for developers not familiar with Laravel
Code Comparison
Laravel WebSockets (PHP):
use BeyondCode\LaravelWebSockets\WebSocketsServer;
$server = new WebSocketsServer();
$server->start();
Drawflow (JavaScript):
import Drawflow from 'drawflow';
const drawflow = new Drawflow(document.getElementById('drawflow'));
drawflow.start();
Key Differences
- Laravel WebSockets is a backend WebSocket server solution, while Drawflow is a frontend flow-based programming and diagramming tool
- Laravel WebSockets focuses on real-time communication, whereas Drawflow emphasizes visual node-based workflows
- Laravel WebSockets is tightly integrated with Laravel, while Drawflow is framework-agnostic and can be used in various JavaScript environments
Use Cases
- Laravel WebSockets: Real-time applications, chat systems, live notifications in Laravel projects
- Drawflow: Visual programming interfaces, workflow editors, diagram builders in web applications
The minimal javascript library to create flowcharts ✨
Pros of Flowy
- More visually appealing and modern UI design
- Includes a demo with pre-built blocks for quick start
- Supports touch devices and mobile responsiveness
Cons of Flowy
- Less actively maintained (last update over 3 years ago)
- Fewer customization options and flexibility
- Limited documentation and examples
Code Comparison
Flowy:
flowy.import(output);
flowy.output();
Drawflow:
editor.import(json);
editor.export();
Both libraries offer similar import/export functionality, but Drawflow provides a more comprehensive API with methods like addNode()
, removeNode()
, and clear()
.
Drawflow offers greater flexibility in node creation and customization, while Flowy focuses on a simpler, more visually appealing approach. Drawflow is actively maintained and has more extensive documentation, making it potentially more suitable for complex projects. However, Flowy's modern design and mobile responsiveness may be advantageous for certain use cases.
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
Drawflow
Simple flow library.
Drawflow allows you to create data flows easily and quickly.
Installing only a javascript library and with four lines of code.
â LIVE DEMO
ð¨ THEME EDIT GENERATOR
Table of contents
- Features
- Installation
- Mouse and Keys
- Editor
- Modules
- Nodes
- Methods
- Events
- Export / Import
- Example
- License
Features
- Drag Nodes
- Multiple Inputs / Outputs
- Multiple connections
- Delete Nodes and Connections
- Add/Delete inputs/outputs
- Reroute connections
- Data sync on Nodes
- Zoom in / out
- Clear data module
- Support modules
- Editor mode
edit
,fixed
orview
- Import / Export data
- Events
- Mobile support
- Vanilla javascript (No dependencies)
- NPM
- Vue Support component nodes && Nuxt
Installation
Download or clone repository and copy the dist folder, CDN option Or npm.
Clone
git clone https://github.com/jerosoler/Drawflow.git
CDN
# Last
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/jerosoler/Drawflow/dist/drawflow.min.css">
<script src="https://cdn.jsdelivr.net/gh/jerosoler/Drawflow/dist/drawflow.min.js"></script>
# or version view releases https://github.com/jerosoler/Drawflow/releases
<link rel="stylesheet" href="https://unpkg.com/drawflow@x.x.xx/dist/drawflow.min.css" />
<script src="https://unpkg.com/drawflow@x.x.xx/dist/drawflow.min.js"></script>
NPM
npm i drawflow
Typescript
External package. More info #119
npm install -D @types/drawflow
Import
import Drawflow from 'drawflow'
import styleDrawflow from 'drawflow/dist/drawflow.min.css'
Require
var Drawflow = require('drawflow')
var styleDrawflow = require('drawflow/dist/drawflow.min.css')
Create the parent element of drawflow.
<div id="drawflow"></div>
Running
Start drawflow.
var id = document.getElementById("drawflow");
const editor = new Drawflow(id);
editor.start();
Parameter | Type | Description |
---|---|---|
id | Object | Name of module |
render | Object | It's for Vue . |
parent | Object | It's for Vue . The parent Instance |
For vue 2 example.
import Vue from 'vue'
// Pass render Vue
this.editor = new Drawflow(id, Vue, this);
For vue 3 example.
import { h, getCurrentInstance, render } from 'vue'
const Vue = { version: 3, h, render };
this.editor = new Drawflow(id, Vue);
// Pass render Vue 3 Instance
const internalInstance = getCurrentInstance()
editor.value = new Drawflow(id, Vue, internalInstance.appContext.app._context);
Nuxt
Add to nuxt.config.js
file
build: {
transpile: ['drawflow'],
...
}
Mouse and Keys
del key
to remove element.Right click
to show remove options (Mobile long press).Left click press
to move editor or node selected.Ctrl + Mouse Wheel
Zoom in/out (Mobile pinch).
Editor
You can change the editor to fixed type to block. Only editor can be moved. You can put it before start.
editor.editor_mode = 'edit'; // Default
editor.editor_mode = 'fixed'; // Only scroll
You can also adjust the zoom values.
editor.zoom_max = 1.6;
editor.zoom_min = 0.5;
editor.zoom_value = 0.1;
Editor options
Parameter | Type | Default | Description |
---|---|---|---|
reroute | Boolean | false | Active reroute |
reroute_fix_curvature | Boolean | false | Fix adding points |
curvature | Number | 0.5 | Curvature |
reroute_curvature_start_end | Number | 0.5 | Curvature reroute first point and las point |
reroute_curvature | Number | 0.5 | Curvature reroute |
reroute_width | Number | 6 | Width of reroute |
line_path | Number | 5 | Width of line |
force_first_input | Boolean | false | Force the first input to drop the connection on top of the node |
editor_mode | Text | edit | edit for edit, fixed for nodes fixed but their input fields available, view for view only |
zoom | Number | 1 | Default zoom |
zoom_max | Number | 1.6 | Default zoom max |
zoom_min | Number | 0.5 | Default zoom min |
zoom_value | Number | 0.1 | Default zoom value update |
zoom_last_value | Number | 1 | Default zoom last value |
draggable_inputs | Boolean | true | Drag nodes on click inputs |
useuuid | Boolean | false | Use UUID as node ID instead of integer index. Only affect newly created nodes, do not affect imported nodes |
Reroute
Active reroute connections. Use before start
or import
.
editor.reroute = true;
Create point with double click on line connection. Double click on point for remove.
Modules
Separate your flows in different editors.
editor.addModule('nameNewModule');
editor.changeModule('nameNewModule');
editor.removeModule('nameModule');
// Default Module is Home
editor.changeModule('Home');
RemovedModule
if it is in the same module redirects to the Home
module
Nodes
Adding a node is simple.
editor.addNode(name, inputs, outputs, posx, posy, class, data, html);
Parameter | Type | Description |
---|---|---|
name | text | Name of module |
inputs | number | Number of de inputs |
outputs | number | Number of de outputs |
pos_x | number | Position on start node left |
pos_y | number | Position on start node top |
class | text | Added classname to de node. Multiple classnames separated by space |
data | json | Data passed to node |
html | text | HTML drawn on node or name of register node. |
typenode | boolean & text | Default false , true for Object HTML, vue for vue |
You can use the attribute df-*
in inputs, textarea or select to synchronize with the node data and contenteditable.
Atrributs multiples parents support df-*-*...
Node example
var html = `
<div><input type="text" df-name></div>
`;
var data = { "name": '' };
editor.addNode('github', 0, 1, 150, 300, 'github', data, html);
Register Node
it's possible register nodes for reuse.
var html = document.createElement("div");
html.innerHTML = "Hello Drawflow!!";
editor.registerNode('test', html);
// Use
editor.addNode('github', 0, 1, 150, 300, 'github', data, 'test', true);
// For vue
import component from '~/components/testcomponent.vue'
editor.registerNode('name', component, props, options);
// Use for vue
editor.addNode('github', 0, 1, 150, 300, 'github', data, 'name', 'vue');
Parameter | Type | Description |
---|---|---|
name | text | Name of module registered. |
html | text | HTML to drawn or vue component. |
props | json | Only for vue . Props of component. Not Required |
options | json | Only for vue . Options of component. Not Required |
Methods
Other available functions.
Mehtod | Description |
---|---|
zoom_in() | Increment zoom +0.1 |
zoom_out() | Decrement zoom -0.1 |
getNodeFromId(id) | Get Info of node. Ex: id: 5 |
getNodesFromName(name) | Return Array of nodes id. Ex: name: telegram |
removeNodeId(id) | Remove node. Ex id: node-x |
updateNodeDataFromId | Update data element. Ex: 5, { name: 'Drawflow' } |
addNodeInput(id) | Add input to node. Ex id: 5 |
addNodeOutput(id) | Add output to node. Ex id: 5 |
removeNodeInput(id, input_class) | Remove input to node. Ex id: 5 , input_2 |
removeNodeOutput(id, output_class) | Remove output to node. Ex id: 5 , output_2 |
addConnection(id_output, id_input, output_class, input_class) | Add connection. Ex: 15,16,'output_1','input_1' |
removeSingleConnection(id_output, id_input, output_class, input_class) | Remove connection. Ex: 15,16,'output_1','input_1' |
updateConnectionNodes(id) | Update connections position from Node Ex id: node-x |
removeConnectionNodeId(id) | Remove node connections. Ex id: node-x |
getModuleFromNodeId(id) | Get name of module where is the id. Ex id: 5 |
clearModuleSelected() | Clear data of module selected |
clear() | Clear all data of all modules and modules remove. |
Methods example
editor.removeNodeId('node-4');
Events
You can detect events that are happening.
List of available events:
Event | Return | Description |
---|---|---|
nodeCreated | id | id of Node |
nodeRemoved | id | id of Node |
nodeDataChanged | id | id of Node df-* attributes changed. |
nodeSelected | id | id of Node |
nodeUnselected | true | Unselect node |
nodeMoved | id | id of Node |
connectionStart | { output_id, output_class } | id of nodes and output selected |
connectionCancel | true | Connection Cancel |
connectionCreated | { output_id, input_id, output_class, input_class } | id 's of nodes and output/input selected |
connectionRemoved | { output_id, input_id, output_class, input_class } | id 's of nodes and output/input selected |
connectionSelected | { output_id, input_id, output_class, input_class } | id 's of nodes and output/input selected |
connectionUnselected | true | Unselect connection |
addReroute | id | id of Node output |
removeReroute | id | id of Node output |
rerouteMoved | id | id of Node output |
moduleCreated | name | name of Module |
moduleChanged | name | name of Module |
moduleRemoved | name | name of Module |
click | event | Click event |
clickEnd | event | Once the click changes have been made |
contextmenu | event | Click second button mouse event |
mouseMove | { x, y } | Position |
mouseUp | event | MouseUp Event |
keydown | event | Keydown event |
zoom | zoom_level | Level of zoom |
translate | { x, y } | Position translate editor |
import | import | Finish import |
export | data | Data export |
Events example
editor.on('nodeCreated', function(id) {
console.log("Node created " + id);
})
Export / Import
You can export and import your data.
var exportdata = editor.export();
editor.import(exportdata);
Export example
Example of exported data:
{
"drawflow": {
"Home": {
"data": {}
},
"Other": {
"data": {
"16": {
"id": 16,
"name": "facebook",
"data": {},
"class": "facebook",
"html": "\n
\n
Facebook Message
\n
\n ",
"inputs": {},
"outputs": {
"output_1": {
"connections": [
{
"node": "17",
"output": "input_1"
}
]
}
},
"pos_x": 226,
"pos_y": 138
},
"17": {
"id": 17,
"name": "log",
"data": {},
"class": "log",
"html": "\n
\n
Save log file
\n
\n ",
"inputs": {
"input_1": {
"connections": [
{
"node": "16",
"input": "output_1"
}
]
}
},
"outputs": {},
"pos_x": 690,
"pos_y": 129
}
}
}
}
}
Example
View the complete example in folder docs.
There is also an example how to use Drawflow in a custom element. (based on LitElement).
License
MIT License
Top Related Projects
A graph node engine and editor written in Javascript similar to PD or UDK Blueprints, comes with its own editor in HTML5 Canvas2D. The engine can run client side or server side using Node. It allows to export graphs as JSONs to be included in applications independently.
JavaScript framework for visual programming
a super simple, no-nonsense diagramming library written in react that just works
Websockets for Laravel. Done right.
The minimal javascript library to create flowcharts ✨
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