Search in sources :

Example 11 with Table

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

the class ManageColumnEstimators method getColumns.

public List<Column> getColumns() {
    GraphModel graphModel = Lookup.getDefault().lookup(GraphController.class).getGraphModel();
    Table table;
    if (Lookup.getDefault().lookup(DataTablesController.class).isNodeTableMode()) {
        table = graphModel.getNodeTable();
    } else {
        table = graphModel.getEdgeTable();
    }
    List<Column> availableColumns = new ArrayList<>();
    for (Column column : table) {
        if (TimeMap.class.isAssignableFrom(column.getTypeClass())) {
            availableColumns.add(column);
        }
    }
    return availableColumns;
}
Also used : Table(org.gephi.graph.api.Table) Column(org.gephi.graph.api.Column) GraphModel(org.gephi.graph.api.GraphModel) ArrayList(java.util.ArrayList) GraphController(org.gephi.graph.api.GraphController) DataTablesController(org.gephi.datalab.api.datatables.DataTablesController)

Example 12 with Table

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

the class MergeNodeDuplicates method getUI.

@Override
public ManipulatorUI getUI() {
    Table nodeTable = Lookup.getDefault().lookup(GraphController.class).getGraphModel().getNodeTable();
    List<Column> columnsList = new ArrayList<>();
    for (Column column : nodeTable) {
        if (!column.isReadOnly()) {
            columnsList.add(column);
        }
    }
    columns = columnsList.toArray(new Column[0]);
    mergeStrategies = new AttributeRowsMergeStrategy[columns.length];
    deleteMergedNodes = NbPreferences.forModule(MergeNodeDuplicates.class).getBoolean(DELETE_MERGED_NODES_SAVED_PREFERENCES, true);
    caseSensitive = NbPreferences.forModule(MergeNodeDuplicates.class).getBoolean(CASE_SENSITIVE_SAVED_PREFERENCES, true);
    return new MergeNodeDuplicatesUI();
}
Also used : Table(org.gephi.graph.api.Table) Column(org.gephi.graph.api.Column) ArrayList(java.util.ArrayList) MergeNodeDuplicatesUI(org.gephi.datalab.plugin.manipulators.general.ui.MergeNodeDuplicatesUI)

Example 13 with Table

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

the class SearchReplaceControllerImpl method canReplace.

@Override
public boolean canReplace(SearchResult result) {
    GraphController gc = Lookup.getDefault().lookup(GraphController.class);
    Table table;
    Column column;
    if (result.getFoundNode() != null) {
        table = gc.getGraphModel().getNodeTable();
        column = table.getColumn(result.getFoundColumnIndex());
    } else {
        table = gc.getGraphModel().getEdgeTable();
        column = table.getColumn(result.getFoundColumnIndex());
    }
    return Lookup.getDefault().lookup(AttributeColumnsController.class).canChangeColumnData(column);
}
Also used : Table(org.gephi.graph.api.Table) Column(org.gephi.graph.api.Column) AttributeColumnsController(org.gephi.datalab.api.AttributeColumnsController) GraphController(org.gephi.graph.api.GraphController)

Example 14 with Table

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

the class GraphElementsControllerImpl method mergeNodes.

@Override
public Node mergeNodes(Graph graph, Node[] nodes, Node selectedNode, Column[] columns, AttributeRowsMergeStrategy[] mergeStrategies, boolean deleteMergedNodes) {
    Table edgesTable = graph.getModel().getEdgeTable();
    if (selectedNode == null) {
        //Use first node as selected node if null
        selectedNode = nodes[0];
    }
    //Create empty new node:
    Node newNode = createNode("", null, graph);
    //Set properties (position, size and color) using the selected node properties:
    newNode.setX(selectedNode.x());
    newNode.setY(selectedNode.y());
    newNode.setZ(selectedNode.z());
    newNode.setSize(selectedNode.size());
    newNode.setR(selectedNode.r());
    newNode.setG(selectedNode.g());
    newNode.setB(selectedNode.b());
    newNode.setAlpha(selectedNode.alpha());
    //Merge attributes:        
    AttributeColumnsController ac = Lookup.getDefault().lookup(AttributeColumnsController.class);
    ac.mergeRowsValues(columns, mergeStrategies, nodes, selectedNode, newNode);
    Set<Node> nodesSet = new HashSet<>();
    nodesSet.addAll(Arrays.asList(nodes));
    //Assign edges to the new node:
    Edge newEdge;
    for (Node node : nodes) {
        for (Edge edge : getNodeEdges(node)) {
            Node newEdgeSource;
            Node newEdgeTarget;
            if (edge.getSource() == node) {
                newEdgeSource = newNode;
                if (nodesSet.contains(edge.getTarget())) {
                    //Self loop because of edge between merged nodes
                    newEdgeTarget = newNode;
                } else {
                    newEdgeTarget = edge.getTarget();
                }
            } else {
                newEdgeTarget = newNode;
                if (nodesSet.contains(edge.getSource())) {
                    //Self loop because of edge between merged nodes
                    newEdgeSource = newNode;
                } else {
                    newEdgeSource = edge.getSource();
                }
            }
            if (graph.getEdge(newEdgeSource, newEdgeTarget) != null) {
                //This edge already exists
                continue;
            }
            newEdge = createEdge(newEdgeSource, newEdgeTarget, edge.isDirected(), edge.getTypeLabel(), graph);
            if (newEdge != null) {
                //Copy edge attributes:
                for (Column column : edgesTable) {
                    if (!column.isReadOnly()) {
                        Object value = edge.getAttribute(column);
                        if (value == null) {
                            newEdge.removeAttribute(column);
                        } else {
                            newEdge.setAttribute(column, edge.getAttribute(column));
                        }
                    }
                }
            }
        }
    }
    //Finally delete merged nodes:
    if (deleteMergedNodes) {
        deleteNodes(nodes);
    }
    return newNode;
}
Also used : Table(org.gephi.graph.api.Table) Column(org.gephi.graph.api.Column) Node(org.gephi.graph.api.Node) AttributeColumnsController(org.gephi.datalab.api.AttributeColumnsController) Edge(org.gephi.graph.api.Edge) HashSet(java.util.HashSet)

Example 15 with Table

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

the class AttributeColumnsControllerImpl method copyRowDataToOtherRows.

@Override
public void copyRowDataToOtherRows(Element row, Element[] otherRows, Column[] columnsToCopy) {
    if (columnsToCopy != null) {
        for (Column column : columnsToCopy) {
            //Copy all except id and computed attributes:
            if (canChangeColumnData(column)) {
                for (Element otherRow : otherRows) {
                    Object value = row.getAttribute(column);
                    setAttributeValue(value, otherRow, column);
                }
            }
        }
    } else {
        Table table;
        if (row instanceof Node) {
            table = Lookup.getDefault().lookup(GraphController.class).getGraphModel().getNodeTable();
        } else {
            table = Lookup.getDefault().lookup(GraphController.class).getGraphModel().getNodeTable();
        }
        for (Column column : table) {
            if (canChangeColumnData(column)) {
                for (Element otherRow : otherRows) {
                    otherRow.removeAttribute(column);
                }
            }
        }
    }
}
Also used : Table(org.gephi.graph.api.Table) Column(org.gephi.graph.api.Column) Element(org.gephi.graph.api.Element) Node(org.gephi.graph.api.Node) GraphController(org.gephi.graph.api.GraphController)

Aggregations

Table (org.gephi.graph.api.Table)28 Column (org.gephi.graph.api.Column)22 Node (org.gephi.graph.api.Node)10 GraphController (org.gephi.graph.api.GraphController)7 Edge (org.gephi.graph.api.Edge)5 GraphElementsController (org.gephi.datalab.api.GraphElementsController)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 EdgesDataTable (org.gephi.desktop.datalab.tables.EdgesDataTable)3 NodesDataTable (org.gephi.desktop.datalab.tables.NodesDataTable)3 TimeFormat (org.gephi.graph.api.TimeFormat)3 TimeRepresentation (org.gephi.graph.api.TimeRepresentation)3 DateTimeZone (org.joda.time.DateTimeZone)3 CsvReader (com.csvreader.CsvReader)2 FileInputStream (java.io.FileInputStream)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 AttributeColumnsController (org.gephi.datalab.api.AttributeColumnsController)2 SearchResult (org.gephi.datalab.api.SearchReplaceController.SearchResult)2 DataTablesController (org.gephi.datalab.api.datatables.DataTablesController)2