Skip to content
This repository has been archived by the owner on Jul 29, 2019. It is now read-only.

Commit

Permalink
Network: Block recalculation of level in LayoutEngine._determineLevel…
Browse files Browse the repository at this point in the history
…sDirected() (#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.
  • Loading branch information
wimrijnders authored and yotamberk committed Jul 26, 2017
1 parent 435a2ab commit 6b191f8
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion lib/network/modules/LayoutEngine.js
Original file line number Diff line number Diff line change
Expand Up @@ -1414,16 +1414,38 @@ 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
*/
_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) {
Expand Down

0 comments on commit 6b191f8

Please sign in to comment.