Skip to content

Commit

Permalink
issue #21: Dump arch / plan to Graphviz formats
Browse files Browse the repository at this point in the history
  • Loading branch information
afelix committed Apr 12, 2012
1 parent dcde819 commit a8413a9
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions lib/arch.js
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,18 @@ module.exports = INHERIT({
}, this).join('')
},

/**
* Dump this arch to Graphviz string for debug purposes.
*
* @returns {String} Graphviz string representation of this arch.
*/
toGraphviz: function() {
return 'digraph G {\n' +
this.findRoots().map(function(r) {
return this.nodeToGraphviz(r)
}, this).join('') + '}\n';
},

/**
* Dump node with its children to string.
*
Expand All @@ -373,6 +385,27 @@ module.exports = INHERIT({
this.children[id].map(function(c) {
return spaces + this.nodeToString(c, spaces + ' ')
}, this).join('')
},

/**
* Dump node with its children to Graphviz string.
*
* @param {String} id Node ID to dump.
*/
nodeToGraphviz: function(id) {
var _this = this,
thisNode = '"' + id + '"',
s = ' ' + thisNode + ';\n',
children = this.children[id] || [];

children.forEach(function(child) {
s += ' ' + thisNode + ' -> "' + child + '";\n';
});
children.forEach(function(child) {
s += _this.nodeToGraphviz(child);
});

return s;
}

});

0 comments on commit a8413a9

Please sign in to comment.