Search in sources :

Example 6 with TimeMap

use of org.gephi.graph.api.types.TimeMap in project gephi by gephi.

the class AbstractProcessor method flushToElementAttributes.

protected void flushToElementAttributes(ElementDraft elementDraft, Element element) {
    for (ColumnDraft col : elementDraft.getColumns()) {
        if (elementDraft instanceof EdgeDraft && col.getId().equals("weight")) {
            continue;
        }
        Object val = elementDraft.getValue(col.getId());
        if (val != null) {
            TimeMap existingMap;
            if (col.isDynamic() && (existingMap = (TimeMap) element.getAttribute(col.getId())) != null && !existingMap.isEmpty()) {
                TimeMap valMap = (TimeMap) val;
                Object[] keys = existingMap.toKeysArray();
                Object[] vals = existingMap.toValuesArray();
                for (int i = 0; i < keys.length; i++) {
                    valMap.put(keys[i], vals[i]);
                }
                element.setAttribute(col.getId(), valMap);
            } else {
                element.setAttribute(col.getId(), val);
            }
        }
    }
}
Also used : ColumnDraft(org.gephi.io.importer.api.ColumnDraft) EdgeDraft(org.gephi.io.importer.api.EdgeDraft) TimeMap(org.gephi.graph.api.types.TimeMap)

Example 7 with TimeMap

use of org.gephi.graph.api.types.TimeMap in project gephi by gephi.

the class AbstractProcessor method flushEdgeWeight.

protected void flushEdgeWeight(EdgeDraft edgeDraft, Edge edge) {
    Object val = edgeDraft.getValue("weight");
    if (val != null && val instanceof TimeMap) {
        TimeMap valMap = (TimeMap) val;
        TimeMap existingMap = (TimeMap) edge.getAttribute("weight");
        if (existingMap != null) {
            Object[] keys = ((TimeMap) val).toKeysArray();
            Object[] vals = ((TimeMap) val).toValuesArray();
            for (int i = 0; i < keys.length; i++) {
                valMap.put(keys[i], ((Number) vals[i]).doubleValue());
            }
        }
        edge.setAttribute("weight", val);
    }
}
Also used : TimeMap(org.gephi.graph.api.types.TimeMap)

Example 8 with TimeMap

use of org.gephi.graph.api.types.TimeMap in project gephi by gephi.

the class AttributePartitionImpl method refresh.

@Override
protected void refresh() {
    if (graph != null) {
        parts.clear();
        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) {
                    Integer count = parts.get(v);
                    if (count == null) {
                        count = 0;
                    }
                    parts.put(v, ++count);
                    elements++;
                }
            }
        }
    }
}
Also used : Element(org.gephi.graph.api.Element) TimeMap(org.gephi.graph.api.types.TimeMap)

Aggregations

TimeMap (org.gephi.graph.api.types.TimeMap)8 Element (org.gephi.graph.api.Element)3 ColumnDraft (org.gephi.io.importer.api.ColumnDraft)2 HashSet (java.util.HashSet)1 Edge (org.gephi.graph.api.Edge)1 Index (org.gephi.graph.api.Index)1 TimeSet (org.gephi.graph.api.types.TimeSet)1 EdgeDraft (org.gephi.io.importer.api.EdgeDraft)1 EdgeWeightMergeStrategy (org.gephi.io.importer.api.EdgeWeightMergeStrategy)1