Search in sources :

Example 1 with Sprite

use of org.graphstream.ui.spriteManager.Sprite in project gs-ui-javafx by graphstream.

the class TestPies method run.

private void run() {
    System.setProperty("org.graphstream.ui", "org.graphstream.ui.javafx.util.Display");
    SingleGraph g = new SingleGraph("test");
    Node A = g.addNode("A");
    Node B = g.addNode("B");
    g.addEdge("AB", "A", "B");
    SpriteManager sm = new SpriteManager(g);
    Sprite pie = sm.addSprite("pie");
    g.setAttribute("ui.antialias");
    pie.setAttribute("ui.style", "shape: pie-chart; fill-color: #F00, #0F0, #00F; size: 30px;");
    // g.addAttribute("ui.stylesheet", "sprite { shape: pie-chart; fill-color: #F00, #0F0, #00F; size: 30px; } node {fill-color: red; }")
    double[] values = new double[3];
    values[0] = 0.3333;
    values[1] = 0.3333;
    values[2] = 0.3333;
    pie.setAttribute("ui.pie-values", values);
    pie.attachToEdge("AB");
    pie.setPosition(0.5);
    g.display();
    double[] values2 = new double[3];
    values2[0] = 0.1;
    values2[1] = 0.3;
    values2[2] = 0.6;
    boolean on = true;
    while (true) {
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        if (on) {
            values[0] = 0.1;
            values[1] = 0.3;
            values[2] = 0.6;
            A.setAttribute("ui.pie-values", new double[] { 1.0 });
            A.setAttribute("ui.style", "shape:pie-chart; fill-color:red;");
        } else {
            values[0] = 0.3;
            values[1] = 0.3;
            values[2] = 0.3;
            A.setAttribute("ui.pie-values", new double[] { 1.0 });
            A.setAttribute("ui.style", "shape:pie-chart; fill-color:blue;");
        }
        pie.setAttribute("ui.pie-values", values);
        // pie.addAttribute("ui.pie-values", if(on) values else values2)
        on = !on;
    }
}
Also used : Sprite(org.graphstream.ui.spriteManager.Sprite) Node(org.graphstream.graph.Node) SingleGraph(org.graphstream.graph.implementations.SingleGraph) SpriteManager(org.graphstream.ui.spriteManager.SpriteManager)

Example 2 with Sprite

use of org.graphstream.ui.spriteManager.Sprite 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)

Aggregations

Node (org.graphstream.graph.Node)2 Sprite (org.graphstream.ui.spriteManager.Sprite)2 SpriteManager (org.graphstream.ui.spriteManager.SpriteManager)2 Edge (org.graphstream.graph.Edge)1 MultiGraph (org.graphstream.graph.implementations.MultiGraph)1 SingleGraph (org.graphstream.graph.implementations.SingleGraph)1 FxDefaultView (org.graphstream.ui.fx_viewer.FxDefaultView)1 FxViewer (org.graphstream.ui.fx_viewer.FxViewer)1 FxGraphRenderer (org.graphstream.ui.javafx.FxGraphRenderer)1 Viewer (org.graphstream.ui.view.Viewer)1 ViewerPipe (org.graphstream.ui.view.ViewerPipe)1