Drawflow
Simple flow library
README
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.
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 or view
- 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
- ```html
- # 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
- ```javascript
- npm i drawflow
- ```
Typescript
External package. More info #119
- ```javascript
- npm install -D @types/drawflow
- ```
Import
- ```javascript
- import Drawflow from 'drawflow'
- import styleDrawflow from 'drawflow/dist/drawflow.min.css'
- ```
Require
- ```javascript
- var Drawflow = require('drawflow')
- var styleDrawflow = require('drawflow/dist/drawflow.min.css')
- ```
Create the parent element of drawflow.
- ```html
- <div id="drawflow"></div>
- ```
Running
Start drawflow.
- ```javascript
- 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.
- ```javascript
- import Vue from 'vue'
- // Pass render Vue
- this.editor = new Drawflow(id, Vue, this);
- ```
For vue 3 example.
- ```javascript
- 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
- ```javascript
- 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.
- ```javascript
- editor.editor_mode = 'edit'; // Default
- editor.editor_mode = 'fixed'; // Only scroll
- ```
You can also adjust the zoom values.
- ```javascript
- 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.
- ```javascript
- editor.reroute = true;
- ```
Create point with double click on line connection. Double click on point for remove.
Modules
Separate your flows in different editors.
- ```javascript
- 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