This guide tries to centralize everything that has been written on WireIt. If you think something is missing or need better explanation, please contact us through the forum. Being written by a french, help in finding typos, technical errors, or poorly worded sentences is greatly appreciated.
WireIt is an open-source javascript library to create web wirable interfaces for dataflow applications, visual programming languages, graphical modeling, or graph editors.
WireIt is tested on all A-Grade Browsers, although it might work with older versions of browsers and platforms. Please report your issues with specific browsers in the forum.
It uses the YUI library (2.7.0) for DOM and events manipulation, and excanvas for IE support of the canvas tag.
The code for Wireit is provided under a MIT license.
Here are the main widget classes :
Different types of Container are provided :
You can create your own container by subclassing the base Container class, and still benefit from the drop-in use of the WiringEditor in your web application.
WireIt provides another useful component: the WiringEditor, a single-page editor for your visual language.
You create a simple html page, import WireIt widgets and WiringEditor, define your visual language using a JSON configuration and a full-page editor is built into the browser to use your language.
The WiringEditor requires a connection to a database to use save/load features. You can customize it using adapters. A default adapter is provided, which uses JSON-RPC through ajax calls, and a PHP/MySQL backend.
| file or directory | |
|---|---|
| backend/ | Contains backend (server-side) code for the WiringEditor |
| build/ | Contains the minified javascript and build scripts |
| css/ | Contains the css WireIt components |
| doc/ | Auto-generated API documentation |
| examples/ | Examples or applications that are part of the library |
| images/ | WireIt images |
| index.html | WireIt Home page |
| INSTALL.txt | Installation instructions |
| js/ | javascript sources |
| lib/ | Librairies required by WireIt |
| license.txt | Open-source license details |
| README.txt | This file |
| VERSION.txt | The change log |
WireIt is mostly a bunch of static javascript, css, and image files, so you can just download the library and put the files in your project library directory.
However, the WiringEditor requires a database connection to use the save/load features. (see WiringEditor installation)
You could also clone the development repository to get the edge version.
In a production environment, documentation and examples are not necessary. More on this in production.
The WiringEditor requires a database connection to use the save/load features.
The database connection can be adapted to your project though adapters.
Adapters themselves don't require any particular installation, however, they are connected to a backend, which often require a specific server environment.
Please refer to the adapters documentation to install the associated backends.
You can create your own adapters.
Depending on which default adapter you decided to use, copy the examples/gearsAdapter/ or examples/WiringEditor/ files into your project directory.
Edit the index.html file you copied to check that the paths to javascript and css files are correct. (You might want to create your project directory directly in the examples/ folder so that the paths remain unchanged.)
Launch the index.html file in your browser. You're ready to create your visual language.
The visual language is defined in a JSON format :
var myLanguage = {
// Set a unique name for the language
languageName: "myLanguage",
modules: [
// List of module type definitions
]
};
Here is the skeleton of a module definition :
{
"name": "moduleName",
"container": {
// which container class to use
"xtype":"WireIt.InOutContainer",
// Depends of the container
"inputs": ["text1", "text2", "option1"],
"outputs": ["result", "error"]
}
}
To declare a module using a different Container class, you'll have to set the container xtype property.
The xtype property is a string representing the class. This had to be a string to remain JSON compliant.
Of course, you can use containers provided in WireIt (ImageContainer, FormContainer, InOutContainer), or a custom container.
Set "xtype": "WireIt.Container" (optional). The parameters are :
{
"name": "demoModule",
"container": {
"xtype":"WireIt.Container",
"icon": "../../res/icons/application_edit.png",
"terminals": [
{"name": "_INPUT1", "direction": [-1,0], "offsetPosition": {"left": -3, "top": 2 }},
{"name": "_INPUT2", "direction": [-1,0], "offsetPosition": {"left": -3, "top": 37 }},
{"name": "_OUTPUT", "direction": [1,0], "offsetPosition": {"left": 103, "top": 20 }}
]
}
}
Set "xtype": "WireIt.InOutContainer". Additional parameters are :
Example:
{
"name": "InOut test",
"container": {
"xtype":"WireIt.InOutContainer",
"inputs": ["text1", "text2", "option1"],
"outputs": ["result", "error"]
}
}
Set "xtype": "WireIt.FormContainer". Additional parameters are all those used in inputEx.Group. (see inputEx)
{
"name": "MyModule",
"container": {
"xtype": "WireIt.FormContainer",
// inputEx options :
"title": "WireIt.FormContainer demo",
"collapsible": true,
"fields": [
{"type": "select", "inputParams": {"label": "Title", "name": "title", "selectValues": ["Mr","Mrs","Mme"] } },
{"inputParams": {"label": "Firstname", "name": "firstname", "required": true } },
{"inputParams": {"label": "Lastname", "name": "lastname", "value":"Dupont"} },
{"type":"email", "inputParams": {"label": "Email", "name": "email", "required": true, "wirable": true}},
{"type":"boolean", "inputParams": {"label": "Happy to be there ?", "name": "happy"}},
{"type":"url", "inputParams": {"label": "Website", "name":"website", "size": 25}}
],
"legend": "Tell us about yourself..."
}
}
Set "xtype": "WireIt.ImageContainer". Additional parameters are :
{
"name": "AND gate",
"container": {
"xtype":"WireIt.ImageContainer",
"image": "../logicGates/images/gate_and.png",
"terminals": [
{"name": "_INPUT1", "direction": [-1,0], "offsetPosition": {"left": -3, "top": 2 }},
{"name": "_INPUT2", "direction": [-1,0], "offsetPosition": {"left": -3, "top": 37 }},
{"name": "_OUTPUT", "direction": [1,0], "offsetPosition": {"left": 103, "top": 20 }}
]
}
}
To add properties to the Wirings, we configure the propertiesFields property of the language definition.
This property defines the fields as they will appear in the "Properties" form on the right in the WiringEditor.
The form is created using the inputEx form library. The propertiesFields array is directly used to instantiate a inputEx.Group class. Please refer to inputEx documentation to learn how to configure your fields.
When you use the save/load fetures of the WiringEditor, the form values are automatically saved within your wirings before being sent back to the server.
var demoLanguage = {
languageName: "meltingpotDemo",
// inputEx fields for pipes properties
propertiesFields: [
// default fields (the "name" field is required by the WiringEditor):
{"type": "string", inputParams: {"name": "name", label: "Title", typeInvite: "Enter a title" } },
{"type": "text", inputParams: {"name": "description", label: "Description", cols: 30} },
// Additional fields
{"type": "boolean", inputParams: {"name": "isTest", value: true, label: "Test"}},
{"type": "select", inputParams: {"name": "category", label: "Category", selectValues: ["Demo", "Test", "Other"]} }
],
modules: [
//...
]
};
The HiddenField can be used to store additional wirings informations.
Adapters are used by the WiringEditor to provide the loading/saving features. It makes it easy to "plug" the WiringEditor into your application. They usually connect to a database of some kind through Ajax calls to store the wirings and bring them back.
WireIt provides default adapters to get you started :
// Override adapter default parameters
WireIt.WiringEditor.adapters.MyAdapter.config.configParam1 = value1;
// Instantiate the WiringEditor with a custom adapter
new WireIt.WiringEditor({
...
adapter: WireIt.WiringEditor.adapters.MyAdapter
...
})
This adapter is the general way to connect to a custom backend through Ajax (or XHR) calls. It uses a JSON representation.
You can use it to connect to a REST resource store or any HTTP-based RPC backend.
The ajaxAdapter example connects to a fake backend (the queried URLs are static files), but demonstrate how to configure the adapter :
WireIt.WiringEditor.adapters.Ajax.config = {
saveWiring: {
method: 'GET',
// The url can be hard-coded
url: 'fakeSaveDelete.json'
},
deleteWiring: {
method: 'GET',
/**
* 'url' can also be a function that returns the URL as a string.
* For exemple, to connect to a REST store, you might want to send a DELETE /resource/wirings/moduleName
* (moduleName is present in the "value" parameter)
*/
url: function(value) {
return "fakeSaveDelete.json";
}
},
listWirings: {
method: 'GET',
url: 'listWirings.json'
}
};
This adapter uses Ajax calls as the previous one, but wraps http requests in a JSON-RPC envelope.
This adapter is used in the WiringEditor demo.
It is connected to a sample PHP/MySQL backend, which requires the following installtion steps :
The JSON-RPC adapter configuration resides in the single service url :
WireIt.WiringEditor.adapters.JsonRpc.config.url = '/my/json-rpc/serviceUrl';
This adapter uses the database component of Google Gears to store the wirings in a SQLite table client-side (in the browser).
This adapter is very useful for prototyping your project, since it can be used without any server installation.
To use this adapter, you must install google gears.
A demo of this adapter is showed in the gears adapter example.
This adapter doesn't have any noticeable configuration except WireIt.WiringEditor.adapters.Gears.config.dbName which contains the gears database name (default is 'database-test').
The gears adapter already includes gears-init.js
Why would you build your own ?
Here is the skeleton of an adapter :
WireIt.WiringEditor.adapters.MyAdapter = {
// adapter default options
config: {
// ...
},
// Initialization method called by the WiringEditor
init: function() {
},
/**
* save/list/delete asynchronous methods
*/
saveWiring: function(val, callbacks) {
// ...
// don't forget to call the callbacks !
},
deleteWiring: function(val, callbacks) {
// ...
// don't forget to call the callbacks !
},
listWirings: function(val, callbacks) {
// ...
// don't forget to call the callbacks !
}
// + private methods or properties
};
})();
The main three methods use asynchronous callbacks to push back the results to the WiringEditor. Here is the structure of the callbacks that are passed to these methods :
var callbacks = {
success: function() {
},
failure: function() {
},
scope: this
};
To call the callbacks, in a synchronous way, use something like :
function(val, callbacks) {
if(everythingGoesFine) {
callbacks.success.call(callbacks.scope, results);
}
else {
callbacks.failure.call(callbacks.scope, results);
}
}
The asynchronous pattern is particularly useful for ajax-based adapters. Here is an example with YUI :
function(val, callbacks) {
YAHOO.util.Connect.asyncRequest('POST', 'myUrl', {
success: function(r) {
//...
callbacks.success.call(callbacks.scope, results);
},
failure: function(r) {
callbacks.failure.call(callbacks.scope, error);
}
});
}
First, here is the JSON output of the WiringEditor :
var working = {
"modules":[
{
"config":{
"position":[166,195],
"xtype":"WireIt.ImageContainer"
},
"name":"AND gate",
"value":{}
},
{
"config":{
"position":[454,271],
"xtype":"WireIt.ImageContainer"
},
"name":"AND gate",
"value":{}
},
{
"config":{
"position":[149,403],
"xtype":"WireIt.ImageContainer"
},
"name":"AND gate",
"value":{}
}
],
"wires":[
{
"src":{"moduleId":0,"terminal":"_OUTPUT"},
"tgt":{"moduleId":1,"terminal":"_INPUT1"}
},
{
"src":{"moduleId":2,"terminal":"_OUTPUT"},
"tgt":{"moduleId":1,"terminal":"_INPUT2"}
}
],
"properties":{
"name":"demo",
"description":"",
"isTest":true,
"category":"Demo"
}
};
First comes the list of instantiated modules. The name is set to the module name, config.xtype indicates the container class, config.position is pretty self-explanatory, and value contains the exported value for this instance (in this case it is empty, but for a FormContainer, it will contain the form value.)
Secondly, the wires instances, composed of a src (source) terminal and a tgt (target) terminal.
Each terminal is referenced by its moduleId (module index in the above definition) and its name (terminal).
Finally, the properties object contains the value of the "Properties" form on the right of the editor.
The examples store directly the JSON in a TEXT column in the database. Almost all programming languages provide built-in JSON stringify/parse methods, so you can parse this tree to convert to another format.
The WiringEditor adds a CSS class for each module instance in your layer: WiringEditor-module-moduleName.
You can therefore style all the descending structure using cascaded style sheets.
Here is an exemple for the "comment" module of the WiringEditor demo.
/* Comment Module */
div.WireIt-Container.WiringEditor-module-comment {
width: 200px;
}
div.WireIt-Container.WiringEditor-module-comment div.body {
background-color: #EEEE66;
}
div.WireIt-Container.WiringEditor-module-comment div.body textarea {
background-color: transparent; font-weight: bold; border: 0;
}
The WiringEditor has an option called autoload.
This is a parameter passed in the URL that tells the WiringEditor which wiring to open when the editor is displayed.
http://myhost.com/editor/?autoload=myWiring
For example, here is a direct link to the "guideAutoloadDemo" wiring of the WiringEditor example :
examples/WiringEditor/?autoload=guideAutoloadDemo
There are two methods to handle wire mouse events :
Listen to wire events (recommanded)
wire.eventMouseIn.subscribe(wireRed, wire, true); wire.eventMouseOut.subscribe(wireBlue, wire, true); wire.eventMouseClick.subscribe(wireClick, wire, true);
Override Wire.prototype methods
Wire.prototype.onWireIn = function(x,y) {
};
Wire.prototype.onWireOut = function(x,y) {
};
Wire.prototype.onWireClick = function(x,y) {
};
Here is an example to create a random layer and lister for wire events :
// Functions executed with the scope of a wire
var wireRed = function() {
this.options.color = 'rgb(255, 0, 0)';
this.redraw();
},
wireBlue = function() {
this.options.color = 'rgb(173, 216, 230)';
this.redraw();
},
wireClick = function() {
alert("Hoho ! you clicked !");
};
// Generate a random layer
var layer = new WireIt.Layer({});
for(var i = 0 ; i < 5 ; i++) {
layer.addContainer({
terminals: [ {direction: [0,1], offsetPosition: {bottom: -13, left: 25} }],
title: "Block #"+i,
position: [ Math.floor(Math.random()*800)+30, Math.floor(Math.random()*300)+30 ]
});
}
for(var i = 0 ; i < 7 ; i++) {
var w = layer.addWire({
src: {moduleId: Math.floor(Math.random()*5), terminalId: 0},
tgt: {moduleId: Math.floor(Math.random()*5), terminalId: 0}
});
// Subscribe methods to mouse events for all wires
w.eventMouseIn.subscribe(wireRed, w, true);
w.eventMouseOut.subscribe(wireBlue, w, true);
w.eventMouseClick.subscribe(wireClick, w, true);
}
The general way to create a new Container class is to extend the WireIt.Container class. We do this YUI-style :
WireIt.MyContainer = function(options, layer) {
WireIt.MyContainer.superclass.constructor.call(this, options, layer);
};
YAHOO.lang.extend(WireIt.MyContainer, WireIt.Container, {
// override methods or new methods
});
You can extend from WireIt.Container, WireIt.InOutContainer, WireIt.ImageContainer, WireIt.FormContainer.
For more details with Container methods, please refer to the API Documentation.
To extend or modify the behavior of an existing Container.
WireIt.ImageContainer.prototype.myMethod = function () {
// new code
};
To use your new Container in a language definition go to Module Definition.
In a production environment, it is preferable to use rollup files: The javascript files are concatenated into a single javascript file (to reduce the number of HTTP requests) then compressed using the YUI compressor (to reduce file size).
Some rollup files are provided in the wireit/build directory :
<script type="text/javascript" src="lib/wireit/build/wireit-min.js"></script>
or
<script type="text/javascript" src="lib/wireit/build/wiring-editor-min.js"></script>
Warning :The rollup files don't include the excanvas.js library required by Internet Explorer, because this file is conditionally loaded using the "if IE" hack :
<!--[if IE]><script type="text/javascript" src="../../lib/excanvas.js"></script><![endif]-->
Warning :The wiring-editor-min.js file doesn't include any adapter, and only includes some fields of the inputEx library.
It is strongly recommended to build your custom rollup file for production. You can then include the adapter you use, the visual language definition, or even the YUI library dependencies. The script to build those files is available at build/rollups.sh (only in source, not in the zipped library)
The YUI library is included in the zip file, but the YUI files can be served from Yahoo or Google servers.
Moreover, the WireIt zip file contains example, guides, documentation, which are not necessary in a production environment. We recommend you to copy only the required files on your webserver :
wireit/ - build/ - css/ - images/ - js/ - lib/
WiringEditor :
Beta/Experimental :
Deeper hacking into WireIt might require some knowledge in the libraries used :
Email me your own: <eric.abouaf at gmail>
You can contribute in a lot of different ways :
If you use this project in a commercial application, or simply wish to see this project continue, you can donate on PayPal. Donations will be used for WireIt development and promotion.
Here is a list of the main requested features. Please note that this is a wish-list, it's not always what the developers are currently working on.
WireIt has proven useful for graph editing, but it is also very good at data visualization.
However, the current layout engine still has a long way to go...
Adding labels to the wires. This will now be easier thanks to the Canvas-Text library.
Keep improving this strong application framework.
The idea is to generate containers/terminals/wires from existing HTML. This is especially useful for wirings to be indexable by search engines.
New backends/code generators to increase development speed.
Although the backend largely depends on your project, it would be nice to have one for each major framework: Rails, Django, Symfony, AppEngine, ...
WireIt is released under the MIT license.