Search in sources :

Example 1 with Element

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

the class EqualValuesMergeStrategy method execute.

@Override
public void execute() {
    Column column1, column2;
    column1 = columns[0];
    column2 = columns[1];
    //Simplify code using data laboratory API utilities:
    AttributeColumnsController ac = Lookup.getDefault().lookup(AttributeColumnsController.class);
    //New column:
    Column newColumn = ac.addAttributeColumn(table, columnTitle, Boolean.class);
    //Fill rows of new column:
    Element[] rows = ac.getTableAttributeRows(table);
    for (int i = 0; i < rows.length; i++) {
        rows[i].setAttribute(newColumn, valuesAreEqual(column1, column2, rows[i]));
    }
}
Also used : Column(org.gephi.graph.api.Column) AttributeColumnsController(org.gephi.datalab.api.AttributeColumnsController) Element(org.gephi.graph.api.Element)

Example 2 with Element

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

the class ConvertColumnToDynamic method execute.

@Override
public void execute(Table table, Column column) {
    Class dynamicType = AttributeUtils.getIntervalMapType(column.getTypeClass());
    AttributeColumnsController ac = Lookup.getDefault().lookup(AttributeColumnsController.class);
    Element[] rows = ac.getTableAttributeRows(table);
    Object[] values = new Object[rows.length];
    Interval interval = new Interval(Double.parseDouble(start), Double.parseDouble(end));
    for (int i = 0; i < values.length; i++) {
        try {
            IntervalMap val = (IntervalMap) dynamicType.newInstance();
            val.put(interval, rows[i].getAttribute(column));
        } catch (Exception e) {
        }
    }
    table.removeColumn(column);
    Column dynamicColumn = table.addColumn(column.getId(), column.getTitle(), dynamicType, null);
    for (int i = 0; i < values.length; i++) {
        rows[i].setAttribute(dynamicColumn, values[i]);
    }
}
Also used : Column(org.gephi.graph.api.Column) AttributeColumnsController(org.gephi.datalab.api.AttributeColumnsController) Element(org.gephi.graph.api.Element) IntervalMap(org.gephi.graph.api.types.IntervalMap) Interval(org.gephi.graph.api.Interval)

Example 3 with Element

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

the class AppearanceModelImpl method isPartition.

private boolean isPartition(Graph graph, Column column) {
    int valueCount, elementCount;
    if (column.isDynamic()) {
        if (!column.isNumber()) {
            return true;
        }
        Set<Object> set = new HashSet<>();
        boolean hasNullValue = false;
        int elements = 0;
        ElementIterable<? extends Element> iterable = AttributeUtils.isNodeColumn(column) ? graph.getNodes() : graph.getEdges();
        for (Element el : iterable) {
            TimeMap val = (TimeMap) el.getAttribute(column);
            if (val != null) {
                Object[] va = val.toValuesArray();
                for (Object v : va) {
                    if (v != null) {
                        set.add(v);
                    } else {
                        hasNullValue = true;
                    }
                    elements++;
                }
            }
        }
        valueCount = set.size();
        elementCount = elements;
    } else if (column.isIndexed()) {
        if (!column.isNumber()) {
            return true;
        }
        Index index;
        if (AttributeUtils.isNodeColumn(column)) {
            index = graphModel.getNodeIndex(graph.getView());
        } else {
            index = graphModel.getEdgeIndex(graph.getView());
        }
        valueCount = index.countValues(column);
        elementCount = index.countElements(column);
    } else {
        return false;
    }
    double ratio = valueCount / (double) elementCount;
    return ratio <= 0.5 || (valueCount <= 100 && valueCount != elementCount);
}
Also used : Element(org.gephi.graph.api.Element) TimeMap(org.gephi.graph.api.types.TimeMap) Index(org.gephi.graph.api.Index) HashSet(java.util.HashSet)

Example 4 with Element

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

the class AttributeRankingImpl method refreshDynamic.

protected void refreshDynamic(ElementIterable<? extends Element> iterable) {
    double minN = Double.POSITIVE_INFINITY;
    double maxN = Double.NEGATIVE_INFINITY;
    for (Element el : iterable) {
        TimeMap timeMap = (TimeMap) el.getAttribute(column);
        if (timeMap != null) {
            double numMin = ((Number) timeMap.get(graph.getView().getTimeInterval(), Estimator.MIN)).doubleValue();
            double numMax = ((Number) timeMap.get(graph.getView().getTimeInterval(), Estimator.MAX)).doubleValue();
            if (numMin < minN) {
                minN = numMin;
            }
            if (numMax > maxN) {
                maxN = numMax;
            }
        }
    }
    min = minN;
    max = maxN;
}
Also used : Element(org.gephi.graph.api.Element) TimeMap(org.gephi.graph.api.types.TimeMap)

Example 5 with Element

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

the class AttributeColumnsControllerImpl method negateColumnBooleanType.

/**
     * Used to negate the values of a single boolean column.
     */
private void negateColumnBooleanType(Table table, Column column) {
    Object value;
    Boolean newValue;
    for (Element row : getTableAttributeRows(table)) {
        value = row.getAttribute(column);
        if (value != null) {
            newValue = !((Boolean) value);
            row.setAttribute(column, newValue);
        }
    }
}
Also used : Element(org.gephi.graph.api.Element)

Aggregations

Element (org.gephi.graph.api.Element)30 Column (org.gephi.graph.api.Column)19 AttributeColumnsController (org.gephi.datalab.api.AttributeColumnsController)15 BigDecimal (java.math.BigDecimal)8 GraphController (org.gephi.graph.api.GraphController)4 TimeFormat (org.gephi.graph.api.TimeFormat)4 DateTimeZone (org.joda.time.DateTimeZone)4 Matcher (java.util.regex.Matcher)3 GraphModel (org.gephi.graph.api.GraphModel)3 TimeMap (org.gephi.graph.api.types.TimeMap)3 ArrayList (java.util.ArrayList)2 Graph (org.gephi.graph.api.Graph)2 Interval (org.gephi.graph.api.Interval)2 IntervalSet (org.gephi.graph.api.types.IntervalSet)2 File (java.io.File)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 JFileChooser (javax.swing.JFileChooser)1 Index (org.gephi.graph.api.Index)1 Node (org.gephi.graph.api.Node)1