Search in sources :

Example 6 with AttributeColumnsController

use of org.gephi.datalab.api.AttributeColumnsController in project gephi by gephi.

the class AttributeColumnsMergeStrategiesControllerImpl method thirdQuartileNumberMerge.

@Override
public Column thirdQuartileNumberMerge(Table table, Column[] columnsToMerge, String newColumnTitle) {
    checkTableAndColumnsAreNumberOrNumberList(table, columnsToMerge);
    AttributeColumnsController ac = Lookup.getDefault().lookup(AttributeColumnsController.class);
    Column newColumn;
    // Create as BIGDECIMAL column by default. Then it can be duplicated to other type.
    newColumn = ac.addAttributeColumn(table, newColumnTitle, BigDecimal.class);
    if (newColumn == null) {
        return null;
    }
    BigDecimal Q3;
    for (Element row : ac.getTableAttributeRows(table)) {
        Q3 = StatisticsUtils.quartile3(ac.getRowNumbers(row, columnsToMerge));
        row.setAttribute(newColumn, Q3);
    }
    return newColumn;
}
Also used : Column(org.gephi.graph.api.Column) AttributeColumnsController(org.gephi.datalab.api.AttributeColumnsController) Element(org.gephi.graph.api.Element) BigDecimal(java.math.BigDecimal)

Example 7 with AttributeColumnsController

use of org.gephi.datalab.api.AttributeColumnsController in project gephi by gephi.

the class AttributeColumnsMergeStrategiesControllerImpl method interQuartileRangeNumberMerge.

@Override
public Column interQuartileRangeNumberMerge(Table table, Column[] columnsToMerge, String newColumnTitle) {
    checkTableAndColumnsAreNumberOrNumberList(table, columnsToMerge);
    AttributeColumnsController ac = Lookup.getDefault().lookup(AttributeColumnsController.class);
    Column newColumn;
    // Create as BIGDECIMAL column by default. Then it can be duplicated to other type.
    newColumn = ac.addAttributeColumn(table, newColumnTitle, BigDecimal.class);
    if (newColumn == null) {
        return null;
    }
    BigDecimal IQR, Q1, Q3;
    Number[] rowNumbers;
    for (Element row : ac.getTableAttributeRows(table)) {
        rowNumbers = ac.getRowNumbers(row, columnsToMerge);
        Q3 = StatisticsUtils.quartile3(rowNumbers);
        Q1 = StatisticsUtils.quartile1(rowNumbers);
        if (Q3 != null && Q1 != null) {
            IQR = Q3.subtract(Q1);
        } else {
            IQR = null;
        }
        row.setAttribute(newColumn, IQR);
    }
    return newColumn;
}
Also used : Column(org.gephi.graph.api.Column) AttributeColumnsController(org.gephi.datalab.api.AttributeColumnsController) Element(org.gephi.graph.api.Element) BigDecimal(java.math.BigDecimal)

Example 8 with AttributeColumnsController

use of org.gephi.datalab.api.AttributeColumnsController in project gephi by gephi.

the class AttributeColumnsMergeStrategiesControllerImpl method sumNumbersMerge.

@Override
public Column sumNumbersMerge(Table table, Column[] columnsToMerge, String newColumnTitle) {
    checkTableAndColumnsAreNumberOrNumberList(table, columnsToMerge);
    AttributeColumnsController ac = Lookup.getDefault().lookup(AttributeColumnsController.class);
    Column newColumn;
    // Create as BIGDECIMAL column by default. Then it can be duplicated to other type.
    newColumn = ac.addAttributeColumn(table, newColumnTitle, BigDecimal.class);
    if (newColumn == null) {
        return null;
    }
    BigDecimal sum;
    for (Element row : ac.getTableAttributeRows(table)) {
        sum = StatisticsUtils.sum(ac.getRowNumbers(row, columnsToMerge));
        row.setAttribute(newColumn, sum);
    }
    return newColumn;
}
Also used : Column(org.gephi.graph.api.Column) AttributeColumnsController(org.gephi.datalab.api.AttributeColumnsController) Element(org.gephi.graph.api.Element) BigDecimal(java.math.BigDecimal)

Example 9 with AttributeColumnsController

use of org.gephi.datalab.api.AttributeColumnsController in project gephi by gephi.

the class AttributeColumnsMergeStrategiesControllerImpl method medianNumberMerge.

@Override
public Column medianNumberMerge(Table table, Column[] columnsToMerge, String newColumnTitle) {
    checkTableAndColumnsAreNumberOrNumberList(table, columnsToMerge);
    AttributeColumnsController ac = Lookup.getDefault().lookup(AttributeColumnsController.class);
    Column newColumn;
    // Create as BIGDECIMAL column by default. Then it can be duplicated to other type.
    newColumn = ac.addAttributeColumn(table, newColumnTitle, BigDecimal.class);
    if (newColumn == null) {
        return null;
    }
    final int newColumnIndex = newColumn.getIndex();
    BigDecimal median;
    for (Element row : ac.getTableAttributeRows(table)) {
        median = StatisticsUtils.median(ac.getRowNumbers(row, columnsToMerge));
        row.setAttribute(newColumn, median);
    }
    return newColumn;
}
Also used : Column(org.gephi.graph.api.Column) AttributeColumnsController(org.gephi.datalab.api.AttributeColumnsController) Element(org.gephi.graph.api.Element) BigDecimal(java.math.BigDecimal)

Example 10 with AttributeColumnsController

use of org.gephi.datalab.api.AttributeColumnsController 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)

Aggregations

AttributeColumnsController (org.gephi.datalab.api.AttributeColumnsController)31 Column (org.gephi.graph.api.Column)23 Element (org.gephi.graph.api.Element)14 BigDecimal (java.math.BigDecimal)8 ArrayList (java.util.ArrayList)7 DataTablesController (org.gephi.datalab.api.datatables.DataTablesController)5 Edge (org.gephi.graph.api.Edge)3 PropertyEditor (java.beans.PropertyEditor)2 Node (org.gephi.graph.api.Node)2 TimeFormat (org.gephi.graph.api.TimeFormat)2 IntervalSet (org.gephi.graph.api.types.IntervalSet)2 AttributeValueWrapper (org.gephi.ui.tools.plugin.edit.EditWindowUtils.AttributeValueWrapper)2 DateTimeZone (org.joda.time.DateTimeZone)2 PropertySupport (org.openide.nodes.PropertySupport)2 Sheet (org.openide.nodes.Sheet)2 CsvWriter (com.csvreader.CsvWriter)1 Dialog (java.awt.Dialog)1 File (java.io.File)1 IOException (java.io.IOException)1 Charset (java.nio.charset.Charset)1