Search in sources :

Example 11 with MultiGraph

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

the class TestIcons method run.

private void run(String[] args) {
    iconAnim.add(ImageCache.class.getClassLoader().getResource("org/graphstream/ui/viewer_fx/test/data/icon_1.png").toString());
    iconAnim.add(ImageCache.class.getClassLoader().getResource("org/graphstream/ui/viewer_fx/test/data/icon_2.png").toString());
    iconAnim.add(ImageCache.class.getClassLoader().getResource("org/graphstream/ui/viewer_fx/test/data/icon_3.png").toString());
    iconAnim.add(ImageCache.class.getClassLoader().getResource("org/graphstream/ui/viewer_fx/test/data/icon_4.png").toString());
    iconAnim.add(ImageCache.class.getClassLoader().getResource("org/graphstream/ui/viewer_fx/test/data/icon_5.png").toString());
    iconAnim.add(ImageCache.class.getClassLoader().getResource("org/graphstream/ui/viewer_fx/test/data/icon_6.png").toString());
    iconAnim.add(ImageCache.class.getClassLoader().getResource("org/graphstream/ui/viewer_fx/test/data/icon_7.png").toString());
    iconAnim.add(ImageCache.class.getClassLoader().getResource("org/graphstream/ui/viewer_fx/test/data/icon_8.png").toString());
    iconAnim.add(ImageCache.class.getClassLoader().getResource("org/graphstream/ui/viewer_fx/test/data/icon_9.png").toString());
    MultiGraph graph = new MultiGraph("Icons ...");
    FxViewer 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");
    graph.addEdge("AB", "A", "B");
    graph.addEdge("BC", "B", "C");
    graph.addEdge("CD", "C", "D");
    graph.addEdge("DA", "D", "A");
    A.setAttribute("xyz", new double[] { 0.0, 1.0, 0 });
    B.setAttribute("xyz", new double[] { 3.2, 1.5, 0 });
    C.setAttribute("xyz", new double[] { 0.2, 0.0, 0 });
    D.setAttribute("xyz", new double[] { 3.0, -0.5, 0 });
    A.setAttribute("label", "Topic1");
    B.setAttribute("label", "Topic2");
    C.setAttribute("label", "Topic3");
    D.setAttribute("label", "Topic4");
    A.setAttribute("ui.icon", iconAnim.get(0));
    int i = 0;
    while (loop) {
        pipeIn.pump();
        sleep(60);
        if (i >= 9)
            i = 0;
        else if (i < 0)
            i = 8;
        A.setAttribute("ui.icon", iconAnim.get(i));
        if (direction)
            i++;
        else
            i--;
    }
    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) ImageCache(org.graphstream.ui.javafx.util.ImageCache) FxDefaultView(org.graphstream.ui.fx_viewer.FxDefaultView) MultiGraph(org.graphstream.graph.implementations.MultiGraph) ViewerPipe(org.graphstream.ui.view.ViewerPipe)

Example 12 with MultiGraph

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

the class TestRandomWalk method run.

private void run() {
    MultiGraph graph = new MultiGraph("random walk");
    DorogovtsevMendesGenerator gen = new DorogovtsevMendesGenerator();
    RandomWalk rwalk = new RandomWalk();
    gen.addSink(graph);
    gen.begin();
    for (int i = 0; i < 400; i++) {
        gen.nextEvents();
    }
    gen.end();
    graph.setAttribute("ui.stylesheet", styleSheet);
    graph.setAttribute("ui.quality");
    graph.setAttribute("ui.antialias");
    graph.display();
    rwalk.setEntityCount(graph.getNodeCount() * 2);
    rwalk.setEvaporation(0.97);
    rwalk.setEntityMemory(40);
    rwalk.init(graph);
    for (int i = 0; i < 3000; i++) {
        rwalk.compute();
        if (i % 100 == 0) {
            System.err.println("step " + i);
            updateGraph(graph, rwalk);
        }
    // Thread.sleep(100)
    }
    rwalk.terminate();
    updateGraph(graph, rwalk);
    graph.setAttribute("ui.screenshot", "randomWalk.png");
}
Also used : DorogovtsevMendesGenerator(org.graphstream.algorithm.generator.DorogovtsevMendesGenerator) RandomWalk(org.graphstream.algorithm.randomWalk.RandomWalk) MultiGraph(org.graphstream.graph.implementations.MultiGraph)

Example 13 with MultiGraph

use of org.graphstream.graph.implementations.MultiGraph 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);
}
Also used : FxViewer(org.graphstream.ui.fx_viewer.FxViewer) Sprite(org.graphstream.ui.spriteManager.Sprite) 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) Edge(org.graphstream.graph.Edge) SpriteManager(org.graphstream.ui.spriteManager.SpriteManager) MultiGraph(org.graphstream.graph.implementations.MultiGraph) ViewerPipe(org.graphstream.ui.view.ViewerPipe)

Example 14 with MultiGraph

use of org.graphstream.graph.implementations.MultiGraph 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);
}
Also used : Viewer(org.graphstream.ui.view.Viewer) DorogovtsevMendesGenerator(org.graphstream.algorithm.generator.DorogovtsevMendesGenerator) MultiGraph(org.graphstream.graph.implementations.MultiGraph) ViewerPipe(org.graphstream.ui.view.ViewerPipe)

Example 15 with MultiGraph

use of org.graphstream.graph.implementations.MultiGraph 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();
}
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) MultiGraph(org.graphstream.graph.implementations.MultiGraph) FxViewer(org.graphstream.ui.fx_viewer.FxViewer) WindowEvent(javafx.stage.WindowEvent) Edge(org.graphstream.graph.Edge) ViewerPipe(org.graphstream.ui.view.ViewerPipe)

Aggregations

MultiGraph (org.graphstream.graph.implementations.MultiGraph)21 Node (org.graphstream.graph.Node)12 FxViewer (org.graphstream.ui.fx_viewer.FxViewer)12 ViewerPipe (org.graphstream.ui.view.ViewerPipe)10 Scene (javafx.scene.Scene)9 FxGraphRenderer (org.graphstream.ui.javafx.FxGraphRenderer)9 FxDefaultView (org.graphstream.ui.fx_viewer.FxDefaultView)8 Viewer (org.graphstream.ui.view.Viewer)8 DorogovtsevMendesGenerator (org.graphstream.algorithm.generator.DorogovtsevMendesGenerator)5 Edge (org.graphstream.graph.Edge)4 Graph (org.graphstream.graph.Graph)4 WindowEvent (javafx.stage.WindowEvent)3 FxViewPanel (org.graphstream.ui.fx_viewer.FxViewPanel)3 SpriteManager (org.graphstream.ui.spriteManager.SpriteManager)3 ThreadProxyPipe (org.graphstream.stream.thread.ThreadProxyPipe)2 IOException (java.io.IOException)1 GridPane (javafx.scene.layout.GridPane)1 StackPane (javafx.scene.layout.StackPane)1 Stage (javafx.stage.Stage)1 RandomWalk (org.graphstream.algorithm.randomWalk.RandomWalk)1