From 6b191f8bc9dbe32bc7c4f9bf0fe35e65336b448a Mon Sep 17 00:00:00 2001 From: wimrijnders Date: Wed, 26 Jul 2017 14:42:37 +0200 Subject: [PATCH] Network: Block recalculation of level in LayoutEngine._determineLevelsDirected() (#3294) * Levels of direct hierarchical network only incremented * Cleaned up old code * Quick fix on presence globaOptions in mergeOptions() * Revert fix, doesn't work * Network: Block recalculation of level in LayoutEngine._determineLevelsDirected() Fix for #2311. Nodes with bidirectional edges got their levels shifted due to the handling of both edge directions. This fix adds a check on bidirectionality and blocks any subsequent level adjustment. Pure tree layouts are unaffected by this change. --- lib/network/modules/LayoutEngine.js | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/network/modules/LayoutEngine.js b/lib/network/modules/LayoutEngine.js index c75505f2..76935690 100644 --- a/lib/network/modules/LayoutEngine.js +++ b/lib/network/modules/LayoutEngine.js @@ -1414,7 +1414,7 @@ class LayoutEngine { } /** - * this function allocates nodes in levels based on the direction of the edges + * Allocate nodes in levels based on the direction of the edges. * * @param hubsize * @private @@ -1422,8 +1422,30 @@ class LayoutEngine { _determineLevelsDirected() { let minLevel = 10000; + /** + * Check if there is an edge going the opposite direction for given edge + */ + let self = this; + let isBidirectional = (edge) => { + for (let key in self.body.edges) { + let otherEdge = self.body.edges[key]; + if (otherEdge.toId === edge.fromId && otherEdge.fromId === edge.toId) { + return true; + } + } + + return false; + }; + let levelByDirection = (nodeA, nodeB, edge) => { let levelA = this.hierarchical.levels[nodeA.id]; + let levelB = this.hierarchical.levels[nodeB.id]; + + if (isBidirectional(edge) && levelA !== undefined && levelB !== undefined) { + // Don't redo the level determination if already done in this case. + return; + } + // set initial level if (levelA === undefined) { levelA = this.hierarchical.levels[nodeA.id] = minLevel;} if (edge.toId == nodeB.id) {