Created
April 20, 2014 21:27
-
-
Save AlphaGit/11125710 to your computer and use it in GitHub Desktop.
Sugiyama algorithm: removing fake nodes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var unlinkFakeNode = function (fakeNode) { | |
// fake node: remove and connect nodes that it is connecting | |
var previousNodes = fakeNode.previousNodes.slice(0); // copy since it's going to be modified | |
previousNodes.forEach(function (previousNode) { | |
// previous --> next1, previous --> next2, etc | |
fakeNode.nextNodes.forEach(function (nextNode) { | |
sugiyamaService.connectNodes(previousNode, nextNode); | |
}); | |
// previous --X--> fake | |
sugiyamaService.disconnectNodes(previousNode, fakeNode); | |
}); | |
var nextNodes = fakeNode.nextNodes.slice(0); // copy since it's going to be modified | |
nextNodes.forEach(function (nextNode) { | |
sugiyamaService.disconnectNodes(fakeNode, nextNode); | |
}); | |
}; | |
var removeFakeNodesColumn = function (column) { | |
var rowIndex = column.length; | |
while (rowIndex--) { | |
var node = column[rowIndex]; | |
if (sugiyamaService.isFakeNode(node)) { | |
unlinkFakeNode(node); | |
column.splice(rowIndex, 1); | |
} | |
} | |
}; | |
sugiyamaService.removeFakeNodes = function (grid) { | |
for (var columnIndex = 0; columnIndex < grid.length; columnIndex++) { | |
removeFakeNodesColumn(grid[columnIndex]); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment