Search in sources :

Example 1 with SingleGraph

use of org.graphstream.graph.implementations.SingleGraph 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 SingleGraph

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

the class TestPolys method run.

private void run() {
    System.setProperty("org.graphstream.ui", "org.graphstream.ui.javafx.util.Display");
    SingleGraph g = new SingleGraph("Polys");
    Node A = g.addNode("A");
    Node B = g.addNode("B");
    Node C = g.addNode("C");
    Node D = g.addNode("D");
    A.setAttribute("xyz", new double[] { 1, 1, 0 });
    B.setAttribute("xyz", new double[] { 1, -1, 0 });
    C.setAttribute("xyz", new double[] { -1, -1, 0 });
    D.setAttribute("xyz", new double[] { -1, 1, 0 });
    A.setAttribute("ui.label", "A");
    B.setAttribute("ui.label", "B");
    C.setAttribute("ui.label", "C");
    D.setAttribute("ui.label", "D");
    Edge AB = g.addEdge("AB", "A", "B");
    Edge BC = g.addEdge("BC", "B", "C");
    Edge CD = g.addEdge("CD", "C", "D");
    Edge DA = g.addEdge("DA", "D", "A");
    AB.setAttribute("ui.points", new double[] { 1, 1, 0, 1.25, 0.5, 0, 0.75, -0.5, 0, 1, -1, 0 });
    BC.setAttribute("ui.points", new double[] { 1, -1, 0, 0.5, -0.5, 0, -0.5, -0.25, 0, -1, -1, 0 });
    CD.setAttribute("ui.points", new double[] { -1, -1, 0, -0.40, -0.5, 0, -1.70, 0.5, 0, -1, 1, 0 });
    // DA.setAttribute("ui.points", new double[]{-1, 1, 0,
    // -0.5, 0.75, 0,
    // 0.5, 0.25, 0,
    // 1, 1, 0});
    g.setAttribute("ui.stylesheet", styleSheet);
    g.setAttribute("ui.antialias");
    g.display(false);
}
Also used : Node(org.graphstream.graph.Node) SingleGraph(org.graphstream.graph.implementations.SingleGraph) Edge(org.graphstream.graph.Edge)

Example 3 with SingleGraph

use of org.graphstream.graph.implementations.SingleGraph 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)

Aggregations

Node (org.graphstream.graph.Node)3 SingleGraph (org.graphstream.graph.implementations.SingleGraph)3 Random (java.util.Random)1 Scene (javafx.scene.Scene)1 WindowEvent (javafx.stage.WindowEvent)1 Edge (org.graphstream.graph.Edge)1 IdAlreadyInUseException (org.graphstream.graph.IdAlreadyInUseException)1 FxDefaultView (org.graphstream.ui.fx_viewer.FxDefaultView)1 FxViewer (org.graphstream.ui.fx_viewer.FxViewer)1 Point3 (org.graphstream.ui.geom.Point3)1 FxGraphRenderer (org.graphstream.ui.javafx.FxGraphRenderer)1 Sprite (org.graphstream.ui.spriteManager.Sprite)1 SpriteManager (org.graphstream.ui.spriteManager.SpriteManager)1 Viewer (org.graphstream.ui.view.Viewer)1 ViewerPipe (org.graphstream.ui.view.ViewerPipe)1