This repository has been archived by the owner on Nov 13, 2020. It is now read-only.
Fix issue #71 (endless loop in mxHierarchicalLayout) #72
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
import com.mxgraph.layout.hierarchical.stage.mxHierarchicalLayoutStage; | ||
import com.mxgraph.layout.hierarchical.stage.mxMedianHybridCrossingReduction; | ||
import com.mxgraph.layout.hierarchical.stage.mxMinimumCycleRemover; | ||
import com.mxgraph.model.mxCell; | ||
import com.mxgraph.model.mxGraphModel; | ||
import com.mxgraph.model.mxIGraphModel; | ||
import com.mxgraph.view.mxCellState; | ||
|
@@ -409,13 +410,22 @@ public Set<Object> filterDescendants(Object cell) | |
for (int i = 0; i < childCount; i++) | ||
{ | ||
Object child = model.getChildAt(cell, i); | ||
result.addAll(filterDescendants(child)); | ||
|
||
// Ignore ports in the layout vertex list, they are dealt with | ||
// in the traversal mechanisms | ||
if (!isPort((mxCell) child)) { | ||
result.addAll(filterDescendants(child)); | ||
} | ||
} | ||
} | ||
|
||
return result; | ||
} | ||
|
||
private boolean isPort(mxCell cell) { | ||
return cell.getGeometry().isRelative(); | ||
} | ||
|
||
/** | ||
* Traverses the (directed) graph invoking the given function for each | ||
* visited vertex and edge. The function is invoked with the current vertex | ||
|
@@ -456,19 +466,51 @@ protected void traverse(Object vertex, boolean directed, Object edge, | |
|
||
int edgeCount = model.getEdgeCount(vertex); | ||
|
||
boolean[] edgeIsSource = new boolean[edgeCount]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe add a comment like: "// caching for performance reasons" |
||
if (edgeCount > 0) { | ||
for (int i = 0; i < edgeCount; i++) { | ||
Object e = model.getEdgeAt(vertex, i); | ||
edgeIsSource[i] = view.getVisibleTerminal(e, true) == vertex; | ||
} | ||
} | ||
|
||
if (edgeCount > 0) | ||
{ | ||
for (int i = 0; i < edgeCount; i++) | ||
{ | ||
Object e = model.getEdgeAt(vertex, i); | ||
boolean isSource = view.getVisibleTerminal(e, true) == vertex; | ||
|
||
if (!directed || isSource) | ||
if (!directed || edgeIsSource[i]) | ||
{ | ||
Object next = view.getVisibleTerminal(e, !isSource); | ||
traverse(next, directed, e, allVertices, | ||
currentComp, hierarchyVertices, | ||
filledVertexSet); | ||
Object next = view.getVisibleTerminal(e, !edgeIsSource[i]); | ||
|
||
// Check whether there are more edges incoming from the target vertex than outgoing | ||
// The hierarchical model treats bi-directional parallel edges as being sourced | ||
// from the more "sourced" terminal. If the directions are equal in number, the direction | ||
// is that of the natural direction from the roots of the layout. | ||
// The checks below are slightly more verbose than need be for performance reasons | ||
Comment on lines
+487
to
+491
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. space indents should be tabs |
||
int netCount = 1; | ||
|
||
for (int j = 0; j < edgeCount; j++) { | ||
if (j != i) { | ||
boolean isSorce2 = edgeIsSource[j]; | ||
Object e2 = model.getEdgeAt(vertex, j); | ||
Object otherTerm = view.getVisibleTerminal(e2, !isSorce2); | ||
if (otherTerm == next) { | ||
if (isSorce2) { | ||
netCount++; | ||
} else { | ||
netCount--; | ||
} | ||
} | ||
} | ||
} | ||
|
||
if (netCount >= 0){ | ||
traverse(next, directed, e, allVertices, | ||
currentComp, hierarchyVertices, | ||
filledVertexSet); | ||
} | ||
} | ||
} | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
space indents should be tabs