• Stars
    star
    217
  • Rank 176,637 (Top 4 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 11 years ago
  • Updated over 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

JavaScript dataflow graph editor

blocks.js

blocks

JavaScript dataflow graph editor

blocks.js is a JavaScript visual editor for editing dataflow graph, it can be used to edit processes graphs.

Note that this is just a flexible front-end editor, there is no back-end here.

You can try a live demo.

Overview

blocks.js is feeded using blocks specifications, using meta informations explaining its fields, name and behaviour.

It allow the user to edit the blocks scene.

Then, thanks for instance to the export(), method, you can get back the edited scene. When you load the blocks, you can also load back a scene.

Using blocks.js

Downloading

If you want to use it, you'll have to fetch the code, either by cloning this repository, or by downloading it.

Requirements

blocks.js uses:

All these requirements are included in this repository. This is why the third party libraries will look like this:

<!-- Third party libraries -->
<script type="text/javascript" src="build/jquery.js"></script>
<script type="text/javascript" src="build/jquery.json.min.js"></script>
<script type="text/javascript" src="build/jquery.mousewheel.min.js"></script>
<script type="text/javascript" src="build/jquery.svg.min.js"></script>
<script type="text/javascript" src="build/jquery.formserialize.min.js"></script>
<script type="text/javascript" src="build/jquery.fancybox.min.js"></script> 
<link rel="stylesheet" type="text/css" href="build/fancybox/jquery.fancybox.css" />

Then, you'll have to load blocks.js and blocks.css:

<!-- blocks.js -->
<script type="text/javascript" src="build/blocks.js"></script> 
<link rel="stylesheet" type="text/css" href="build/blocks.css" />

Running it

Here is a simple example:

// Instanciate Blocks
var blocks = new Blocks();

// Registering a simple block, with an input
// and an output
blocks.register({
    name: "Test",
    fields: [
        {
            name: "Input",
            attrs: "input"
        },
        {
            name: "Output",
            attrs: "output"
        }
    ]
});

// Running blocks on the div with the name "blocks"
blocks.run("#blocks");

Have a look at simple.html.

Blocks

The blocks is an object containing:

  • name: the name of the block
  • family: the block family, this will be used to put it in the right blocks menu sub-section
  • module: the block module, act like a namespace and avoid name collisions
  • description: a description of what the block does, to help the user
  • size: the size of the block, can be ̀small, normal or a certain number of pixels
  • class: additionals CSS classes that will be added to the block
  • fields: an array listing of the block fields, see below

Fields

A field can be an input, output and/or an editable parameter of the block. It is an object containing:

  • name: the name of the field, should not contain special chars
  • label: the label of the field, which will be printed in the blocks title, can contain special characters
  • attrs: a string containg field attributes, can contain input, output and/or editable. For instance: "editable input"
  • type: the field type. See typing.
  • defaultValue: the default value of the field, that will be used if it's editable
  • hide: do not display the editable field in the block information
  • hideLabel: do not display the editable field label in the block information
  • card: the cardinality of the input/output. This can be a string like "0-3" or and array like [0,3], it represents the minimum and the maximum edges that can be connected to the I/O.
  • dimension: the number of connection on the same field can depend on another field value, size, or be fixed to a static number. See variadic I/Os

Do not hesitate to have a look at the repository demo, in the `demo/̀ directory.

Scene

The scene is an easy-to-parse object containing:

Scene blocks

All scene block is represented with:

  • id: its numeric ID
  • x and y, the position of the block in the scene
  • type: the block type name
  • module: the block type module name
  • values: an array containing the values of all its editable fields

Scene edges

A scene edge is represented with:

  • id: its numeric ID
  • block1: the ID of the block where the edge starts
  • connector1: the connector of the block where the edge starts
  • block2: the ID of the block where the edge ends
  • connector2: the connector of the block where the edge ends

Scene connectors

A connector is an array containing 2 or 3 elements:

  • A string, input or output, explaining if the connector is outgoing of the block or entering in it
  • The name of the block field, in lower case
  • Optionally, the index for variadic fields

Typing

Each field can be typed. Basic types (string, choice, longtext, bool, int) are rendered as form inputs, all other unknown types are rendered as a simple text input. (Note: for choice type, you can define choices adding a ̀choices entry in the block field).

If the type ends with [], it is considered as an array, the Add & Remove buttons will be added when editing.

By default, the different types are not compatibles, and thus can't be linked together. You can however tell blocks.js that some types are compatible using:

// Tells blocks.js that string and number are compatible and can be linked
blocks.types.addCompatibility('string', 'number');

// Tells blocks.js that an image can be converted to a string, however, the
// string can't be converted to an image
blocks.types.addCompatibilityOneWay('image', 'string');

Variadic I/Os

Some I/Os can be variadic, think of a block that would output the n first users of a database, you could define it this way:

blocks.register({
    name: "TopUsers",
    description: "Outputs the n first users of the database",
    fields: [
        {
            name: "n",
            type: "int",
            hide: true,
            defaultValue: 3,
            attrs: "editable"
        },
        {
	    name: "users",
            label: "User #",
            dimension: "n",
            attrs: "output"
        }
    ]
});

Here, the number of outputed users will be editable, using the n editable field. Note that the # will be replaced by the number of the output.

Example

Here is an example that uses blocks.js:

Contributing & hacking

The development takes places in the src/ directory. There is a Makefile using uglifyjs command line to create the build.

You can use index-dev.html to test blocks.js using its sources, and index.html to try it in build mode.

The build/ directory of this repository will not be updated on every commit, but must contain a recent snapshot of the repository.

License

blocks.js is under MIT license. Have a look at the LICENSE file for more information.

More Repositories

1

Captcha

PHP Captcha library
PHP
1,675
star
2

Image

A PHP library to handle images
PHP
992
star
3

CaptchaBundle

Symfony bundle implementing a "captcha" form type
PHP
342
star
4

fatcat

FAT filesystems explore, extract, repair, and forensic tool
C++
285
star
5

ImageBundle

Image manipulation bundle for Symfony 2
PHP
194
star
6

Formidable

The PHP pragmatic forms library
PHP
120
star
7

Cache

A lightweight filesystem caching system
PHP
109
star
8

RST

PHP library to parse reStructuredText documents
PHP
93
star
9

notroot

Install APT packages without root access
Shell
78
star
10

Tex2png

PHP Library to generate PNGs from LaTeX math formula
PHP
70
star
11

ASCII-Tetris

ASCII Tetris game written in C
C
66
star
12

FormBundle

Provides the "entity_id" type (read "entity identifier")
PHP
64
star
13

Plankton

Plankton is a PHP pico framework
PHP
58
star
14

Mitm

Man in the middle tool
C
30
star
15

GnuPlot

A PHP Library for using GnuPlot
PHP
27
star
16

ArduiFlow

Arduino programming using flowchart environment
JavaScript
8
star
17

ArtNet-Console

A minimalist ArtNet-Console (Qt+libartnet)
C++
7
star
18

intro_ia

Jupyter Notebook
5
star
19

Tex2pngBundle

Symfony2 bundle to generate PNG images from LaTeX math formulas
PHP
4
star
20

CSV

CSV loader/saver
PHP
3
star
21

robotis-loader

Python program to flash robotis boards (OpenCM9.04, CM900)
Python
3
star
22

eFlute

Electronic flute
Eagle
3
star
23

FPDF

(Unofficial) FPDF Repository
PHP
3
star
24

PHP

Cours de PHP
PHP
2
star
25

orbita-placo

Python
2
star
26

MoveTheBox-solver

A simple solver for the MoveTheBox puzzle game
C
2
star
27

Slidey

The hybrid document & slide webapp builder
JavaScript
2
star
28

Counter-Counter-Strike

Un simple programme C pour faire lagger les serveur CS sur le réseau local
2
star
29

WebToApp-POC

This is a proof of concept on how a web application could communicate to a low level application using ZeroMQ
Objective-C
2
star
30

gregwar.github.io

HTML
2
star
31

avrel

AVR EmuLator (pedagogical)
C++
1
star
32

maple_mini_mbed

C
1
star
33

dfu-util

C
1
star
34

Configurations

Mes fichiers de configuration
Vim Script
1
star
35

td-dawin-2020

JavaScript
1
star
36

SlideySkeleton

Slidey skeleton project
PHP
1
star