Permalink
Browse files

code corrections

  • Loading branch information...
1 parent efa506f commit b87d54ad75ad3ec45e114610927958903bd11c8f @glejeune committed Nov 16, 2010
Showing with 66 additions and 65 deletions.
  1. +28 −29 lib/deps/attributs.js
  2. +10 −10 lib/deps/edge.js
  3. +10 −10 lib/deps/node.js
  4. +18 −16 lib/graphviz.js
View
@@ -1,4 +1,4 @@
-var Hash = require( './core_ext/hash' ).Hash,
+var Hash = require('./core_ext/hash').Hash,
sys = require('sys');
var attrs = {
@@ -94,8 +94,7 @@ var attrs = {
"nslimit" : { "usage" : "G", "type" : "double" },
"nslimit1" : { "usage" : "G", "type" : "double" },
"ordering" : { "usage" : "G", "type" : "string" },
- "orientation" : { "usage" : "N", "type" : "double" },
- "orientation" : { "usage" : "G", "type" : "string" },
+ "orientation" : { "usage" : "GN", "type" : "string" },
"outputorder" : { "usage" : "G", "type" : "outputMode" },
"overlap" : { "usage" : "G", "type" : "string" },
"overlap_scaling" : { "usage" : "G", "type" : "double" },
@@ -181,62 +180,62 @@ var quotedTypes = [
];
function mustBeQuoted(data) {
- return( quotedTypes.indexOf(attrs[data]["type"]) != -1 )
+ return(quotedTypes.indexOf(attrs[data].type) !== -1);
}
function quoteMe(attr, value) {
- if( mustBeQuoted(attr) ) {
- return( '"'+value+'"' );
+ if(mustBeQuoted(attr)) {
+ return('"' + value + '"');
} else {
- return( value );
+ return(value);
}
}
function validateAttribut(name, type) {
- if( attrs[name] ) {
- return( attrs[name]["usage"].indexOf(type) > -1 );
+ if(attrs[name]) {
+ return(attrs[name].usage.indexOf(type) > -1);
} else {
- return( false );
+ return(false);
}
}
exports.isValid = function(name, type) {
return validateAttribut(name, type);
-}
+};
var Attributs = exports.Attributs = function(t) {
this._type = t;
this.attributs = new Hash();
-}
+};
Attributs.prototype.length = function() {
- return( this.attributs.length );
-}
+ return(this.attributs.length);
+};
-Attributs.prototype.set = function( name, value ) {
- if( validateAttribut(name, this._type) == false ) {
- sys.debug( "Warning : Invalid attribut `"+name+"' for a "+gType[this._type] );
+Attributs.prototype.set = function(name, value) {
+ if(validateAttribut(name, this._type) === false) {
+ sys.debug("Warning : Invalid attribut `" + name + "' for a " + gType[this._type]);
// throw "Invalid attribut `"+name+"' for a "+gType[this._type]
}
this.attributs.setItem(name, value);
-}
+};
-Attributs.prototype.get = function( name ) {
+Attributs.prototype.get = function(name) {
return this.attributs.items[name];
-}
+};
Attributs.prototype.to_dot = function(link) {
- var attrsOutput = "";
- var sep = "";
+ var attrsOutput = "",
+ sep = "";
- if( this.attributs.length > 0 ) {
- attrsOutput = attrsOutput + " [ "
- for( var name in this.attributs.items ) {
- attrsOutput = attrsOutput + sep + name + " = " + quoteMe(name, this.attributs.items[name])
- sep = ", "
+ if(this.attributs.length > 0) {
+ attrsOutput = attrsOutput + " [ ";
+ for(var name in this.attributs.items) {
+ attrsOutput = attrsOutput + sep + name + " = " + quoteMe(name, this.attributs.items[name]);
+ sep = ", ";
}
- attrsOutput = attrsOutput + " ]"
+ attrsOutput = attrsOutput + " ]";
}
return attrsOutput;
-}
+};
View
@@ -1,8 +1,8 @@
/**
* Module dependencies
*/
-var Hash = require( './core_ext/hash' ).Hash,
- Attributs = require( './attributs' ).Attributs;
+var Hash = require('./core_ext/hash').Hash,
+ Attributs = require('./attributs').Attributs;
/**
* Create a new edge
@@ -27,9 +27,9 @@ var Edge = exports.Edge = function(graph, nodeOne, nodeTwo) {
* @param {Void} value The attribut value
* @api public
*/
-Edge.prototype.set = function( name, value ) {
+Edge.prototype.set = function(name, value) {
this.attributs.set(name, value);
-}
+};
/**
* Get an edge attribut
@@ -38,20 +38,20 @@ Edge.prototype.set = function( name, value ) {
* @return {Void}
* @api public
*/
-Edge.prototype.get = function( name ) {
+Edge.prototype.get = function(name) {
return this.attributs.get(name);
-}
+};
/**
* @api private
*/
Edge.prototype.to_dot = function() {
var edgeLink = "->";
- if( this.relativeGraph.type == "graph" ) {
+ if(this.relativeGraph.type === "graph") {
edgeLink = "--";
}
- var edgeOutput = '"'+this.nodeOne.id+'"' + " " + edgeLink + " " + '"'+this.nodeTwo.id+'"';
- edgeOutput = edgeOutput + this.attributs.to_dot()
+ var edgeOutput = '"' + this.nodeOne.id + '"' + " " + edgeLink + " " + '"' + this.nodeTwo.id + '"';
+ edgeOutput = edgeOutput + this.attributs.to_dot();
return edgeOutput;
-}
+};
View
@@ -1,8 +1,8 @@
/**
* Module dependencies
*/
-var Hash = require( './core_ext/hash' ).Hash,
- Attributs = require( './attributs' ).Attributs;
+var Hash = require('./core_ext/hash').Hash,
+ Attributs = require('./attributs').Attributs;
/**
* Create a new node
@@ -22,9 +22,9 @@ var Node = exports.Node = function(graph, id) {
*
*/
Node.prototype.to = function(id, attrs) {
- this.relativeGraph.addEdge(this, id, attrs)
+ this.relativeGraph.addEdge(this, id, attrs);
return this.relativeGraph.from(id);
-}
+};
/**
* Set a node attribut
@@ -33,9 +33,9 @@ Node.prototype.to = function(id, attrs) {
* @param {Void} value The attribut value
* @api public
*/
-Node.prototype.set = function( name, value ) {
+Node.prototype.set = function(name, value) {
this.attributs.set(name, value);
-}
+};
/**
* Get a node attribut
@@ -44,14 +44,14 @@ Node.prototype.set = function( name, value ) {
* @return {Void}
* @api public
*/
-Node.prototype.get = function( name ) {
+Node.prototype.get = function(name) {
return this.attributs.get(name);
-}
+};
/**
* @api private
*/
Node.prototype.to_dot = function() {
- var nodeOutput = '"'+this.id+'"' + this.attributs.to_dot();
+ var nodeOutput = '"' + this.id + '"' + this.attributs.to_dot();
return nodeOutput;
-}
+};
View
@@ -20,7 +20,7 @@ exports.graph = function(id) {
var graph = new Graph(null, id);
graph.type = 'graph';
return graph;
-}
+};
/**
* Create a new directed graph
@@ -33,17 +33,17 @@ exports.digraph = function(id) {
var graph = new Graph(null, id);
graph.type = 'digraph';
return graph;
-}
+};
function _parse(file, callback, errback) {
- var gvprScript = path.join( __dirname, "ext", "gvpr", "dot2js.g" );
- var parameters = ["-f"+gvprScript, file];
- var cmd = "gvpr";
- var __graph_eval;
- var err = '';
- var out = '';
+ var gvprScript = path.join(__dirname, "ext", "gvpr", "dot2js.g"),
+ parameters = ["-f" + gvprScript, file],
+ cmd = "gvpr",
+ __graph_eval,
+ err = '',
+ out = '',
+ graphviz = spawn(cmd, parameters);
- graphviz = spawn(cmd, parameters);
graphviz.stdout.on('data', function(data) {
out += data;
eval(data.toString());
@@ -53,10 +53,12 @@ function _parse(file, callback, errback) {
});
graphviz.stdin.end();
graphviz.on('exit', function(code) {
- if(code !== 0 || __graph_eval == undefined) {
- if(errback) { errback(code, out, err) }
+ if(code !== 0 || __graph_eval === undefined) {
+ if(errback) {
+ errback(code, out, err);
+ }
} else {
- callback(__graph_eval)
+ callback(__graph_eval);
}
});
}
@@ -69,14 +71,14 @@ function _parse(file, callback, errback) {
* @api public
*/
exports.parse = function(file_or_script, callback, errback) {
- if( fsExt.exist(file_or_script) ) {
- _parse(file_or_script, callback, errback)
+ if(fsExt.exist(file_or_script)) {
+ _parse(file_or_script, callback, errback);
} else {
temp.open('node-graphviz', function(err, info) {
fs.write(info.fd, file_or_script);
fs.close(info.fd, function(err) {
- _parse(info.path, callback, errback)
+ _parse(info.path, callback, errback);
});
});
}
-}
+};

0 comments on commit b87d54a

Please sign in to comment.