diff --git a/lib/layout.js b/lib/layout.js index 26b07304..df006b23 100644 --- a/lib/layout.js +++ b/lib/layout.js @@ -20,14 +20,14 @@ module.exports = layout; function layout(g, opts) { var time = opts && opts.debugTiming ? util.time : util.notime; time("layout", function() { - var layoutGraph = + var layoutGraph = time(" buildLayoutGraph", function() { return buildLayoutGraph(g); }); - time(" runLayout", function() { runLayout(layoutGraph, time); }); + time(" runLayout", function() { runLayout(layoutGraph, time, opts); }); time(" updateInputGraph", function() { updateInputGraph(g, layoutGraph); }); }); } -function runLayout(g, time) { +function runLayout(g, time, opts) { time(" makeSpaceForEdgeLabels", function() { makeSpaceForEdgeLabels(g); }); time(" removeSelfEdges", function() { removeSelfEdges(g); }); time(" acyclic", function() { acyclic.run(g); }); @@ -42,7 +42,7 @@ function runLayout(g, time) { time(" normalize.run", function() { normalize.run(g); }); time(" parentDummyChains", function() { parentDummyChains(g); }); time(" addBorderSegments", function() { addBorderSegments(g); }); - time(" order", function() { order(g); }); + time(" order", function() { order(g, opts); }); time(" insertSelfEdges", function() { insertSelfEdges(g); }); time(" adjustCoordinateSystem", function() { coordinateSystem.adjust(g); }); time(" position", function() { position(g); }); diff --git a/lib/order/index.js b/lib/order/index.js index 4ac2d9fa..ba8d35cc 100644 --- a/lib/order/index.js +++ b/lib/order/index.js @@ -26,7 +26,7 @@ module.exports = order; * 1. Graph nodes will have an "order" attribute based on the results of the * algorithm. */ -function order(g) { +function order(g, opts) { var maxRank = util.maxRank(g), downLayerGraphs = buildLayerGraphs(g, _.range(1, maxRank + 1), "inEdges"), upLayerGraphs = buildLayerGraphs(g, _.range(maxRank - 1, -1, -1), "outEdges"); @@ -34,6 +34,10 @@ function order(g) { var layering = initOrder(g); assignOrder(g, layering); + if (opts && opts.disableOptimalOrder) { + return; + } + var bestCC = Number.POSITIVE_INFINITY, best;