From 446eb651eebb02bc857c421bde13aeee7a741b97 Mon Sep 17 00:00:00 2001 From: Chris Pettitt Date: Mon, 31 Mar 2014 21:04:56 -0700 Subject: [PATCH] Add debug tool for positioning phase --- lib/debug.js | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/lib/debug.js b/lib/debug.js index 416bd75a..9ab22e37 100644 --- a/lib/debug.js +++ b/lib/debug.js @@ -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; +};