From d10af36749fde8f8e8b6e17617cd67e0257349e4 Mon Sep 17 00:00:00 2001 From: Anton Ivanov Date: Mon, 27 Jul 2020 21:52:11 +0300 Subject: [PATCH] add disableOptimalOrder options --- lib/layout.js | 8 ++++---- lib/order/index.js | 6 +++++- 2 files changed, 9 insertions(+), 5 deletions(-) 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;