Created
May 15, 2016 08:40
-
-
Save Vladislav-Kisliy/76980b64332b4e9d8aad79dcae51f611 to your computer and use it in GitHub Desktop.
StO: Visualization of graph
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.awt.Color; | |
import java.util.List; | |
import java.util.Random; | |
import org.graphstream.graph.Edge; | |
public class TestDraw { | |
private final Random rand; | |
private final List<SomeObjectWithNode> nodes; | |
public TestDraw(List<SomeObjectWithNode> k) { | |
this.nodes = k; | |
rand = new Random(); | |
} | |
public void adjust() { | |
for (SomeObjectWithNode k : nodes) { | |
k.n.addAttribute("ui.color", k.c); | |
for (Edge e : k.n.getEdgeSet()) { | |
float r = rand.nextFloat(); | |
float g = rand.nextFloat(); | |
float b = rand.nextFloat(); | |
Color randomColor = new Color(r, g, b); | |
e.setAttribute("ui.color", randomColor); | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayList; | |
import java.util.List; | |
import java.util.concurrent.TimeUnit; | |
import org.graphstream.graph.Graph; | |
import org.graphstream.graph.Node; | |
import org.graphstream.graph.implementations.SingleGraph; | |
public class TestGs { | |
public static void main(String[] args) { | |
List<SomeObjectWithNode> a = new ArrayList<>(); | |
System.setProperty("gs.ui.renderer", "org.graphstream.ui.j2dviewer.J2DGraphRenderer"); | |
Graph g = new SingleGraph("test1"); | |
g.addAttribute("ui.quality"); | |
g.addAttribute("ui.antialias"); | |
g.addAttribute("ui.stylesheet", "node { fill-mode: dyn-plain; size: 10px;} " | |
+ "edge { fill-mode: dyn-plain; size: 2px;}"); | |
g.display(); | |
a.add(new SomeObjectWithNode(g.addNode(Integer.toString(0)))); | |
Node lastNode = g.getNode("0"); | |
for (int i = 1; i < 10; i++) { | |
a.add(new SomeObjectWithNode(g.addNode(Integer.toString(i)))); | |
g.addEdge(Integer.toString(i - 1).concat(Integer.toString(i)), a.get(i).n, lastNode); | |
lastNode = a.get(i).n; | |
} | |
TestDraw t = new TestDraw(a); | |
while (true) { | |
t.adjust(); | |
try { | |
TimeUnit.SECONDS.sleep(2); | |
} catch (InterruptedException e) { | |
e.printStackTrace(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment