Convert Figma logo to code with AI

alyssaxuu logoflowy

The minimal javascript library to create flowcharts ✨

11,329
979
11,329
56

Top Related Projects

7,739

Visual connectivity for webapps

a super simple, no-nonsense diagramming library written in react that just works

5,694

🚀 JavaScript diagramming library that uses SVG and HTML for rendering.

10,079

JavaScript framework for visual programming

Simple flow library 🖥️🖱️

6,804

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

  1. 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">
  1. Create a container for the flowchart:
<div id="canvas"></div>
  1. 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
  });
});
  1. Add blocks and customize as needed:
flowy.addBlock('<div class="block">Start</div>', 0, 1);

Competitor Comparisons

7,739

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.

5,694

🚀 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.

10,079

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.

6,804

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 Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Flowy

Demo
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:

  1. Link flowy.min.js and flowy.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>
  1. Create a canvas element that will contain the flowchart (for example, <div id="canvas"></div>)
  2. 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);
ParameterTypeDescription
canvasjavascript DOM elementThe element that will contain the blocks
ongrabfunction (optional)Function that gets triggered when a block is dragged
onreleasefunction (optional)Function that gets triggered when a block is released
onsnapfunction (optional)Function that gets triggered when a block snaps with another one
onrearrangefunction (optional)Function that gets triggered when blocks are rearranged
spacing_xinteger (optional)Horizontal spacing between blocks (default 20px)
spacing_yinteger (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

ParameterTypeDescription
blockjavascript DOM elementThe 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;

ParameterTypeDescription
blockjavascript DOM elementThe block that has been grabbed
firstbooleanIf true, the block that has been dragged is the first one in the canvas
parentjavascript DOM elementThe 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;

ParameterTypeDescription
blockjavascript DOM elementThe block that has been grabbed
parentjavascript DOM elementThe 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:

KeyValue typeDescription
htmlstringContains the canvas data
blockarrarrayContains the block array generated by the library (for import purposes)
blocksarrayContains the readable block array
idintegerUnique value that identifies a block
parentintegerThe id of the parent a block is attached to (-1 means the block has no parent)
dataarray of objectsAn array of all the inputs within a certain block
namestringThe name attribute of the input
valuestringThe value attribute of the input
attrarray of objectsContains 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()

ParameterTypeDescription
outputjavascript DOM elementThe 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 💜