Skip to content

Commit

Permalink
Fix for #22. Removing edges is now reflected in the internal represen…
Browse files Browse the repository at this point in the history
…tation of adjacency.
  • Loading branch information
brunomnsilva committed Aug 3, 2021
1 parent 7b3cd99 commit 0878b88
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
Binary file modified releases/JavaFXSmartGraph-0.9.4.jar
Binary file not shown.
Binary file modified releases/JavaFXSmartGraph-0.9.4.zip
Binary file not shown.
1 change: 1 addition & 0 deletions src/com/brunomnsilva/smartgraph/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
22 changes: 19 additions & 3 deletions src/com/brunomnsilva/smartgraph/graphview/SmartGraphPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ public class SmartGraphPanel<V, E> 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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -661,13 +664,26 @@ private void removeNodes() {
for (Edge<E, V> 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<V>[] vertices = e.vertices();

if( getTotalEdgesBetween(vertices[0], vertices[1]) == 0 ) {
SmartGraphVertexNode<V> v0 = vertexNodes.get(vertices[0]);
SmartGraphVertexNode<V> v1 = vertexNodes.get(vertices[1]);

v0.removeAdjacentVertex(v1);
v1.removeAdjacentVertex(v0);
}
}

//remove adjacencies from remaining vertices
for (SmartGraphVertexNode<V> v : vertexNodes.values()) {
v.removeAdjacentVertices(verticesToRemove);
}

}

private void removeEdge(SmartGraphEdgeBase e) {
Expand Down

0 comments on commit 0878b88

Please sign in to comment.