Search in sources :

Example 1 with Index

use of org.gephi.graph.api.Index 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)

Aggregations

HashSet (java.util.HashSet)1 Element (org.gephi.graph.api.Element)1 Index (org.gephi.graph.api.Index)1 TimeMap (org.gephi.graph.api.types.TimeMap)1