Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions lib/deps/attributs.js → lib/deps/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ function quoteMe(attr, value) {
}
}

function validateAttribut(name, type) {
function validateAttribute(name, type) {
if(attrs[name]) {
return(attrs[name].usage.indexOf(type) > -1);
} else {
Expand All @@ -211,39 +211,39 @@ function validateAttribut(name, type) {
}

exports.isValid = function(name, type) {
return validateAttribut(name, type);
return validateAttribute(name, type);
};

var Attributs = exports.Attributs = function(t) {
var Attributes = exports.Attributes = function(t) {
this._type = t;
this.attributs = new Hash();
this.attributes = new Hash();
};

Attributs.prototype.length = function() {
return(this.attributs.length);
Attributes.prototype.length = function() {
return(this.attributes.length);
};

Attributs.prototype.set = function(name, value) {
if(validateAttribut(name, this._type) === false) {
util.debug("Warning : Invalid attribut `" + name + "' for a " + gType[this._type]);
// throw "Invalid attribut `"+name+"' for a "+gType[this._type]
Attributes.prototype.set = function(name, value) {
if(validateAttribute(name, this._type) === false) {
util.debug("Warning : Invalid attribute `" + name + "' for a " + gType[this._type]);
// throw "Invalid attribute `"+name+"' for a "+gType[this._type]
}
this.attributs.setItem(name, value);
this.attributes.setItem(name, value);
};

Attributs.prototype.get = function(name) {
return this.attributs.items[name];
Attributes.prototype.get = function(name) {
return this.attributes.items[name];
};

Attributs.prototype.to_dot = function(link) {
Attributes.prototype.to_dot = function(link) {
var attrsOutput = "",
sep = "";

if(this.attributs.length > 0) {
if(this.attributes.length > 0) {
attrsOutput = attrsOutput + " [ ";
for(var name in this.attributs.items) {
if (this.attributs.items.hasOwnProperty(name)) {
attrsOutput = attrsOutput + sep + name + " =" + quoteMe(name, this.attributs.items[name]);
for(var name in this.attributes.items) {
if (this.attributes.items.hasOwnProperty(name)) {
attrsOutput = attrsOutput + sep + name + " =" + quoteMe(name, this.attributes.items[name]);
sep = ", ";
}
}
Expand Down
20 changes: 10 additions & 10 deletions lib/deps/edge.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Module dependencies
*/
var Hash = require('./core_ext/hash').Hash,
Attributs = require('./attributs').Attributs;
Attributes = require('./attributes').Attributes;

/**
* Create a new edge
Expand All @@ -17,30 +17,30 @@ var Edge = exports.Edge = function(graph, nodeOne, nodeTwo) {
this.relativeGraph = graph;
this.nodeOne = nodeOne;
this.nodeTwo = nodeTwo;
this.attributs = new Attributs("E");
this.attributes = new Attributes("E");
};

/**
* Set an edge attribut
* Set an edge attribute
*
* @param {String} name The attribut name
* @param {Void} value The attribut value
* @param {String} name The attribute name
* @param {Void} value The attribute value
* @api public
*/
Edge.prototype.set = function(name, value) {
this.attributs.set(name, value);
this.attributes.set(name, value);
return this;
};

/**
* Get an edge attribut
* Get an edge attribute
*
* @param {String} name The attribut name
* @param {String} name The attribute name
* @return {Void}
* @api public
*/
Edge.prototype.get = function(name) {
return this.attributs.get(name);
return this.attributes.get(name);
};

/**
Expand All @@ -53,6 +53,6 @@ Edge.prototype.to_dot = function() {
}

var edgeOutput = '"' + this.nodeOne.id + '"' + " " + edgeLink + " " + '"' + this.nodeTwo.id + '"';
edgeOutput = edgeOutput + this.attributs.to_dot();
edgeOutput = edgeOutput + this.attributes.to_dot();
return edgeOutput;
};
90 changes: 45 additions & 45 deletions lib/deps/graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
var Hash = require( './core_ext/hash' ).Hash,
Node = require( './node' ).Node,
Edge = require( './edge' ).Edge,
gvattrs = require( './attributs' ),
Attributs = gvattrs.Attributs,
gvattrs = require( './attributes' ),
Attributes = gvattrs.Attributes,
util = require('util'),
path = require('path'),
spawn = require('child_process').spawn;
Expand All @@ -27,20 +27,20 @@ var Graph = exports.Graph = function(graph, id) {
this.edges = new Array();
this.clusters = new Hash();
if( this.relativeGraph == null ) {
this.graphAttributs = new Attributs("G");
this.graphAttributes = new Attributes("G");
} else {
this.graphAttributs = new Attributs("C");
this.graphAttributes = new Attributes("C");
}
this.nodesAttributs = new Attributs("N");
this.edgesAttributs = new Attributs("E");
this.nodesAttributes = new Attributes("N");
this.edgesAttributes = new Attributes("E");
this.use = 'dot';
};

/**
* Create a new node
*
* @param {String} id The node ID
* @param {Object} attrs Node attributs
* @param {Object} attrs Node attributes
* @return {Node}
* @api public
*/
Expand Down Expand Up @@ -88,7 +88,7 @@ Graph.prototype.nodeCount = function() {
*
* @param {String|Node} nodeOne
* @param {String|Node} nodeTwo
* @param {Object} attrs Node attributs
* @param {Object} attrs Node attributes
* @return {Edge}
* @api public
*/
Expand Down Expand Up @@ -165,69 +165,69 @@ Graph.prototype.clusterCount = function() {
}

/**
* Set a graph attribut
* Set a graph attribute
*
* @param {String} name The attribut name
* @param {Void} value The attribut value
* @param {String} name The attribute name
* @param {Void} value The attribute value
* @api public
*/
Graph.prototype.set = function(name, value) {
this.graphAttributs.set(name, value);
this.graphAttributes.set(name, value);
}

/**
* Get a graph attribut
* Get a graph attribute
*
* @param {String} name The attribut name
* @param {String} name The attribute name
* @return {Void}
* @api public
*/
Graph.prototype.get = function(name) {
return this.graphAttributs.get(name);
return this.graphAttributes.get(name);
}

/**
* Set a global node attribut
* Set a global node attribute
*
* @param {String} name The attribut name
* @param {Void} value The attribut value
* @param {String} name The attribute name
* @param {Void} value The attribute value
* @api public
*/
Graph.prototype.setNodeAttribut = function(name, value) {
this.nodesAttributs.set(name, value);
Graph.prototype.setNodeAttribute = function(name, value) {
this.nodesAttributes.set(name, value);
}

/**
* Get a global node attribut
* Get a global node attribute
*
* @param {String} name The attribut name
* @param {String} name The attribute name
* @return {Void}
* @api public
*/
Graph.prototype.getNodeAttribut = function(name) {
return this.nodesAttributs.get(name);
Graph.prototype.getNodeAttribute = function(name) {
return this.nodesAttributes.get(name);
}

/**
* Set a global edge attribut
* Set a global edge attribute
*
* @param {String} name The attribut name
* @param {Void} value The attribut value
* @param {String} name The attribute name
* @param {Void} value The attribute value
* @api public
*/
Graph.prototype.setEdgeAttribut = function(name, value) {
this.edgesAttributs.set(name, value);
Graph.prototype.setEdgeAttribute = function(name, value) {
this.edgesAttributes.set(name, value);
}

/**
* Get a global edge attribut
* Get a global edge attribute
*
* @param {String} name The attribut name
* @param {String} name The attribute name
* @return {Void}
* @api public
*/
Graph.prototype.getEdgeAttribut = function(name) {
return this.edgesAttributs.get(name);
Graph.prototype.getEdgeAttribute = function(name) {
return this.edgesAttributes.get(name);
}

/**
Expand All @@ -244,19 +244,19 @@ Graph.prototype.to_dot = function() {
dotScript = 'subgraph ' + this.id + ' {\n'
}

// Graph attributs
if( this.graphAttributs.length() > 0 ) {
dotScript = dotScript + " graph" + this.graphAttributs.to_dot() + ";\n";
// Graph attributes
if( this.graphAttributes.length() > 0 ) {
dotScript = dotScript + " graph" + this.graphAttributes.to_dot() + ";\n";
}

// Nodes attributs
if( this.nodesAttributs.length() > 0 ) {
dotScript = dotScript + " node" + this.nodesAttributs.to_dot() + ";\n";
// Nodes attributes
if( this.nodesAttributes.length() > 0 ) {
dotScript = dotScript + " node" + this.nodesAttributes.to_dot() + ";\n";
}

// Edges attributs
if( this.edgesAttributs.length() > 0 ) {
dotScript = dotScript + " edge" + this.edgesAttributs.to_dot() + ";\n";
// Edges attributes
if( this.edgesAttributes.length() > 0 ) {
dotScript = dotScript + " edge" + this.edgesAttributes.to_dot() + ";\n";
}

// Each clusters
Expand Down Expand Up @@ -319,7 +319,7 @@ Graph.prototype.render = function(type_or_options, name_or_callback, errback) {
if( type_or_options.G != undefined ) {
for( attr in type_or_options.G ) {
if( gvattrs.isValid( attr, "G" ) == false ) {
util.debug( "Warning : Invalid attribut `"+attr+"' for a graph" );
util.debug( "Warning : Invalid attribute `"+attr+"' for a graph" );
}
parameters.push( "-G"+attr+"="+type_or_options.G[attr] )
}
Expand All @@ -328,7 +328,7 @@ Graph.prototype.render = function(type_or_options, name_or_callback, errback) {
if( type_or_options.N != undefined ) {
for( attr in type_or_options.N ) {
if( gvattrs.isValid( attr, "N" ) == false ) {
util.debug( "Warning : Invalid attribut `"+attr+"' for a node" );
util.debug( "Warning : Invalid attribute `"+attr+"' for a node" );
}
parameters.push( "-N"+attr+"="+type_or_options.N[attr] )
}
Expand All @@ -337,7 +337,7 @@ Graph.prototype.render = function(type_or_options, name_or_callback, errback) {
if( type_or_options.E != undefined ) {
for( attr in type_or_options.E ) {
if( gvattrs.isValid( attr, "E" ) == false ) {
util.debug( "Warning : Invalid attribut `"+attr+"' for an edge" );
util.debug( "Warning : Invalid attribute `"+attr+"' for an edge" );
}
parameters.push( "-E"+attr+"="+type_or_options.E[attr] )
}
Expand Down
20 changes: 10 additions & 10 deletions lib/deps/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Module dependencies
*/
var Hash = require('./core_ext/hash').Hash,
Attributs = require('./attributs').Attributs;
Attributes = require('./attributes').Attributes;

/**
* Create a new node
Expand All @@ -15,7 +15,7 @@ var Hash = require('./core_ext/hash').Hash,
var Node = exports.Node = function(graph, id) {
this.relativeGraph = graph;
this.id = id;
this.attributs = new Attributs("N");
this.attributes = new Attributes("N");
};

/**
Expand All @@ -27,32 +27,32 @@ Node.prototype.to = function(id, attrs) {
};

/**
* Set a node attribut
* Set a node attribute
*
* @param {String} name The attribut name
* @param {Void} value The attribut value
* @param {String} name The attribute name
* @param {Void} value The attribute value
* @api public
*/
Node.prototype.set = function(name, value) {
this.attributs.set(name, value);
this.attributes.set(name, value);
return this;
};

/**
* Get a node attribut
* Get a node attribute
*
* @param {String} name The attribut name
* @param {String} name The attribute name
* @return {Void}
* @api public
*/
Node.prototype.get = function(name) {
return this.attributs.get(name);
return this.attributes.get(name);
};

/**
* @api private
*/
Node.prototype.to_dot = function() {
var nodeOutput = '"' + this.id + '"' + this.attributs.to_dot();
var nodeOutput = '"' + this.id + '"' + this.attributes.to_dot();
return nodeOutput;
};
6 changes: 3 additions & 3 deletions tests/cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ cluster_0.set( "style", "filled" );
// color=lightgrey;
cluster_0.set( "color", "lightgrey" );
// node [style=filled,color=white];
cluster_0.setNodeAttribut( "style", "filled" )
cluster_0.setNodeAttribut( "color", "white" )
cluster_0.setNodeAttribute( "style", "filled" )
cluster_0.setNodeAttribute( "color", "white" )

// a0 -> a1 -> a2 -> a3;
cluster_0.addEdge( "a0", "a1" );
Expand All @@ -24,7 +24,7 @@ cluster_0.set( "label", "process #1" )
// subgraph cluster_1 {
var cluster_1 = g.addCluster("cluster_1");
// node [style=filled];
cluster_1.setNodeAttribut( "style", "filled" )
cluster_1.setNodeAttribute( "style", "filled" )

// b0 -> b1 -> b2 -> b3;
cluster_1.addEdge( "b0", "b1" );
Expand Down