Skip to content
Browse files

Remove \t

  • Loading branch information...
1 parent 16683e3 commit 2beac46fb42da29834c93e0f19134f680a3b2bb5 @glejeune committed Sep 3, 2010
Showing with 178 additions and 177 deletions.
  1. +18 −17 lib/deps/attributs.js
  2. +32 −32 lib/deps/core_ext/hash.js
  3. +15 −15 lib/deps/edge.js
  4. +96 −96 lib/deps/graph.js
  5. +10 −10 lib/deps/node.js
  6. +7 −7 lib/graphviz.js
View
35 lib/deps/attributs.js
@@ -1,29 +1,30 @@
-var Hash = require( './core_ext/hash' ).Hash;
+var Hash = require( './core_ext/hash' ).Hash,
+ sys = require('sys')
var Attributs = exports.Attributs = function() {
- this.attributs = new Hash();
+ this.attributs = new Hash();
}
Attributs.prototype.set = function( name, value ) {
- this.attributs.setItem(name, value);
+ this.attributs.setItem(name, value);
}
Attributs.prototype.get = function( name ) {
- return this.attributs.items[name];
+ return this.attributs.items[name];
}
Attributs.prototype.to_dot = function(link) {
- var attrsOutput = "";
- var sep = "";
-
- if( this.attributs.length > 0 ) {
- attrsOutput = attrsOutput + " [ "
- for( var name in this.attributs.items ) {
- attrsOutput = attrsOutput + sep + name + " = " + this.attributs.items[name]
- sep = ", "
- }
- attrsOutput = attrsOutput + " ]"
- }
-
- return attrsOutput;
+ var attrsOutput = "";
+ var sep = "";
+
+ if( this.attributs.length > 0 ) {
+ attrsOutput = attrsOutput + " [ "
+ for( var name in this.attributs.items ) {
+ attrsOutput = attrsOutput + sep + name + " = " + this.attributs.items[name]
+ sep = ", "
+ }
+ attrsOutput = attrsOutput + " ]"
+ }
+
+ return attrsOutput;
}
View
64 lib/deps/core_ext/hash.js
@@ -1,53 +1,53 @@
var Hash = exports.Hash = function() {
- this.length = 0;
- this.items = new Array();
- for (var i = 0; i < arguments.length; i += 2) {
- if (typeof(arguments[i + 1]) != 'undefined') {
- this.items[arguments[i]] = arguments[i + 1];
- this.length++;
- }
- }
+ this.length = 0;
+ this.items = new Array();
+ for (var i = 0; i < arguments.length; i += 2) {
+ if (typeof(arguments[i + 1]) != 'undefined') {
+ this.items[arguments[i]] = arguments[i + 1];
+ this.length++;
+ }
+ }
}
Hash.prototype.removeItem = function(in_key) {
- var tmp_previous;
- if (typeof(this.items[in_key]) != 'undefined') {
- this.length--;
- var tmp_previous = this.items[in_key];
- delete this.items[in_key];
- }
+ var tmp_previous;
+ if (typeof(this.items[in_key]) != 'undefined') {
+ this.length--;
+ var tmp_previous = this.items[in_key];
+ delete this.items[in_key];
+ }
- return tmp_previous;
+ return tmp_previous;
}
Hash.prototype.getItem = function(in_key) {
- return this.items[in_key];
+ return this.items[in_key];
}
Hash.prototype.setItem = function(in_key, in_value) {
- var tmp_previous;
- if (typeof(in_value) != 'undefined') {
- if (typeof(this.items[in_key]) == 'undefined') {
- this.length++;
- }
- else {
- tmp_previous = this.items[in_key];
- }
+ var tmp_previous;
+ if (typeof(in_value) != 'undefined') {
+ if (typeof(this.items[in_key]) == 'undefined') {
+ this.length++;
+ }
+ else {
+ tmp_previous = this.items[in_key];
+ }
- this.items[in_key] = in_value;
- }
+ this.items[in_key] = in_value;
+ }
- return tmp_previous;
+ return tmp_previous;
}
Hash.prototype.hasItem = function(in_key) {
- return typeof(this.items[in_key]) != 'undefined';
+ return typeof(this.items[in_key]) != 'undefined';
}
Hash.prototype.clear = function() {
- for (var i in this.items) {
- delete this.items[i];
- }
+ for (var i in this.items) {
+ delete this.items[i];
+ }
- this.length = 0;
+ this.length = 0;
}
View
30 lib/deps/edge.js
@@ -1,28 +1,28 @@
var Hash = require( './core_ext/hash' ).Hash,
- Attributs = require( './attributs' ).Attributs;
+ Attributs = require( './attributs' ).Attributs;
var Edge = exports.Edge = function(graph, nodeOne, nodeTwo) {
- this.relativeGraph = graph;
- this.nodeOne = nodeOne;
- this.nodeTwo = nodeTwo;
- this.attributs = new Attributs();
+ this.relativeGraph = graph;
+ this.nodeOne = nodeOne;
+ this.nodeTwo = nodeTwo;
+ this.attributs = new Attributs();
};
Edge.prototype.set = function( name, value ) {
- this.attributs.set(name, value);
+ this.attributs.set(name, value);
}
Edge.prototype.get = function( name ) {
- return this.attributs.get(name);
+ return this.attributs.get(name);
}
Edge.prototype.to_dot = function() {
- var edgeLink = "->";
- if( this.relativeGraph.type == "graph" ) {
- edgeLink = "--";
- }
-
- var edgeOutput = this.nodeOne.id + " " + edgeLink + " " + this.nodeTwo.id;
- edgeOutput = edgeOutput + this.attributs.to_dot()
- return edgeOutput;
+ var edgeLink = "->";
+ if( this.relativeGraph.type == "graph" ) {
+ edgeLink = "--";
+ }
+
+ var edgeOutput = this.nodeOne.id + " " + edgeLink + " " + this.nodeTwo.id;
+ edgeOutput = edgeOutput + this.attributs.to_dot()
+ return edgeOutput;
}
View
192 lib/deps/graph.js
@@ -1,20 +1,20 @@
var Hash = require( './core_ext/hash' ).Hash,
- Node = require( './node' ).Node,
- Edge = require( './edge' ).Edge,
- sys = require('sys'),
- fs = require('fs'),
- exec = require('child_process').exec,
+ Node = require( './node' ).Node,
+ Edge = require( './edge' ).Edge,
+ sys = require('sys'),
+ fs = require('fs'),
+ exec = require('child_process').exec,
child;
var Graph = exports.Graph = function(graph, id) {
- this.relativeGraph = graph;
- this.id = id;
- this.type = "graph";
- this.gvPath = "";
- this.nodes = new Hash();
- this.edges = new Array();
- this.clusters = new Hash();
- this.graphAttributs = new Hash();
+ this.relativeGraph = graph;
+ this.id = id;
+ this.type = "graph";
+ this.gvPath = "";
+ this.nodes = new Hash();
+ this.edges = new Array();
+ this.clusters = new Hash();
+ this.graphAttributs = new Hash();
};
//
@@ -23,129 +23,129 @@ var Graph = exports.Graph = function(graph, id) {
// This method may not be called directly but internaly
//
Graph.prototype.setType = function(type) {
- this.type = type;
+ this.type = type;
}
Graph.prototype.getType = function(type) {
- return this.type;
+ return this.type;
}
Graph.prototype.addNode = function(id) {
- this.nodes.setItem(id, new Node(this, id));
- return this.nodes.items[id];
+ this.nodes.setItem(id, new Node(this, id));
+ return this.nodes.items[id];
}
Graph.prototype.getNode = function(id) {
- return this.nodes.items[id];
+ return this.nodes.items[id];
}
Graph.prototype.nodeCount = function() {
- return this.nodes.length;
+ return this.nodes.length;
}
Graph.prototype.addEdge = function(nodeOne, nodeTwo) {
- var _nodeOne = nodeOne;
- var _nodeTwo = nodeTwo;
- if( typeof(nodeOne) == 'string' ) {
- _nodeOne = this.nodes.items[nodeOne];
- if( _nodeOne == null ) {
- _nodeOne = this.addNode( nodeOne );
- }
- }
- if( typeof(nodeTwo) == 'string' ) {
- _nodeTwo = this.nodes.items[nodeTwo];
- if( _nodeTwo == null ) {
- _nodeTwo = this.addNode( nodeTwo );
- }
- }
-
- var edge = new Edge(this, _nodeOne, _nodeTwo);
- this.edges.push( edge );
-
- return edge;
+ var _nodeOne = nodeOne;
+ var _nodeTwo = nodeTwo;
+ if( typeof(nodeOne) == 'string' ) {
+ _nodeOne = this.nodes.items[nodeOne];
+ if( _nodeOne == null ) {
+ _nodeOne = this.addNode( nodeOne );
+ }
+ }
+ if( typeof(nodeTwo) == 'string' ) {
+ _nodeTwo = this.nodes.items[nodeTwo];
+ if( _nodeTwo == null ) {
+ _nodeTwo = this.addNode( nodeTwo );
+ }
+ }
+
+ var edge = new Edge(this, _nodeOne, _nodeTwo);
+ this.edges.push( edge );
+
+ return edge;
}
Graph.prototype.edgeCount = function() {
- return this.edges.length;
+ return this.edges.length;
};
Graph.prototype.addCluster = function(id) {
- var cluster = new Graph(this, id);
- cluster.setType( this.type );
- this.clusters.setItem(id, cluster);
- return cluster;
+ var cluster = new Graph(this, id);
+ cluster.setType( this.type );
+ this.clusters.setItem(id, cluster);
+ return cluster;
}
Graph.prototype.getCluster = function(id) {
- return this.clusters.items[id];
+ return this.clusters.items[id];
}
Graph.prototype.clusterCount = function() {
- return this.clusters.length;
+ return this.clusters.length;
}
Graph.prototype.set = function(name, value) {
- this.graphAttributs.setItem(name, value);
+ this.graphAttributs.setItem(name, value);
}
Graph.prototype.get = function(name) {
- return this.graphAttributs.items[name];
+ return this.graphAttributs.items[name];
}
Graph.prototype.to_dot = function() {
- var dotScript = "";
- if( this.relativeGraph == null ) {
- dotScript = this.type + " " + this.id + " {\n"
- } else {
- dotScript = "subgraph " + this.id + " {\n"
- }
-
- // Graph attributs
- for( var name in this.graphAttributs.items ) {
- dotScript = dotScript + " " + name + " = \"" + this.graphAttributs.items[name] + "\";\n"
- }
-
- // Each clusters
- for( var id in this.clusters.items ) {
- dotScript = dotScript + this.clusters.items[id].to_dot() + "\n"
- }
-
- // Each nodes
- for( var id in this.nodes.items ) {
- dotScript = dotScript + " " + this.nodes.items[id].to_dot() + ";\n"
- }
-
- // Each edges
- for( var i in this.edges ) {
- // dotScript = dotScript + " " + this.edges[i].nodeOne.id + " " + edgeLink + " " + this.edges[i].nodeTwo.id + ";\n"
- dotScript = dotScript + " " + this.edges[i].to_dot() + ";\n"
- }
-
- dotScript = dotScript + "}\n"
-
- return dotScript;
+ var dotScript = "";
+ if( this.relativeGraph == null ) {
+ dotScript = this.type + " " + this.id + " {\n"
+ } else {
+ dotScript = "subgraph " + this.id + " {\n"
+ }
+
+ // Graph attributs
+ for( var name in this.graphAttributs.items ) {
+ dotScript = dotScript + " " + name + " = \"" + this.graphAttributs.items[name] + "\";\n"
+ }
+
+ // Each clusters
+ for( var id in this.clusters.items ) {
+ dotScript = dotScript + this.clusters.items[id].to_dot() + "\n"
+ }
+
+ // Each nodes
+ for( var id in this.nodes.items ) {
+ dotScript = dotScript + " " + this.nodes.items[id].to_dot() + ";\n"
+ }
+
+ // Each edges
+ for( var i in this.edges ) {
+ // dotScript = dotScript + " " + this.edges[i].nodeOne.id + " " + edgeLink + " " + this.edges[i].nodeTwo.id + ";\n"
+ dotScript = dotScript + " " + this.edges[i].to_dot() + ";\n"
+ }
+
+ dotScript = dotScript + "}\n"
+
+ return dotScript;
}
Graph.prototype.output = function(type, name) {
- var dotFile = name+".dot"
- fs.writeFile(dotFile, this.to_dot(), function (err) {
- if (err) throw err;
- });
-
- var cmd = this.gvPath + "dot -T" + type + " -o" + name + " " + dotFile;
- child = exec(cmd,
- function (error, stdout, stderr) {
- sys.print('stdout: ' + stdout + "\n");
- sys.print('stderr: ' + stderr + "\n");
- if (error !== null) {
- console.log('exec error: ' + error);
- }
- });
-
- // TODO: this does not work ! -- Need a Tempfile class "à la" Ruby
- // fs.unlink(dotFile);
+ var dotFile = name+".dot"
+ fs.writeFile(dotFile, this.to_dot(), function (err) {
+ if (err) throw err;
+ });
+
+ var cmd = this.gvPath + "dot -T" + type + " -o" + name + " " + dotFile;
+ child = exec(cmd,
+ function (error, stdout, stderr) {
+ sys.print('stdout: ' + stdout + "\n");
+ sys.print('stderr: ' + stderr + "\n");
+ if (error !== null) {
+ console.log('exec error: ' + error);
+ }
+ });
+
+ // TODO: this does not work ! -- Need a Tempfile class "à la" Ruby
+ // fs.unlink(dotFile);
}
Graph.prototype.setGraphVizPath = function(path) {
- this.gvPath = path + "/";
+ this.gvPath = path + "/";
}
View
20 lib/deps/node.js
@@ -1,29 +1,29 @@
var Hash = require( './core_ext/hash' ).Hash,
- Attributs = require( './attributs' ).Attributs;
+ Attributs = require( './attributs' ).Attributs;
var Node = exports.Node = function(graph, id) {
- this.relativeGraph = graph;
- this.id = id;
- this.attributs = new Attributs();
+ this.relativeGraph = graph;
+ this.id = id;
+ this.attributs = new Attributs();
};
Node.prototype.setId = function(id) {
- this.id = id
+ this.id = id
}
Node.prototype.id = function() {
- return this.id;
+ return this.id;
}
Node.prototype.set = function( name, value ) {
- this.attributs.set(name, value);
+ this.attributs.set(name, value);
}
Node.prototype.get = function( name ) {
- return this.attributs.get(name);
+ return this.attributs.get(name);
}
Node.prototype.to_dot = function() {
- var nodeOutput = this.id + this.attributs.to_dot();
- return nodeOutput;
+ var nodeOutput = this.id + this.attributs.to_dot();
+ return nodeOutput;
}
View
14 lib/graphviz.js
@@ -1,14 +1,14 @@
var sys = require('sys'),
- Graph = require('./deps/graph').Graph;
+ Graph = require('./deps/graph').Graph;
exports.graph = function(id) {
- var graph = new Graph(null, id);
- graph.setType( 'graph' );
- return graph;
+ var graph = new Graph(null, id);
+ graph.setType( 'graph' );
+ return graph;
}
exports.digraph = function(id) {
- var graph = new Graph(null, id);
- graph.setType( 'digraph' );
- return graph;
+ var graph = new Graph(null, id);
+ graph.setType( 'digraph' );
+ return graph;
}

0 comments on commit 2beac46

Please sign in to comment.
Something went wrong with that request. Please try again.