diff --git a/releases/JavaFXSmartGraph-0.9.4.jar b/releases/JavaFXSmartGraph-0.9.4.jar index 3718e36..4be5370 100644 Binary files a/releases/JavaFXSmartGraph-0.9.4.jar and b/releases/JavaFXSmartGraph-0.9.4.jar differ diff --git a/releases/JavaFXSmartGraph-0.9.4.zip b/releases/JavaFXSmartGraph-0.9.4.zip index 0a85bb3..d76f57b 100644 Binary files a/releases/JavaFXSmartGraph-0.9.4.zip and b/releases/JavaFXSmartGraph-0.9.4.zip differ diff --git a/src/com/brunomnsilva/smartgraph/Main.java b/src/com/brunomnsilva/smartgraph/Main.java index 7ffde4a..9b11163 100644 --- a/src/com/brunomnsilva/smartgraph/Main.java +++ b/src/com/brunomnsilva/smartgraph/Main.java @@ -38,6 +38,7 @@ import com.brunomnsilva.smartgraph.containers.SmartGraphDemoContainer; import com.brunomnsilva.smartgraph.graph.Digraph; import com.brunomnsilva.smartgraph.graph.DigraphEdgeList; +import com.brunomnsilva.smartgraph.graph.Edge; import com.brunomnsilva.smartgraph.graphview.SmartCircularSortedPlacementStrategy; import com.brunomnsilva.smartgraph.graphview.SmartGraphVertex; import com.brunomnsilva.smartgraph.graphview.SmartStylableNode; diff --git a/src/com/brunomnsilva/smartgraph/graphview/SmartGraphPanel.java b/src/com/brunomnsilva/smartgraph/graphview/SmartGraphPanel.java index 9a03659..16c05ff 100644 --- a/src/com/brunomnsilva/smartgraph/graphview/SmartGraphPanel.java +++ b/src/com/brunomnsilva/smartgraph/graphview/SmartGraphPanel.java @@ -116,6 +116,9 @@ public class SmartGraphPanel extends Pane { private final double repulsionForce; private final double attractionForce; private final double attractionScale; + + //This value was obtained experimentally + private static final int AUTOMATIC_LAYOUT_ITERATIONS = 20; /** * Constructs a visualization of the graph referenced by @@ -226,13 +229,13 @@ public void handle(long now) { } private synchronized void runLayoutIteration() { - for (int i = 0; i < 20; i++) { + for (int i = 0; i < AUTOMATIC_LAYOUT_ITERATIONS; i++) { resetForces(); computeForces(); updateForces(); } applyForces(); - } + } /** * Runs the initial current vertex placement strategy. @@ -661,13 +664,26 @@ private void removeNodes() { for (Edge e : removedEdges) { SmartGraphEdgeBase edgeToRemove = edgeNodes.get(e); edgeNodes.remove(e); - removeEdge(edgeToRemove); + removeEdge(edgeToRemove); + + //when edges are removed, the adjacency between vertices changes + //the adjacency is kept in parallel in an internal data structure + Vertex[] vertices = e.vertices(); + + if( getTotalEdgesBetween(vertices[0], vertices[1]) == 0 ) { + SmartGraphVertexNode v0 = vertexNodes.get(vertices[0]); + SmartGraphVertexNode v1 = vertexNodes.get(vertices[1]); + + v0.removeAdjacentVertex(v1); + v1.removeAdjacentVertex(v0); + } } //remove adjacencies from remaining vertices for (SmartGraphVertexNode v : vertexNodes.values()) { v.removeAdjacentVertices(verticesToRemove); } + } private void removeEdge(SmartGraphEdgeBase e) {