I created a graph that represents the road map of a certain region using Graphstream
.
Now I want to make it look like the blue node is moving on the graph and for that I'm showing the graph on another thread and, every second, I color a different node blue, like so:
public void drawGraph(List<MyCustomNodeClass> nodes, List<MyCustomEdgeClass> edges){
Graph graph = new MultiGraph("main graph");
Viewer viewer = new Viewer(graph, Viewer.ThreadingModel.GRAPH_IN_ANOTHER_THREAD);
ViewerPipe pipeIn = viewer.newViewerPipe();
viewer.addView("view1", new J2DGraphRenderer());
pipeIn.addAttributeSink(graph);
pipeIn.pump();
nodes.forEach(node-> graph.addNode(node.getId()));
edges.forEach(edge-> graph.getEdge(edge.getId(), edge.getSrc(), edge.getDest()));
Node node = graph.getNode("start");
while(true){
pipeIn.pump();
sleep(100);
node.setAttribute("ui.style", "z-index: 1; size: 3px; fill-color: black;");
node = node = node.getNeighborNodeIterator().next();;
node.setAttribute("ui.style", "z-index: 2; size: 10px; fill-color: blue;");
}
}
private void sleep(long seconds ) {
try { Thread.sleep( seconds ) ; }
catch (InterruptedException e) { e.printStackTrace(); }
}
As the title suggest, my problem is that the graph is huge (15997 edges, 9084 nodes), and it makes it such that the time it takes GraphStream
to render the graph is greater then the sleep time, so the "animation" doesn't work well.
Is there a way to make GraphStream
only render the objects that changed (only 2 node in this case)?