Top Related Projects
Visual connectivity for webapps
a super simple, no-nonsense diagramming library written in react that just works
🚀 JavaScript diagramming library that uses SVG and HTML for rendering.
JavaScript framework for visual programming
Simple flow library 🖥️🖱️
mxGraph is a fully client side JavaScript diagramming library
Quick Overview
Flowy is a JavaScript library for creating flowcharts and diagrams with a simple drag-and-drop interface. It allows users to build visual representations of processes, workflows, or decision trees easily within web applications.
Pros
- Easy to integrate into existing web projects
- Customizable appearance and behavior
- Responsive design that works well on various devices
- Lightweight with minimal dependencies
Cons
- Limited built-in node types and connectors
- Documentation could be more comprehensive
- Lacks advanced features found in some commercial alternatives
- May require additional styling for a polished look
Code Examples
Creating a basic Flowy instance:
const flowy = new Flowy(document.getElementById("canvas"), onGrab, onRelease, onSnap, onRearrange, spacing_x, spacing_y);
Adding a new block to the canvas:
flowy.addBlock('<div>New Block</div>', 0, 1);
Getting the current flowchart data:
const output = flowy.output();
console.log(JSON.stringify(output));
Getting Started
- Include the Flowy library in your HTML:
<script src="https://cdn.jsdelivr.net/gh/alyssaxuu/flowy/flowy.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/alyssaxuu/flowy/flowy.min.css">
- Create a container for the flowchart:
<div id="canvas"></div>
- Initialize Flowy in your JavaScript:
document.addEventListener("DOMContentLoaded", function() {
const flowy = new Flowy(document.getElementById("canvas"), function(block) {
// Callback when a block is grabbed
}, function(block) {
// Callback when a block is released
}, function(block, first, parent) {
// Callback when a block snaps with another one
}, function(block) {
// Callback when a block is rearranged
});
});
- Add blocks and customize as needed:
flowy.addBlock('<div class="block">Start</div>', 0, 1);
Competitor Comparisons
Visual connectivity for webapps
Pros of jsPlumb
- More mature and feature-rich library with extensive documentation
- Supports various types of connectors and endpoints
- Highly customizable with a wide range of styling options
Cons of jsPlumb
- Steeper learning curve due to its complexity
- Larger file size, which may impact page load times
- Requires more setup and configuration for basic functionality
Code Comparison
Flowy:
flowy.beginDrag(block);
flowy.endDrag(block);
flowy.addBlock(block, x, y);
jsPlumb:
jsPlumb.connect({
source: "element1",
target: "element2",
anchor: ["Top", "Bottom"]
});
Summary
Flowy is a lightweight and user-friendly library for creating flowcharts and diagrams, ideal for simpler projects or those new to diagramming libraries. It offers an intuitive drag-and-drop interface with minimal setup.
jsPlumb, on the other hand, is a more powerful and versatile library suitable for complex diagramming needs. It provides advanced features and customization options but requires more time to learn and implement effectively.
Choose Flowy for quick, straightforward flowcharts, or opt for jsPlumb when you need extensive control over your diagrams and connections.
a super simple, no-nonsense diagramming library written in react that just works
Pros of react-diagrams
- More robust and feature-rich, suitable for complex diagramming needs
- Better TypeScript support and stronger typing
- Active development with frequent updates and community contributions
Cons of react-diagrams
- Steeper learning curve due to its complexity and extensive API
- Heavier bundle size, which may impact performance in smaller projects
- Less intuitive for simple flowchart creation compared to Flowy
Code Comparison
react-diagrams:
import createEngine, { DiagramModel, DefaultNodeModel } from '@projectstorm/react-diagrams';
const engine = createEngine();
const model = new DiagramModel();
const node1 = new DefaultNodeModel('Node 1', 'rgb(0,192,255)');
node1.setPosition(100, 100);
model.addAll(node1);
Flowy:
import Flowy from 'flowy';
const flowy = new Flowy(document.getElementById('canvas'));
flowy.addBlock({
id: 'node1',
title: 'Node 1',
position: { x: 100, y: 100 }
});
Both libraries offer diagramming capabilities, but react-diagrams provides more advanced features and customization options at the cost of complexity. Flowy focuses on simplicity and ease of use for basic flowchart creation. The choice between them depends on the specific project requirements and the level of diagramming complexity needed.
🚀 JavaScript diagramming library that uses SVG and HTML for rendering.
Pros of X6
- More comprehensive and feature-rich library for graph visualization and interaction
- Extensive documentation and examples available
- Supports various graph types and customization options
Cons of X6
- Steeper learning curve due to its complexity
- Larger file size and potentially heavier performance impact
Code Comparison
Flowy:
var flowy = new Flowy(document.getElementById("canvas"), onGrab, onRelease, onSnap, spacing_x, spacing_y);
flowy.addBlock(blockElement, x, y);
X6:
import { Graph } from '@antv/x6';
const graph = new Graph({
container: document.getElementById('container'),
width: 800,
height: 600,
});
graph.addNode({ x: 100, y: 100, width: 80, height: 40, label: 'Hello' });
Summary
X6 is a more powerful and versatile graph visualization library compared to Flowy. It offers a wider range of features and customization options, making it suitable for complex graph-based applications. However, this comes at the cost of a steeper learning curve and potentially higher resource usage. Flowy, on the other hand, is simpler and more focused on creating flowchart-like interfaces with a drag-and-drop approach. The choice between the two depends on the specific requirements of your project and the level of complexity you need in your graph visualizations.
JavaScript framework for visual programming
Pros of Rete
- More feature-rich and flexible, supporting complex node-based visual programming
- Active development with frequent updates and a larger community
- Extensive documentation and examples for various use cases
Cons of Rete
- Steeper learning curve due to its complexity and advanced features
- Heavier and potentially slower for simpler flowchart applications
- Requires more setup and configuration for basic use cases
Code Comparison
Flowy:
new Flowy(document.getElementById("canvas"), onGrab, onRelease, onSnap, spacing_x, spacing_y);
Rete:
const editor = new Rete.NodeEditor('demo@0.1.0', container);
const engine = new Rete.Engine('demo@0.1.0');
await editor.fromJSON(data);
await engine.process(editor.toJSON());
Summary
Flowy is a lightweight, easy-to-use flowchart library focused on simplicity and quick implementation. It's ideal for basic flowcharts and simple drag-and-drop interfaces. Rete, on the other hand, is a more powerful and versatile framework for building complex node-based editors and visual programming tools. While Rete offers more advanced features and flexibility, it comes with a steeper learning curve and may be overkill for simpler projects where Flowy would suffice.
Simple flow library 🖥️🖱️
Pros of Drawflow
- More active development with recent updates and bug fixes
- Supports custom node types and allows for more complex workflows
- Better documentation and examples for integration
Cons of Drawflow
- Steeper learning curve due to more advanced features
- Larger file size and potentially higher performance overhead
- Less focus on visual aesthetics compared to Flowy
Code Comparison
Flowy:
const flow = new Flowy(document.getElementById("canvas"));
flow.addBlock("Start", "start", {x: 100, y: 100});
flow.addBlock("Process", "process", {x: 300, y: 100});
flow.addConnection("Start", "Process");
Drawflow:
const drawflow = new Drawflow(document.getElementById('drawflow'));
drawflow.addNode('start', 1, 1, 100, 100, 'start', {}, 'Start');
drawflow.addNode('process', 1, 1, 300, 100, 'process', {}, 'Process');
drawflow.addConnection(1, 2, 'output_1', 'input_1');
Both libraries offer similar functionality for creating flowcharts and diagrams, but Drawflow provides more advanced features and customization options at the cost of simplicity. Flowy focuses on ease of use and visual appeal, making it more suitable for simpler projects or rapid prototyping.
mxGraph is a fully client side JavaScript diagramming library
Pros of mxgraph
- More comprehensive and feature-rich diagramming library
- Supports a wider range of diagram types and use cases
- Better documentation and extensive examples
Cons of mxgraph
- Steeper learning curve due to its complexity
- Larger file size and potentially heavier performance impact
- Less modern and intuitive API compared to Flowy
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();
}
Flowy:
var flowy = new Flowy(document.getElementById("canvas"));
flowy.addBlock({
id: 1,
title: "Hello,",
position: { x: 20, y: 20 }
});
flowy.addBlock({
id: 2,
title: "World!",
position: { x: 200, y: 150 }
});
flowy.addConnection(1, 2);
The code comparison shows that mxgraph requires more setup and has a more verbose API, while Flowy offers a simpler and more intuitive approach to creating diagrams. However, mxgraph's complexity allows for greater customization and advanced features.
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
Flowy
A javascript library to create pretty flowcharts with ease â¨
Dribbble | Twitter | Live demo
Flowy makes creating WebApps with flowchart functionality an incredibly simple task. Build automation software, mind mapping tools, or simple programming platforms in minutes by implementing the library into your project.
You can support this project (and many others) through GitHub Sponsors! â¤ï¸
Made by Alyssa X
Table of contents
Features
Currently, Flowy supports the following:
- Responsive drag and drop
- Automatic snapping
- Automatic scrolling
- Block rearrangement
- Delete blocks
- Automatic block centering
- Conditional snapping
- Conditional block removal
- Import saved files
- Mobile support
- Vanilla javascript (no dependencies)
- npm install
You can suggest new features here
Installation
Adding Flowy to your WebApp is incredibly simple:
- Link
flowy.min.js
andflowy.min.css
to your project. Through jsDelivr:
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/alyssaxuu/flowy/flowy.min.css">
<script src="https://cdn.jsdelivr.net/gh/alyssaxuu/flowy/flowy.min.js"></script>
- Create a canvas element that will contain the flowchart (for example,
<div id="canvas"></div>
) - Create the draggable blocks with the
.create-flowy
class (for example,<div class="create-flowy">Grab me</div>
)
Running Flowy
Initialization
flowy(canvas, ongrab, onrelease, onsnap, onrearrange, spacing_x, spacing_y);
Parameter | Type | Description |
---|---|---|
canvas | javascript DOM element | The element that will contain the blocks |
ongrab | function (optional) | Function that gets triggered when a block is dragged |
onrelease | function (optional) | Function that gets triggered when a block is released |
onsnap | function (optional) | Function that gets triggered when a block snaps with another one |
onrearrange | function (optional) | Function that gets triggered when blocks are rearranged |
spacing_x | integer (optional) | Horizontal spacing between blocks (default 20px) |
spacing_y | integer (optional) | Vertical spacing between blocks (default 80px) |
To define the blocks that can be dragged, you need to add the class .create-flowy
Example
HTML
<div class="create-flowy">The block to be dragged</div>
<div id="canvas"></div>
Javascript
var spacing_x = 40;
var spacing_y = 100;
// Initialize Flowy
flowy(document.getElementById("canvas"), onGrab, onRelease, onSnap, onRearrange, spacing_x, spacing_y);
function onGrab(block){
// When the user grabs a block
}
function onRelease(){
// When the user releases a block
}
function onSnap(block, first, parent){
// When a block snaps with another one
}
function onRearrange(block, parent){
// When a block is rearranged
}
Callbacks
In order to use callbacks, you need to add the functions when initializing Flowy, as explained before.
On grab
function onGrab(block){
// When the user grabs a block
}
Gets triggered when a user grabs a block with the class create-flowy
Parameter | Type | Description |
---|---|---|
block | javascript DOM element | The block that has been grabbed |
On release
function onRelease(){
// When the user lets go of a block
}
Gets triggered when a user lets go of a block, regardless of whether it attaches or even gets released in the canvas.
On snap
function onSnap(block, first, parent){
// When a block can attach to a parent
return true;
}
Gets triggered when a block can attach to another parent block. You can either prevent the attachment, or allow it by using return true;
Parameter | Type | Description |
---|---|---|
block | javascript DOM element | The block that has been grabbed |
first | boolean | If true, the block that has been dragged is the first one in the canvas |
parent | javascript DOM element | The parent the block can attach to |
On rearrange
function onRearrange(block, parent){
// When a block is rearranged
return true;
}
Gets triggered when blocks are rearranged and are dropped anywhere in the canvas, without a parent to attach to. You can either allow the blocks to be deleted, or prevent it and thus have them re-attach to their previous parent using return true;
Parameter | Type | Description |
---|---|---|
block | javascript DOM element | The block that has been grabbed |
parent | javascript DOM element | The parent the block can attach to |
Methods
Get the flowchart data
// As an object
flowy.output();
// As a JSON string
JSON.stringify(flowy.output());
The JSON object that gets outputted looks like this:
{
"html": "",
"blockarr": [],
"blocks": [
{
"id": 1,
"parent": 0,
"data": [
{
"name": "blockid",
"value": "1"
}
],
"attr": [
{
"id": "block-id",
"class": "block-class"
}
]
}
]
}
Here's what each property means:
Key | Value type | Description |
---|---|---|
html | string | Contains the canvas data |
blockarr | array | Contains the block array generated by the library (for import purposes) |
blocks | array | Contains the readable block array |
id | integer | Unique value that identifies a block |
parent | integer | The id of the parent a block is attached to (-1 means the block has no parent) |
data | array of objects | An array of all the inputs within a certain block |
name | string | The name attribute of the input |
value | string | The value attribute of the input |
attr | array of objects | Contains all the data attributes of a certain block |
Import the flowchart data
flowy.import(output)
Allows you to import entire flowcharts initially exported using the previous method, flowy.output()
Parameter | Type | Description |
---|---|---|
output | javascript DOM element | The data from flowy.output() |
Warning
This method accepts raw HTML and does not sanitize it, therefore this method is vulnerable to XSS. The only safe use for this method is when the input is absolutely trusted, if the input is not to be trusted the use this method can introduce a vulnerability in your system.
Delete all blocks
To remove all blocks at once use:
flowy.deleteBlocks()
Currently there is no method to individually remove blocks. The only way to go about it is by splitting branches manually.
Feel free to reach out to me through email at hi@alyssax.com or on Twitter if you have any questions or feedback! Hope you find this useful ð
Top Related Projects
Visual connectivity for webapps
a super simple, no-nonsense diagramming library written in react that just works
🚀 JavaScript diagramming library that uses SVG and HTML for rendering.
JavaScript framework for visual programming
Simple flow library 🖥️🖱️
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