Skip to content

Commit 0878b88

Browse files
author
brunomnsilva
committed
Fix for #22. Removing edges is now reflected in the internal representation of adjacency.
1 parent 7b3cd99 commit 0878b88

4 files changed

Lines changed: 20 additions & 3 deletions

File tree

176 Bytes
Binary file not shown.
240 Bytes
Binary file not shown.

src/com/brunomnsilva/smartgraph/Main.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import com.brunomnsilva.smartgraph.containers.SmartGraphDemoContainer;
3939
import com.brunomnsilva.smartgraph.graph.Digraph;
4040
import com.brunomnsilva.smartgraph.graph.DigraphEdgeList;
41+
import com.brunomnsilva.smartgraph.graph.Edge;
4142
import com.brunomnsilva.smartgraph.graphview.SmartCircularSortedPlacementStrategy;
4243
import com.brunomnsilva.smartgraph.graphview.SmartGraphVertex;
4344
import com.brunomnsilva.smartgraph.graphview.SmartStylableNode;

src/com/brunomnsilva/smartgraph/graphview/SmartGraphPanel.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ public class SmartGraphPanel<V, E> extends Pane {
116116
private final double repulsionForce;
117117
private final double attractionForce;
118118
private final double attractionScale;
119+
120+
//This value was obtained experimentally
121+
private static final int AUTOMATIC_LAYOUT_ITERATIONS = 20;
119122

120123
/**
121124
* Constructs a visualization of the graph referenced by
@@ -226,13 +229,13 @@ public void handle(long now) {
226229
}
227230

228231
private synchronized void runLayoutIteration() {
229-
for (int i = 0; i < 20; i++) {
232+
for (int i = 0; i < AUTOMATIC_LAYOUT_ITERATIONS; i++) {
230233
resetForces();
231234
computeForces();
232235
updateForces();
233236
}
234237
applyForces();
235-
}
238+
}
236239

237240
/**
238241
* Runs the initial current vertex placement strategy.
@@ -661,13 +664,26 @@ private void removeNodes() {
661664
for (Edge<E, V> e : removedEdges) {
662665
SmartGraphEdgeBase edgeToRemove = edgeNodes.get(e);
663666
edgeNodes.remove(e);
664-
removeEdge(edgeToRemove);
667+
removeEdge(edgeToRemove);
668+
669+
//when edges are removed, the adjacency between vertices changes
670+
//the adjacency is kept in parallel in an internal data structure
671+
Vertex<V>[] vertices = e.vertices();
672+
673+
if( getTotalEdgesBetween(vertices[0], vertices[1]) == 0 ) {
674+
SmartGraphVertexNode<V> v0 = vertexNodes.get(vertices[0]);
675+
SmartGraphVertexNode<V> v1 = vertexNodes.get(vertices[1]);
676+
677+
v0.removeAdjacentVertex(v1);
678+
v1.removeAdjacentVertex(v0);
679+
}
665680
}
666681

667682
//remove adjacencies from remaining vertices
668683
for (SmartGraphVertexNode<V> v : vertexNodes.values()) {
669684
v.removeAdjacentVertices(verticesToRemove);
670685
}
686+
671687
}
672688

673689
private void removeEdge(SmartGraphEdgeBase e) {

0 commit comments

Comments
 (0)