Search in sources :

Example 16 with Node

use of org.graphstream.graph.Node 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);
}
Also used : FxViewer(org.graphstream.ui.fx_viewer.FxViewer) Point3(org.graphstream.ui.geom.Point3) FxGraphRenderer(org.graphstream.ui.javafx.FxGraphRenderer) Node(org.graphstream.graph.Node) FxViewer(org.graphstream.ui.fx_viewer.FxViewer) Viewer(org.graphstream.ui.view.Viewer) FxDefaultView(org.graphstream.ui.fx_viewer.FxDefaultView) SpriteManager(org.graphstream.ui.spriteManager.SpriteManager) MultiGraph(org.graphstream.graph.implementations.MultiGraph) ViewerPipe(org.graphstream.ui.view.ViewerPipe)

Example 17 with Node

use of org.graphstream.graph.Node in project gs-ui-javafx by graphstream.

the class TestStars 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");
    graph.addEdge("AB", "A", "B");
    graph.addEdge("BC", "B", "C");
    graph.addEdge("CD", "C", "D");
    graph.addEdge("DA", "D", "A");
    graph.addEdge("DE", "D", "E");
    graph.addEdge("EB", "E", "B");
    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 });
    SpriteManager sman = new SpriteManager(graph);
    sman.setSpriteFactory(new MySpriteFactory());
    MySprite s1 = (MySprite) sman.addSprite("S1");
    MySprite s2 = (MySprite) sman.addSprite("S2");
    MySprite s3 = (MySprite) sman.addSprite("S3");
    s1.attachToEdge("AB");
    s2.attachToEdge("CD");
    s3.attachToEdge("DA");
    while (loop) {
        pipeIn.pump();
        s1.move();
        s2.move();
        s3.move();
        sleep(10);
    }
    System.out.println("bye bye");
    System.exit(0);
}
Also used : FxViewer(org.graphstream.ui.fx_viewer.FxViewer) FxGraphRenderer(org.graphstream.ui.javafx.FxGraphRenderer) Node(org.graphstream.graph.Node) FxViewer(org.graphstream.ui.fx_viewer.FxViewer) Viewer(org.graphstream.ui.view.Viewer) FxDefaultView(org.graphstream.ui.fx_viewer.FxDefaultView) SpriteManager(org.graphstream.ui.spriteManager.SpriteManager) MultiGraph(org.graphstream.graph.implementations.MultiGraph) ViewerPipe(org.graphstream.ui.view.ViewerPipe)

Example 18 with Node

use of org.graphstream.graph.Node 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());
                        }
                    }
                }
            }
        });
    });
}
Also used : FxGraphRenderer(org.graphstream.ui.javafx.FxGraphRenderer) Node(org.graphstream.graph.Node) FxViewer(org.graphstream.ui.fx_viewer.FxViewer) Viewer(org.graphstream.ui.view.Viewer) FxDefaultView(org.graphstream.ui.fx_viewer.FxDefaultView) Scene(javafx.scene.Scene) FxViewer(org.graphstream.ui.fx_viewer.FxViewer) Point3(org.graphstream.ui.geom.Point3) IdAlreadyInUseException(org.graphstream.graph.IdAlreadyInUseException) Random(java.util.Random) WindowEvent(javafx.stage.WindowEvent) SingleGraph(org.graphstream.graph.implementations.SingleGraph) ViewerPipe(org.graphstream.ui.view.ViewerPipe)

Example 19 with Node

use of org.graphstream.graph.Node in project gs-ui-javafx by graphstream.

the class TutorialDiagrams method diagram3.

public Scene diagram3(String title, String styleSheet) {
    MultiGraph graph = new MultiGraph(title);
    Scene s = diagram(graph, styleSheet, title, 800, 500);
    Node G = graph.addNode("Graph");
    Node V = graph.addNode("Viewer");
    Node P1 = graph.addNode("GtoV");
    Node P2 = graph.addNode("VtoG");
    graph.addEdge("G->GtoV", "Graph", "GtoV", true);
    graph.addEdge("GtoV->V", "GtoV", "Viewer", true);
    graph.addEdge("VtoG<-V", "Viewer", "VtoG", true);
    graph.addEdge("G<-VtoG", "VtoG", "Graph", true);
    G.setAttribute("ui.label", "Graph");
    P1.setAttribute("ui.label", "Pipe");
    P2.setAttribute("ui.label", "ViewerPipe");
    V.setAttribute("ui.label", "Viewer");
    G.setAttribute("xyz", new double[] { -2, 0, 0 });
    P1.setAttribute("xyz", new double[] { -1, 1.4, 0 });
    P2.setAttribute("xyz", new double[] { 1, -1.4, 0 });
    V.setAttribute("xyz", new double[] { 2, 0, 0 });
    return s;
}
Also used : Node(org.graphstream.graph.Node) Scene(javafx.scene.Scene) MultiGraph(org.graphstream.graph.implementations.MultiGraph)

Example 20 with Node

use of org.graphstream.graph.Node in project gs-ui-javafx by graphstream.

the class TutorialDiagrams method diagram2.

public Scene diagram2(String title, String styleSheet) {
    MultiGraph graph = new MultiGraph(title);
    Scene s = diagram(graph, styleSheet, title, 500, 250);
    Node G = graph.addNode("Graph");
    Node P = graph.addNode("Pipe");
    Node V = graph.addNode("Viewer");
    graph.addEdge("G->P", "Graph", "Pipe", true);
    graph.addEdge("P->V", "Pipe", "Viewer", true);
    G.setAttribute("xyz", new double[] { 0, 0, 0 });
    P.setAttribute("xyz", new double[] { 1, 0, 0 });
    V.setAttribute("xyz", new double[] { 2, 0, 0 });
    G.setAttribute("ui.label", "Graph");
    P.setAttribute("ui.label", "Pipe");
    V.setAttribute("ui.label", "Viewer");
    return s;
}
Also used : Node(org.graphstream.graph.Node) Scene(javafx.scene.Scene) MultiGraph(org.graphstream.graph.implementations.MultiGraph)

Aggregations

Node (org.graphstream.graph.Node)28 MultiGraph (org.graphstream.graph.implementations.MultiGraph)12 Edge (org.graphstream.graph.Edge)10 FxViewer (org.graphstream.ui.fx_viewer.FxViewer)9 ViewerPipe (org.graphstream.ui.view.ViewerPipe)9 FxDefaultView (org.graphstream.ui.fx_viewer.FxDefaultView)8 FxGraphRenderer (org.graphstream.ui.javafx.FxGraphRenderer)8 Scene (javafx.scene.Scene)6 Viewer (org.graphstream.ui.view.Viewer)6 SpriteManager (org.graphstream.ui.spriteManager.SpriteManager)4 SingleGraph (org.graphstream.graph.implementations.SingleGraph)3 WindowEvent (javafx.stage.WindowEvent)2 FilterComplex (org.fagu.fmv.ffmpeg.filter.FilterComplex)2 Point3 (org.graphstream.ui.geom.Point3)2 Sprite (org.graphstream.ui.spriteManager.Sprite)2 FileOutputStream (java.io.FileOutputStream)1 PrintWriter (java.io.PrintWriter)1 HashMap (java.util.HashMap)1 Random (java.util.Random)1 In (org.fagu.fmv.ffmpeg.filter.FilterComplexBase.In)1