use of org.graphstream.ui.view.ViewerPipe in project gs-ui-javafx by graphstream.
the class TestSize method run.
private void run() {
MultiGraph graph = new MultiGraph("Test Size");
Viewer viewer = new FxViewer(graph, FxViewer.ThreadingModel.GRAPH_IN_ANOTHER_THREAD);
ViewerPipe pipeIn = viewer.newViewerPipe();
FxDefaultView view = (FxDefaultView) viewer.addView("view1", new FxGraphRenderer());
DefaultApplication.init(view, graph);
new Thread(() -> Application.launch(DefaultApplication.class)).start();
pipeIn.addAttributeSink(graph);
pipeIn.addViewerListener(this);
pipeIn.pump();
graph.setAttribute("ui.stylesheet", styleSheet);
graph.setAttribute("ui.antialias");
graph.setAttribute("ui.quality");
Node A = graph.addNode("A");
Node B = graph.addNode("B");
Node C = graph.addNode("C");
Node D = graph.addNode("D");
Edge AB = graph.addEdge("AB", "A", "B", true);
Edge BC = graph.addEdge("BC", "B", "C", true);
Edge CD = graph.addEdge("CD", "C", "D", true);
Edge DA = graph.addEdge("DA", "D", "A", true);
Edge BB = graph.addEdge("BB", "B", "B", true);
A.setAttribute("xyz", new double[] { 0, 1, 0 });
B.setAttribute("xyz", new double[] { 1, 1, 0 });
C.setAttribute("xyz", new double[] { 1, 0, 0 });
D.setAttribute("xyz", new double[] { 0, 0, 0 });
AB.setAttribute("ui.label", "AB");
BC.setAttribute("ui.label", "A Long label ...");
CD.setAttribute("ui.label", "CD");
BB.setAttribute("ui.label", "BB");
SpriteManager sm = new SpriteManager(graph);
Sprite S1 = sm.addSprite("S1");
S1.attachToNode("C");
S1.setPosition(StyleConstants.Units.PX, 40, 45, 0);
double size = 20f;
double sizeInc = 1f;
while (loop) {
pipeIn.pump();
sleep(40);
A.setAttribute("ui.size", size);
// A.setAttribute( "ui.size", "%spx".format( size ) )
BC.setAttribute("ui.size", size);
S1.setAttribute("ui.size", size);
size += sizeInc;
if (size > 50) {
sizeInc = -1f;
size = 50f;
} else if (size < 20) {
sizeInc = 1f;
size = 20f;
}
}
System.out.println("bye bye");
System.exit(0);
}
use of org.graphstream.ui.view.ViewerPipe in project gs-ui-javafx by graphstream.
the class TestSprite method run.
private void run() {
graph = new MultiGraph("TestSprites");
Viewer viewer = graph.display(true);
ViewerPipe pipeIn = viewer.newViewerPipe();
DorogovtsevMendesGenerator gen = new DorogovtsevMendesGenerator();
pipeIn.addAttributeSink(graph);
pipeIn.addViewerListener(this);
pipeIn.pump();
System.out.println(NODE_COUNT + " nodes, " + SPRITE_COUNT + " sprites%n");
graph.setAttribute("ui.default.title", "Layout Test");
graph.setAttribute("ui.antialias");
graph.setAttribute("ui.stylesheet", styleSheet);
gen.addSink(graph);
// gen.setDirectedEdges( true, true )
gen.begin();
int i = 0;
while (i < NODE_COUNT) {
gen.nextEvents();
i += 1;
}
gen.end();
sleep(1000);
addSprites();
while (loop) {
pipeIn.pump();
moveSprites();
sleep(10);
}
System.out.println("bye bye");
System.exit(0);
}
use of org.graphstream.ui.view.ViewerPipe in project gs-ui-javafx by graphstream.
the class TestShapeDecor method start.
public void start(Stage primaryStage) throws Exception {
MultiGraph graph = new MultiGraph("Shape Decor");
Viewer viewer = new FxViewer(graph, FxViewer.ThreadingModel.GRAPH_IN_ANOTHER_THREAD);
ViewerPipe pipeIn = viewer.newViewerPipe();
FxDefaultView view = (FxDefaultView) viewer.addView("view1", new FxGraphRenderer());
view.resize(500, 430);
Scene scene = new Scene(view, 500, 430, true, SceneAntialiasing.DISABLED);
primaryStage.setScene(scene);
primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>() {
@Override
public void handle(WindowEvent t) {
Platform.exit();
System.exit(0);
}
});
primaryStage.show();
pipeIn.addAttributeSink(graph);
pipeIn.addViewerListener(this);
pipeIn.pump();
graph.setAttribute("ui.stylesheet", styleSheet);
graph.setAttribute("ui.antialias");
graph.setAttribute("ui.quality");
Node A = graph.addNode("A");
Node B = graph.addNode("B");
Node C = graph.addNode("C");
Node D = graph.addNode("D");
Node E = graph.addNode("E");
Node F = graph.addNode("F");
Node G = graph.addNode("G");
Node U = graph.addNode("U");
Node V = graph.addNode("V");
Node W = graph.addNode("W");
Node X = graph.addNode("X");
Node Y = graph.addNode("Y");
Node Z = graph.addNode("Z");
Node T = graph.addNode("T");
graph.addNode("a");
graph.addNode("b");
graph.addNode("c");
graph.addNode("d");
graph.addNode("e");
graph.addNode("f");
graph.addNode("g");
graph.addNode("u");
graph.addNode("v");
graph.addNode("w");
graph.addNode("x");
graph.addNode("y");
graph.addNode("z");
graph.addNode("t");
graph.addNode("i");
graph.addNode("j");
Edge au = graph.addEdge("au", "a", "u");
Edge bv = graph.addEdge("bv", "b", "v");
Edge cw = graph.addEdge("cw", "c", "w");
Edge dx = graph.addEdge("dx", "d", "x");
Edge ey = graph.addEdge("ey", "e", "y");
Edge fz = graph.addEdge("fz", "f", "z");
Edge gt = graph.addEdge("gt", "g", "t");
Edge ij = graph.addEdge("ij", "i", "j");
Edge AU = graph.addEdge("AU", "A", "U");
Edge BV = graph.addEdge("BV", "B", "V");
Edge CW = graph.addEdge("CW", "C", "W");
Edge DX = graph.addEdge("DX", "D", "X");
Edge EY = graph.addEdge("EY", "E", "Y");
Edge FZ = graph.addEdge("FZ", "F", "Z");
Edge GT = graph.addEdge("GT", "G", "T");
A.setAttribute("xyz", new double[] { 0, 6, 0 });
B.setAttribute("xyz", new double[] { 0, 5, 0 });
C.setAttribute("xyz", new double[] { 0, 4, 0 });
D.setAttribute("xyz", new double[] { 0, 3, 0 });
E.setAttribute("xyz", new double[] { 0, 2, 0 });
F.setAttribute("xyz", new double[] { 0, 1, 0 });
G.setAttribute("xyz", new double[] { 0, 0, 0 });
U.setAttribute("xyz", new double[] { 3, 5, 0 });
V.setAttribute("xyz", new double[] { 3, 4, 0 });
W.setAttribute("xyz", new double[] { 3, 3, 0 });
X.setAttribute("xyz", new double[] { 3, 2, 0 });
Y.setAttribute("xyz", new double[] { 3, 1, 0 });
Z.setAttribute("xyz", new double[] { 3, 0, 0 });
T.setAttribute("xyz", new double[] { 3, -1, 0 });
graph.getNode("a").setAttribute("xyz", new double[] { 6, 5, 0 });
graph.getNode("b").setAttribute("xyz", new double[] { 6, 4, 0 });
graph.getNode("c").setAttribute("xyz", new double[] { 6, 3, 0 });
graph.getNode("d").setAttribute("xyz", new double[] { 6, 2, 0 });
graph.getNode("e").setAttribute("xyz", new double[] { 6, 1, 0 });
graph.getNode("f").setAttribute("xyz", new double[] { 6, 0, 0 });
graph.getNode("g").setAttribute("xyz", new double[] { 6, -1, 0 });
graph.getNode("u").setAttribute("xyz", new double[] { 9, 6, 0 });
graph.getNode("v").setAttribute("xyz", new double[] { 9, 5, 0 });
graph.getNode("w").setAttribute("xyz", new double[] { 9, 4, 0 });
graph.getNode("x").setAttribute("xyz", new double[] { 9, 3, 0 });
graph.getNode("y").setAttribute("xyz", new double[] { 9, 2, 0 });
graph.getNode("z").setAttribute("xyz", new double[] { 9, 1, 0 });
graph.getNode("t").setAttribute("xyz", new double[] { 9, 0, 0 });
graph.getNode("i").setAttribute("xyz", new double[] { 3, 7, 0 });
graph.getNode("j").setAttribute("xyz", new double[] { 6, 8, 0 });
A.setAttribute("label", "Center");
B.setAttribute("label", "AtLeft");
C.setAttribute("label", "AtRight");
D.setAttribute("label", "Left");
E.setAttribute("label", "Right");
F.setAttribute("label", "Under");
G.setAttribute("label", "Above");
U.setAttribute("label", "Center");
V.setAttribute("label", "AtLeft");
W.setAttribute("label", "AtRight");
X.setAttribute("label", "Left");
Y.setAttribute("label", "Right");
Z.setAttribute("label", "Under");
T.setAttribute("label", "Above");
au.setAttribute("label", "Center");
bv.setAttribute("label", "AtLeft");
cw.setAttribute("label", "AtRight");
dx.setAttribute("label", "Left");
ey.setAttribute("label", "Right");
fz.setAttribute("label", "Under");
gt.setAttribute("label", "Above");
ij.setAttribute("label", "Along");
graph.setAttribute("ui.screenshot", "text_align.png");
new Thread(new Runnable() {
@Override
public void run() {
while (loop) {
pipeIn.pump();
sleep(40);
}
System.out.println("bye bye");
System.exit(0);
}
}).start();
}
use of org.graphstream.ui.view.ViewerPipe in project gs-ui-javafx by graphstream.
the class MovingNodeSprite method run.
private void run() {
MultiGraph graph = new MultiGraph("TestSprites");
Viewer viewer = new FxViewer(graph, FxViewer.ThreadingModel.GRAPH_IN_ANOTHER_THREAD);
ViewerPipe pipeIn = viewer.newViewerPipe();
FxDefaultView view = (FxDefaultView) viewer.addView("view1", new FxGraphRenderer());
DefaultApplication.init(view, graph);
new Thread(() -> Application.launch(DefaultApplication.class)).start();
pipeIn.addAttributeSink(graph);
pipeIn.addViewerListener(this);
pipeIn.pump();
graph.setAttribute("ui.stylesheet", styleSheet);
graph.setAttribute("ui.antialias");
graph.setAttribute("ui.quality");
Node A = graph.addNode("A");
Node B = graph.addNode("B");
Node C = graph.addNode("C");
Node D = graph.addNode("D");
Node E = graph.addNode("E");
C.setAttribute("ui.points", new Point3(-0.05f, -0.05f, 0f), new Point3(0f, -0.02f, 0f), new Point3(0.05f, -0.05f, 0f), new Point3(0f, 0.05f, 0f));
graph.addEdge("AB1", "A", "B", true);
graph.addEdge("AB2", "B", "A", true);
graph.addEdge("BC", "B", "C");
graph.addEdge("CD", "C", "D", true);
graph.addEdge("DA", "D", "A");
graph.addEdge("DE", "D", "E", true);
graph.addEdge("EB", "E", "B", true);
graph.addEdge("BB", "B", "B", true);
graph.getEdge("CD").setAttribute("ui.points", new Point3(1, 0, 0), new Point3(0.6f, 0.1f, 0f), new Point3(0.3f, -0.1f, 0f), new Point3(0, 0, 0));
A.setAttribute("xyz", new double[] { 0, 1, 0 });
B.setAttribute("xyz", new double[] { 1.5, 1, 0 });
C.setAttribute("xyz", new double[] { 1, 0, 0 });
D.setAttribute("xyz", new double[] { 0, 0, 0 });
E.setAttribute("xyz", new double[] { 0.4, 0.6, 0 });
A.setAttribute("label", "A");
B.setAttribute("label", "B");
C.setAttribute("label", "C");
D.setAttribute("label", "D");
E.setAttribute("label", "E");
SpriteManager sman = new SpriteManager(graph);
MovingEdgeSprite s1 = sman.addSprite("S1", MovingEdgeSprite.class);
MovingEdgeSprite s2 = sman.addSprite("S2", MovingEdgeSprite.class);
MovingEdgeSprite s3 = sman.addSprite("S3", MovingEdgeSprite.class);
MovingEdgeSprite s4 = sman.addSprite("S4", MovingEdgeSprite.class);
DataSprite s5 = sman.addSprite("S5", DataSprite.class);
MovingEdgeSprite s6 = sman.addSprite("S6", MovingEdgeSprite.class);
MovingEdgeSprite s7 = sman.addSprite("S7", MovingEdgeSprite.class);
MovingEdgeSprite s8 = sman.addSprite("S8", MovingEdgeSprite.class);
s1.attachToEdge("AB1");
s2.attachToEdge("CD");
s3.attachToEdge("DA");
s4.attachToEdge("EB");
s5.attachToNode("A");
s6.attachToNode("D");
s7.attachToEdge("AB2");
s8.attachToEdge("EB");
s2.setOffsetPx(20);
s3.setOffsetPx(15);
s4.setOffsetPx(4);
s5.setPosition(Units.PX, 0, 30, 0);
s5.setData(new float[] { 0.3f, 0.5f, 0.2f });
// s6.setOffsetPx(20);
s8.setPosition(0.5f, 0.5f, 0f);
s1.setAttribute("ui.label", "FooBar1");
s2.setAttribute("ui.label", "FooBar2");
s4.setAttribute("ui.label", "FooBar4");
s7.setAttribute("ui.label", "FooBar7");
s8.setAttribute("ui.points", new Point3(-0.02f, -0.02f, 0f), new Point3(0f, -0.01f, 0f), new Point3(0.02f, -0.02f, 0f), new Point3(0f, 0.02f, 0f));
E.setAttribute("ui.pie-values", 0.2f, 0.3f, 0.4f, 0.1f);
while (loop) {
pipeIn.pump();
s1.move();
s2.move();
s3.move();
s4.move();
s6.move();
s7.move();
s8.move();
sleep(4);
}
System.out.println("bye bye");
System.exit(0);
}
use of org.graphstream.ui.view.ViewerPipe in project gs-ui-javafx by graphstream.
the class TestStars2 method start.
public void start(Stage primaryStage) throws Exception {
SingleGraph graph = new SingleGraph("Stars !");
double x0 = 0.0;
double x1 = 0.0;
double width = 100.0;
double height = 20.0;
int n = 500;
Random random = new Random();
double minDis = 4.0;
double sizeMx = 10.0;
graph.setAttribute("ui.stylesheet", styleSheet);
graph.setAttribute("ui.quality");
graph.setAttribute("ui.antialias");
Viewer viewer = new FxViewer(graph, FxViewer.ThreadingModel.GRAPH_IN_ANOTHER_THREAD);
ViewerPipe pipeIn = viewer.newViewerPipe();
FxDefaultView view = (FxDefaultView) viewer.addView("view1", new FxGraphRenderer());
view.resize(1000, (int) (1200 * (height / width)));
Scene scene = new Scene(view, 1000, 1200 * (height / width), true, SceneAntialiasing.BALANCED);
primaryStage.setScene(scene);
primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>() {
@Override
public void handle(WindowEvent t) {
Platform.exit();
System.exit(0);
}
});
primaryStage.setTitle("Stars 2");
primaryStage.show();
for (int i = 0; i < n; i++) {
Node node = graph.addNode(i + "");
node.setAttribute("xyz", (random.nextDouble() * width), (random.nextDouble() * height), 0);
node.setAttribute("ui.size", (random.nextDouble() * sizeMx));
}
graph.nodes().forEach(node -> {
Point3 pos = new Point3(GraphPosLengthUtils.nodePosition(node));
graph.nodes().forEach(otherNode -> {
if (otherNode != node) {
Point3 otherPos = new Point3(GraphPosLengthUtils.nodePosition(otherNode));
double dist = otherPos.distance(pos);
if (dist < minDis) {
if (!node.hasEdgeBetween(otherNode.getId())) {
try {
graph.addEdge(node.getId() + "--" + otherNode.getId(), node.getId(), otherNode.getId());
} catch (IdAlreadyInUseException e) {
graph.addEdge(node.getId() + "--" + otherNode.getId() + "-2", node.getId(), otherNode.getId());
}
}
}
}
});
});
}
Aggregations