Skip to content

Commit 09c3757

Browse files
committed
Modify examples to illustrate different instantiations.
1 parent 6ffdc03 commit 09c3757

File tree

2 files changed

+21
-30
lines changed

2 files changed

+21
-30
lines changed

src/main/java/com/brunomnsilva/smartgraph/examples/cities/Main.java

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import com.brunomnsilva.smartgraph.graph.Vertex;
3131
import com.brunomnsilva.smartgraph.graphview.SmartCircularSortedPlacementStrategy;
3232
import com.brunomnsilva.smartgraph.graphview.SmartGraphPanel;
33-
import com.brunomnsilva.smartgraph.graphview.SmartGraphProperties;
3433
import javafx.application.Application;
3534
import javafx.scene.Scene;
3635
import javafx.stage.Stage;
@@ -46,7 +45,8 @@ public class Main extends Application {
4645
public void start(Stage ignored) {
4746

4847
Graph<City, Distance> distances = new GraphEdgeList<>();
49-
48+
49+
/* Vertex radius will be derived from the city's population */
5050
Vertex<City> prague = distances.insertVertex(new City("Prague", 1.3f));
5151
Vertex<City> tokyo = distances.insertVertex(new City("Tokyo", 37.5f));
5252
Vertex<City> beijing = distances.insertVertex(new City("Beijing", 21.5f));
@@ -63,37 +63,25 @@ public void start(Stage ignored) {
6363
distances.insertEdge(prague, helsinky, new Distance(1845));
6464
distances.insertEdge(beijing, london, new Distance(8132));
6565

66-
/* Only Java 15 allows for multi-line strings. */
67-
String customProps = "edge.label = true" + "\n" + "edge.arrow = true";
68-
69-
SmartGraphProperties properties = new SmartGraphProperties(customProps);
70-
71-
SmartGraphPanel<City, Distance> graphView = new SmartGraphPanel<>(distances, properties, new SmartCircularSortedPlacementStrategy());
72-
66+
SmartGraphPanel<City, Distance> graphView = new SmartGraphPanel<>(distances, new SmartCircularSortedPlacementStrategy());
67+
7368
Scene scene = new Scene(new SmartGraphDemoContainer(graphView), 1024, 768);
7469

7570
Stage stage = new Stage(StageStyle.DECORATED);
7671
stage.setTitle("JavaFX SmartGraph City Distances");
77-
stage.setMinHeight(500);
7872
stage.setMinWidth(800);
73+
stage.setMinHeight(400);
7974
stage.setScene(scene);
8075
stage.show();
8176

8277
graphView.init();
83-
84-
//graphView.setAutomaticLayout(true);
85-
86-
/* You can manually place vertices at any time. However, these are
87-
absolute coordinates inside the container panel.
88-
Careful choice of a panel's background image can allow you to overlay
89-
the vertices over a, e.g., world map.
90-
*/
91-
graphView.setVertexPosition(beijing, 100, 100);
92-
graphView.setVertexPosition(helsinky, 924, 100);
93-
graphView.setVertexPosition(london, 200, 668);
94-
graphView.setVertexPosition(prague, 824, 668);
95-
graphView.setVertexPosition(tokyo, 512, 200);
96-
graphView.setVertexPosition(newYork, 512, 400);
78+
79+
graphView.setVertexPosition(beijing, 520, 284); // Center-ish
80+
graphView.setVertexPosition(tokyo, 820, 250); // Far right-top
81+
graphView.setVertexPosition(newYork, 150, 600); // Far left-bottom
82+
graphView.setVertexPosition(london, 250, 200); // Left-top
83+
graphView.setVertexPosition(prague, 450, 600); // Center-bottom
84+
graphView.setVertexPosition(helsinky,650, 120); // Right-top
9785

9886
/*
9987
* This illustrates setting an image to the background of a node.

src/main/java/com/brunomnsilva/smartgraph/examples/dynamic/Main.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,13 @@ public class Main extends Application {
5151
public void start(Stage ignored) {
5252

5353
Graph<String, String> g = build_sample_graph();
54-
54+
55+
String customProps = "edge.label = false" + "\n" + "vertex.label = false";
56+
SmartGraphProperties properties = new SmartGraphProperties(customProps);
57+
5558
SmartPlacementStrategy initialPlacement = new SmartCircularSortedPlacementStrategy();
56-
ForceDirectedLayoutStrategy<String> automaticPlacementStrategy = new ForceDirectedSpringGravityLayoutStrategy<>();
5759

58-
SmartGraphPanel<String, String> graphView = new SmartGraphPanel<>(g, initialPlacement, automaticPlacementStrategy);
60+
SmartGraphPanel<String, String> graphView = new SmartGraphPanel<>(g, properties, initialPlacement);
5961
graphView.setAutomaticLayout(true);
6062

6163
Scene scene = new Scene(new SmartGraphDemoContainer(graphView), 1024, 768);
@@ -67,8 +69,9 @@ public void start(Stage ignored) {
6769
stage.setScene(scene);
6870
stage.show();
6971

72+
7073
// Programmatically define the radius of a vertex. In this case the vertex size will increase with its connectivity
71-
graphView.setVertexRadiusProvider(vertexElement -> 10 + getIncidentEdgeCount(g, vertexElement) * 1.5);
74+
graphView.setVertexRadiusProvider(vertexElement -> properties.getVertexRadius() + getIncidentEdgeCount(g, vertexElement) * 1.5);
7275

7376
/* Double click will remove a vertex */
7477
graphView.setVertexDoubleClickAction((SmartGraphVertex<String> graphVertex) -> {
@@ -127,14 +130,14 @@ private Graph<String, String> build_sample_graph() {
127130
private void continuously_test_adding_elements(Graph<String, String> g, SmartGraphPanel<String, String> graphView) {
128131
//update graph
129132
running = true;
130-
final long ITERATION_WAIT = 3000; //milliseconds
133+
final long ITERATION_WAIT = 500; //milliseconds
131134

132135
Runnable r;
133136
r = () -> {
134137
int count = 0;
135138

136139
try {
137-
Thread.sleep(5000);
140+
Thread.sleep(1000);
138141
} catch (InterruptedException ex) {
139142
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
140143
}

0 commit comments

Comments
 (0)