Skip to content

Commit

Permalink
Add debug tool for positioning phase
Browse files Browse the repository at this point in the history
  • Loading branch information
cpettitt committed Apr 1, 2014
1 parent 0819d23 commit 446eb65
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions lib/debug.js
Expand Up @@ -53,3 +53,39 @@ exports.dotOrdering = function(g) {

return result;
};

/**
* Renders a graph in a stringified DOT format that indicates the position of
* of all of the nodes in the graph. This is best used with neato - dot does
* not appear to respect position information.
*/
exports.dotPositioning = function(g) {
var result = 'digraph {',
scale = 0.1; // scale factor for graphviz

g.eachNode(function(u, attrs) {
if (!g.children(u).length) {
result += u + ' [pos="' + (attrs.x * scale) + ',' + (-attrs.y * scale) + '!"';
if (attrs.dummy) {
result += ', shape=diamond';
} else if (attrs.rightBorderSegment) {
result += ', shape=larrow';
} else if (attrs.leftBorderSegment) {
result += ', shape=rarrow';
} else if (attrs.nestingGraphTop) {
result += ', shape=invtriangle';
} else if (attrs.nestingGraphBottom) {
result += ', shape=triangle';
}
result += ', label="' + u + ' ' + attrs.x + ',' + attrs.y + '"];';
}
});

g.eachEdge(function(e, u, v) {
result += u + '->' + v + ';';
});

result += '}';

return result;
};

0 comments on commit 446eb65

Please sign in to comment.