Search in sources :

Example 91 with Graph

use of org.gephi.graph.api.Graph in project gephi-plugins-bootcamp by gephi.

the class GridLayout method goAlgo.

@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.x();
            float py = node.y();
            node.setX(px + (x - px) * (speed / 10000f));
            node.setY(py + (y - py) * (speed / 10000f));
        }
    }
    graph.readUnlock();
}
Also used : Graph(org.gephi.graph.api.Graph) Node(org.gephi.graph.api.Node)

Example 92 with Graph

use of org.gephi.graph.api.Graph in project gephi by gephi.

the class DefaultProcessor method process.

protected void process(ContainerUnloader container, Workspace workspace) {
    //Architecture
    GraphController graphController = Lookup.getDefault().lookup(GraphController.class);
    graphModel = graphController.getGraphModel(workspace);
    //Get graph
    Graph graph = graphModel.getGraph();
    GraphFactory factory = graphModel.factory();
    //Time Format & Time zone
    graphModel.setTimeFormat(container.getTimeFormat());
    graphModel.setTimeZone(container.getTimeZone());
    //Progress
    Progress.start(progressTicket, container.getNodeCount() + container.getEdgeCount());
    //Attributes - Creates columns for properties
    flushColumns(container);
    //Counters
    int addedNodes = 0, addedEdges = 0;
    //Create all nodes
    ElementIdType elementIdType = container.getElementIdType();
    for (NodeDraft draftNode : container.getNodes()) {
        String idString = draftNode.getId();
        Object id = toElementId(elementIdType, idString);
        Node node = graph.getNode(id);
        boolean newNode = false;
        if (node == null) {
            node = factory.newNode(id);
            addedNodes++;
            newNode = true;
        }
        flushToNode(draftNode, node);
        if (newNode) {
            graph.addNode(node);
        }
        Progress.progress(progressTicket);
    }
    //Create all edges and push to data structure
    for (EdgeDraft draftEdge : container.getEdges()) {
        String idString = draftEdge.getId();
        Object id = toElementId(elementIdType, idString);
        String sourceId = draftEdge.getSource().getId();
        String targetId = draftEdge.getTarget().getId();
        Node source = graph.getNode(toElementId(elementIdType, sourceId));
        Node target = graph.getNode(toElementId(elementIdType, targetId));
        Object type = draftEdge.getType();
        int edgeType = graphModel.addEdgeType(type);
        Edge edge = graph.getEdge(source, target, edgeType);
        boolean newEdge = false;
        if (edge == null) {
            switch(container.getEdgeDefault()) {
                case DIRECTED:
                    edge = factory.newEdge(id, source, target, edgeType, draftEdge.getWeight(), true);
                    break;
                case UNDIRECTED:
                    edge = factory.newEdge(id, source, target, edgeType, draftEdge.getWeight(), false);
                    break;
                case MIXED:
                    boolean directed = draftEdge.getDirection() == null || !draftEdge.getDirection().equals(EdgeDirection.UNDIRECTED);
                    edge = factory.newEdge(id, source, target, edgeType, draftEdge.getWeight(), directed);
                    break;
            }
            addedEdges++;
            newEdge = true;
        }
        flushToEdge(draftEdge, edge);
        if (newEdge) {
            graph.addEdge(edge);
        }
        Progress.progress(progressTicket);
    }
    //Report
    int touchedNodes = container.getNodeCount();
    int touchedEdges = container.getEdgeCount();
    if (touchedNodes != addedNodes || touchedEdges != addedEdges) {
        Logger.getLogger(getClass().getSimpleName()).log(Level.INFO, "# Nodes loaded: {0} ({1} added)", new Object[] { touchedNodes, addedNodes });
        Logger.getLogger(getClass().getSimpleName()).log(Level.INFO, "# Edges loaded: {0} ({1} added)", new Object[] { touchedEdges, addedEdges });
    } else {
        Logger.getLogger(getClass().getSimpleName()).log(Level.INFO, "# Nodes loaded: {0}", new Object[] { touchedNodes });
        Logger.getLogger(getClass().getSimpleName()).log(Level.INFO, "# Edges loaded: {0}", new Object[] { touchedEdges });
    }
    Progress.finish(progressTicket);
}
Also used : ElementIdType(org.gephi.io.importer.api.ElementIdType) GraphFactory(org.gephi.graph.api.GraphFactory) EdgeDraft(org.gephi.io.importer.api.EdgeDraft) Graph(org.gephi.graph.api.Graph) NodeDraft(org.gephi.io.importer.api.NodeDraft) Node(org.gephi.graph.api.Node) Edge(org.gephi.graph.api.Edge) GraphController(org.gephi.graph.api.GraphController)

Example 93 with Graph

use of org.gephi.graph.api.Graph in project gephi-plugins-bootcamp by gephi.

the class CountSelfLoop method execute.

@Override
public void execute(GraphModel graphModel) {
    Graph graph = graphModel.getGraphVisible();
    selfLoopCount = 0;
    totalEdgeCount = graph.getEdgeCount();
    for (Edge e : graph.getEdges()) {
        if (e.isSelfLoop()) {
            selfLoopCount++;
        }
    }
}
Also used : Graph(org.gephi.graph.api.Graph) Edge(org.gephi.graph.api.Edge)

Example 94 with Graph

use of org.gephi.graph.api.Graph in project gephi-plugins-bootcamp by gephi.

the class FindTool method select.

@Override
public void select() {
    //Get current visible graph
    GraphController graphController = Lookup.getDefault().lookup(GraphController.class);
    Graph graph = graphController.getGraphModel().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.getLabel();
        String id = n.getId().toString();
        if (label != null) {
            if (!label.isEmpty()) {
                data.put(label, n);
            }
        } else if (id != null && !id.isEmpty()) {
            data.put(id, n);
        }
    }
    graph.readUnlock();
}
Also used : Graph(org.gephi.graph.api.Graph) Node(org.gephi.graph.api.Node) GraphController(org.gephi.graph.api.GraphController)

Example 95 with Graph

use of org.gephi.graph.api.Graph in project gephi by gephi.

the class ImportCSVUIWizardAction method performAction.

@Override
public void performAction() {
    wizardDescriptor = new WizardDescriptor(getPanels());
    step1.setWizardDescriptor(wizardDescriptor);
    step2.setWizardDescriptor(wizardDescriptor);
    // {0} will be replaced by WizardDesriptor.Panel.getComponent().getName()
    wizardDescriptor.setTitleFormat(new MessageFormat("{0}"));
    wizardDescriptor.setTitle(getName());
    Dialog dialog = DialogDisplayer.getDefault().createDialog(wizardDescriptor);
    dialog.setVisible(true);
    dialog.toFront();
    boolean cancelled = wizardDescriptor.getValue() != WizardDescriptor.FINISH_OPTION;
    if (!cancelled) {
        //General parameters:
        File file = (File) wizardDescriptor.getProperty("file");
        Character separator = (Character) wizardDescriptor.getProperty("separator");
        Charset charset = (Charset) wizardDescriptor.getProperty("charset");
        String[] columnNames = (String[]) wizardDescriptor.getProperty("columns-names");
        Class[] columnTypes = (Class[]) wizardDescriptor.getProperty("columns-types");
        //Nodes import parameters:
        Boolean assignNewNodeIds = (Boolean) wizardDescriptor.getProperty("assign-new-node-ids");
        //Edges import parameters:
        Boolean createNewNodes = (Boolean) wizardDescriptor.getProperty("create-new-nodes");
        Graph graph = Lookup.getDefault().lookup(GraphController.class).getGraphModel().getGraph();
        AttributeColumnsController ac = Lookup.getDefault().lookup(AttributeColumnsController.class);
        DataTablesController dtc = Lookup.getDefault().lookup(DataTablesController.class);
        dtc.setAutoRefreshEnabled(false);
        try {
            switch((Mode) wizardDescriptor.getProperty("mode")) {
                case NODES_TABLE:
                    ac.importCSVToNodesTable(graph, file, separator, charset, columnNames, columnTypes, assignNewNodeIds);
                    break;
                case EDGES_TABLE:
                    ac.importCSVToEdgesTable(graph, file, separator, charset, columnNames, columnTypes, createNewNodes);
                    break;
            }
            dtc.refreshCurrentTable();
        } catch (Exception e) {
            Logger.getLogger("").log(Level.SEVERE, null, e);
        } finally {
            dtc.setAutoRefreshEnabled(true);
        }
    }
    step1.unSetup();
    step2.unSetup();
}
Also used : MessageFormat(java.text.MessageFormat) Charset(java.nio.charset.Charset) WizardDescriptor(org.openide.WizardDescriptor) Graph(org.gephi.graph.api.Graph) Dialog(java.awt.Dialog) AttributeColumnsController(org.gephi.datalab.api.AttributeColumnsController) File(java.io.File) DataTablesController(org.gephi.datalab.api.datatables.DataTablesController)

Aggregations

Graph (org.gephi.graph.api.Graph)104 GraphModel (org.gephi.graph.api.GraphModel)57 Node (org.gephi.graph.api.Node)50 DirectedGraph (org.gephi.graph.api.DirectedGraph)43 Test (org.testng.annotations.Test)36 GraphController (org.gephi.graph.api.GraphController)27 UndirectedGraph (org.gephi.graph.api.UndirectedGraph)24 Edge (org.gephi.graph.api.Edge)21 Column (org.gephi.graph.api.Column)9 ArrayList (java.util.ArrayList)8 Function (org.gephi.appearance.api.Function)6 GraphView (org.gephi.graph.api.GraphView)6 AttributeFunction (org.gephi.appearance.api.AttributeFunction)5 AppearanceController (org.gephi.appearance.api.AppearanceController)4 AppearanceModel (org.gephi.appearance.api.AppearanceModel)4 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 TransformerUI (org.gephi.appearance.spi.TransformerUI)3 GraphElementsController (org.gephi.datalab.api.GraphElementsController)3 DataTablesController (org.gephi.datalab.api.datatables.DataTablesController)3