Package org.gephi.graph.api

Examples of org.gephi.graph.api.Graph


    private boolean cancel = false;
    private ProgressTicket progressTicket;

    public boolean execute() {
        GraphModel graphModel = workspace.getLookup().lookup(GraphModel.class);
        Graph graph = null;
        if (exportVisible) {
            graph = graphModel.getGraphVisible();
        } else {
            graph = graphModel.getGraph();
        }
View Full Code Here


    System.out.println();
    System.out.println();
  }

  private Graph makeGraph2() {
    Graph graph = graphModel.newView().getGraphModel().getGraph();
    graph.clearEdges();
    return graph;
  }
View Full Code Here

        executing = true;
    }

    @Override
    public void goAlgo() {
        Graph graph = graphModel.getGraphVisible();
        graph.readLock();
        int nodeCount = graph.getNodeCount();
        Node[] nodes = graph.getNodes().toArray();

        if (column != null) {
            Arrays.sort(nodes, new Comparator<Node>() {

                @Override
                public int compare(Node o1, Node o2) {
                    Number n1 = (Number) o1.getAttributes().getValue(column.getIndex());
                    Number n2 = (Number) o2.getAttributes().getValue(column.getIndex());
                    if (n1.doubleValue() < n2.doubleValue()) {
                        return 1;
                    } else if (n1.doubleValue() > n2.doubleValue()) {
                        return -1;
                    } else {
                        return 0;
                    }
                }
            });
        }

        int rows = (int) Math.round(Math.sqrt(nodeCount)) + 1;
        int cols = (int) Math.round(Math.sqrt(nodeCount)) + 1;
        for (int i = 0; i < rows; i++) {
            for (int j = 0; j < cols && (i * rows + j) < nodes.length; j++) {
                Node node = nodes[i * rows + j];
                float x = (-areaSize / 2f) + ((float) j / cols) * areaSize;
                float y = (areaSize / 2f) - ((float) i / rows) * areaSize;
                float px = node.getNodeData().x();
                float py = node.getNodeData().y();
                node.getNodeData().setX(px + (x - px) * (speed / 10000f));
                node.getNodeData().setY(py + (y - py) * (speed / 10000f));
            }
        }

        graph.readUnlock();
    }
View Full Code Here

        executing = true;
    }

    @Override
    public void goAlgo() {
        Graph graph = graphModel.getGraphVisible();
        graph.readLock();
        int nodeCount = graph.getNodeCount();
        Node[] nodes = graph.getNodes().toArray();

        int rows = (int) Math.round(Math.sqrt(nodeCount)) + 1;
        int cols = (int) Math.round(Math.sqrt(nodeCount)) + 1;
        for (int i = 0; i < rows; i++) {
            for (int j = 0; j < cols && (i * rows + j) < nodes.length; j++) {
                Node node = nodes[i * rows + j];
                float x = (-areaSize / 2f) + ((float) j / cols) * areaSize;
                float y = (areaSize / 2f) - ((float) i / rows) * areaSize;
                float px = node.getNodeData().x();
                float py = node.getNodeData().y();
                node.getNodeData().setX(px + (x - px) * (speed / 10000f));
                node.getNodeData().setY(py + (y - py) * (speed / 10000f));
            }
        }

        graph.readUnlock();
    }
View Full Code Here

    public void execute() {
        //Note that a function to inverse selection directly in the table with DataTablesController
        //would be more efficient than calculating it here, but this example demonstrates some table selection features.
       
        DataTablesController dtc = Lookup.getDefault().lookup(DataTablesController.class);
        Graph graph = Lookup.getDefault().lookup(GraphController.class).getModel().getGraph();
        if (dtc.isNodeTableMode()) {
            //Get currently selected nodes and calculate inverse set.
            Node[] selected = dtc.getNodeTableSelection();

            ArrayList<Node> nodes = new ArrayList<Node>();
            nodes.addAll(Arrays.asList(graph.getNodes().toArray()));
            for (Node node : selected) {
                nodes.remove(node);
            }

            dtc.setNodeTableSelection(nodes.toArray(new Node[0]));
        } else if (dtc.isEdgeTableMode()) {
            //Get currently selected edges and calculate inverse set.
            Edge[] selected = dtc.getEdgeTableSelection();

            ArrayList<Edge> edges = new ArrayList<Edge>();
            edges.addAll(Arrays.asList(graph.getEdges().toArray()));
            for (Edge edge : selected) {
                edges.remove(edge);
            }
           
            dtc.setEdgeTableSelection(edges.toArray(new Edge[0]));
View Full Code Here

   
    @Override
    public void select() {
        //Get current visible graph
        GraphController graphController = Lookup.getDefault().lookup(GraphController.class);
        Graph graph = graphController.getModel().getGraphVisible();
       
        //Build the autocomplete data. A simple map from node's label
        graph.readLock();
        data = new HashMap<String, Node>();
        for (Node n : graph.getNodes()) {
            String label = n.getNodeData().getLabel();
            String id = n.getNodeData().getId();
            if (label != null) {
                if (!label.isEmpty()) {
                    data.put(label, n);
                }
            } else if (id != null && !id.isEmpty()) {
                data.put(id, n);
            }
           
        }
        graph.readUnlock();
    }
View Full Code Here

                        @Override
                        public void mouseClick(int[] positionViewport, float[] position3d) {
                            //Get current graph
                            GraphController gc = Lookup.getDefault().lookup(GraphController.class);
                            Graph graph = gc.getModel().getGraph();
                            GraphFactory factory = gc.getModel().factory();

                            //Add node
                            Node node = factory.newNode();
                            node.getNodeData().setX(position3d[0]);
                            node.getNodeData().setY(position3d[1]);
                            node.getNodeData().setSize(10f);
                            graph.addNode(node);
                        }
                    },
                    new NodeClickEventListener() {

                        @Override
                        public void clickNodes(Node[] nodes) {
                            //Get mouse position
                            float[] position3d = VizController.getInstance().getGraphIO().getMousePosition3d();

                            //Get current graph
                            GraphController gc = Lookup.getDefault().lookup(GraphController.class);
                            Graph graph = gc.getModel().getGraph();
                            GraphFactory factory = gc.getModel().factory();

                            //Add node
                            Node node = factory.newNode();
                            node.getNodeData().setX(position3d[0]);
                            node.getNodeData().setY(position3d[1]);
                            node.getNodeData().setSize(10f);
                            graph.addNode(node);

                            //Add edges with the clicked nodes
                            for (Node n : nodes) {
                                Edge edge = factory.newEdge(node, n);
                                graph.addEdge(edge);
                            }
                        }
                    }};
    }
View Full Code Here

                statement.executeUpdate("create table edges (source string, target string, weight real)");

                //Get the current graph in the defined workspace
                GraphController graphController = Lookup.getDefault().lookup(GraphController.class);
                GraphModel graphModel = graphController.getModel(workspace);
                Graph graph = graphModel.getGraphVisible();

                //Count the number of tasks (nodes + edges) and start the progress
                int tasks = graph.getNodeCount() + graph.getEdgeCount();
                Progress.start(progress, tasks);

                //Export nodes. Progress is incremented at each step.
                for (Node n : graph.getNodes().toArray()) {
                    String id = n.getNodeData().getId();
                    String label = n.getNodeData().getLabel();
                    statement.executeUpdate("insert into nodes values('" + id + "', '" + label + "')");
                    if (cancel) {
                        return false;
                    }
                    Progress.progress(progress);
                }

                //Export edges. Progress is incremented at each step.
                for (Edge e : graph.getEdges().toArray()) {
                    String sourceId = e.getSource().getNodeData().getId();
                    String targetId = e.getTarget().getNodeData().getId();
                    String weight = String.valueOf(e.getWeight());
                    statement.executeUpdate("insert into edges values('" + sourceId + "', '" + targetId + "', '" + weight + "')");
                    if (cancel) {
View Full Code Here

    private int totalEdgeCount;
    private int selfLoopCount;

    @Override
    public void execute(GraphModel graphModel, AttributeModel attributeModel) {
        Graph graph = graphModel.getGraphVisible();
        execute(graph, attributeModel);
    }
View Full Code Here

        GraphModel graphModel = gc.getModel();
       
        if (graphModel != null) {
            //Remove self loops
            int removed = 0;
            Graph graph = graphModel.getGraph();
            graph.writeLock();
            for(Edge edge : graph.getEdges().toArray()) {
                if(edge.isSelfLoop()) {
                    graph.removeEdge(edge);
                    removed++;
                }
            }
            graph.writeUnlock();
           
            //Notification message
            NotifyDescriptor d = new NotifyDescriptor.Message(removed + " self-loop have been removed", NotifyDescriptor.INFORMATION_MESSAGE);
            DialogDisplayer.getDefault().notify(d);
        } else {
View Full Code Here

TOP

Related Classes of org.gephi.graph.api.Graph

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.