Search in sources :

Example 1 with IntervalMap

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

the class IntervalMapSparklinesGraphicsComponentProvider method getSparklinesXAndYNumbers.

@Override
public Number[][] getSparklinesXAndYNumbers(Object value) {
    IntervalMap intervalMap = (IntervalMap) value;
    ArrayList<Number> xValues = new ArrayList<>();
    ArrayList<Number> yValues = new ArrayList<>();
    if (intervalMap == null) {
        return new Number[2][0];
    }
    Interval[] intervals = intervalMap.toKeysArray();
    Object[] values = intervalMap.toValuesArray();
    Number n;
    for (int i = 0; i < intervals.length; i++) {
        n = (Number) values[i];
        if (n != null) {
            xValues.add(intervals[i].getLow());
            yValues.add(n);
        }
    }
    return new Number[][] { xValues.toArray(new Number[0]), yValues.toArray(new Number[0]) };
}
Also used : ArrayList(java.util.ArrayList) IntervalMap(org.gephi.graph.api.types.IntervalMap) Interval(org.gephi.graph.api.Interval)

Example 2 with IntervalMap

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

the class IntervalMapSparklinesGraphicsComponentProvider method getTextFromValue.

@Override
public String getTextFromValue(Object value) {
    if (value == null) {
        return null;
    }
    TimeFormat timeFormat = graphModelProvider.getGraphModel().getTimeFormat();
    DateTimeZone timeZone = graphModelProvider.getGraphModel().getTimeZone();
    return ((IntervalMap) value).toString(timeFormat, timeZone);
}
Also used : TimeFormat(org.gephi.graph.api.TimeFormat) DateTimeZone(org.joda.time.DateTimeZone) IntervalMap(org.gephi.graph.api.types.IntervalMap)

Example 3 with IntervalMap

use of org.gephi.graph.api.types.IntervalMap 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 4 with IntervalMap

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

the class AbstractProcessor method flushEdgeWeight.

protected void flushEdgeWeight(ContainerUnloader container, EdgeDraft edgeDraft, Edge edge, boolean newEdge) {
    Column weightColumn = graphModel.getEdgeTable().getColumn("weight");
    ColumnDraft weightColumnDraft = container.getEdgeColumn("weight");
    boolean weightColumnDraftIsDynamic = weightColumnDraft != null && weightColumnDraft.isDynamic();
    if (weightColumn.isDynamic() != weightColumnDraftIsDynamic) {
        Class weightColumnDraftTypeClass = weightColumnDraft != null ? weightColumnDraft.getResolvedTypeClass(container) : Double.class;
        if (!columnsTypeMismatchAlreadyWarned.contains(weightColumn)) {
            columnsTypeMismatchAlreadyWarned.add(weightColumn);
            String error = NbBundle.getMessage(AbstractProcessor.class, "AbstractProcessor.error.columnTypeMismatch", weightColumn.getId(), weightColumn.getTypeClass().getSimpleName(), weightColumnDraftTypeClass.getSimpleName());
            report.logIssue(new Issue(error, Issue.Level.SEVERE));
        }
        return;
    }
    if (weightColumn.isDynamic()) {
        Object val = edgeDraft.getValue("weight");
        if (val != null && val instanceof TimeMap) {
            TimeMap valMap = (TimeMap) val;
            if (Number.class.isAssignableFrom(valMap.getTypeClass())) {
                final TimeMap newMap;
                if (val instanceof IntervalMap) {
                    newMap = new IntervalDoubleMap();
                } else {
                    newMap = new TimestampDoubleMap();
                }
                TimeMap existingMap = (TimeMap) edge.getAttribute("weight");
                if (existingMap != null) {
                    Object[] keys2 = existingMap.toKeysArray();
                    Object[] vals2 = existingMap.toValuesArray();
                    for (int i = 0; i < keys2.length; i++) {
                        newMap.put(keys2[i], ((Number) vals2[i]).doubleValue());
                    }
                }
                Object[] keys1 = valMap.toKeysArray();
                Object[] vals1 = valMap.toValuesArray();
                for (int i = 0; i < keys1.length; i++) {
                    try {
                        newMap.put(keys1[i], ((Number) vals1[i]).doubleValue());
                    } catch (IllegalArgumentException e) {
                    // Overlapping intervals, ignore
                    }
                }
                edge.setAttribute("weight", newMap);
            }
        }
    } else if (!newEdge) {
        if (edgeDraft.getTimeSet() != null || edgeDraft.getValue("timeset") != null || edge.getAttribute("timeset") != null) {
            // Don't merge double (non dynamic) weights when the edges have dynamic time intervals/timestamps, they are the same edge in different periods of time
            return;
        }
        // Merge the existing edge and the draft edge weights:
        double result = edge.getWeight();
        edgeCountForAverage.addTo(edge, 1);
        int edgeCount = edgeCountForAverage.getInt(edge);
        switch(containers[0].getEdgesMergeStrategy()) {
            case AVG:
                result = (edge.getWeight() * edgeCount + edgeDraft.getWeight()) / (edgeCount + 1);
                break;
            case MAX:
                result = Math.max(edgeDraft.getWeight(), edge.getWeight());
                break;
            case MIN:
                result = Math.min(edgeDraft.getWeight(), edge.getWeight());
                break;
            case SUM:
                result = edgeDraft.getWeight() + edge.getWeight();
                break;
            case FIRST:
                result = edge.getWeight();
                break;
            case LAST:
                result = edgeDraft.getWeight();
                break;
            default:
                break;
        }
        edge.setWeight(result);
    }
}
Also used : ColumnDraft(org.gephi.io.importer.api.ColumnDraft) Issue(org.gephi.io.importer.api.Issue) TimeMap(org.gephi.graph.api.types.TimeMap) IntervalDoubleMap(org.gephi.graph.api.types.IntervalDoubleMap) Column(org.gephi.graph.api.Column) TimestampDoubleMap(org.gephi.graph.api.types.TimestampDoubleMap) IntervalMap(org.gephi.graph.api.types.IntervalMap)

Example 5 with IntervalMap

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

the class AttributeColumnsControllerImpl method getDynamicNumberColumnNumbers.

/**
 * Used for obtaining a list of the numbers of row of a dynamic number column.
 *
 * @param row Row
 * @param column Column with dynamic type
 * @return list of numbers
 */
private List<Number> getDynamicNumberColumnNumbers(Element row, Column column) {
    Class type = column.getTypeClass();
    if (!(AttributeUtils.isNumberType(type) && AttributeUtils.isDynamicType(type))) {
        throw new IllegalArgumentException("Column must be a dynamic number column");
    }
    if (TimestampMap.class.isAssignableFrom(type)) {
        // Timestamp type:
        TimestampMap timestampMap = (TimestampMap) row.getAttribute(column);
        if (timestampMap == null) {
            return new ArrayList<>();
        }
        Number[] dynamicNumbers = (Number[]) timestampMap.toValuesArray();
        return Arrays.asList(dynamicNumbers);
    } else if (IntervalMap.class.isAssignableFrom(type)) {
        // Interval type:
        IntervalMap intervalMap = (IntervalMap) row.getAttribute(column);
        if (intervalMap == null) {
            return new ArrayList<>();
        }
        Number[] dynamicNumbers = (Number[]) intervalMap.toValuesArray();
        return Arrays.asList(dynamicNumbers);
    } else {
        throw new IllegalArgumentException("Unsupported dynamic type class " + type.getCanonicalName());
    }
}
Also used : TimestampMap(org.gephi.graph.api.types.TimestampMap) ArrayList(java.util.ArrayList) IntervalMap(org.gephi.graph.api.types.IntervalMap)

Aggregations

IntervalMap (org.gephi.graph.api.types.IntervalMap)5 ArrayList (java.util.ArrayList)2 Column (org.gephi.graph.api.Column)2 Interval (org.gephi.graph.api.Interval)2 AttributeColumnsController (org.gephi.datalab.api.AttributeColumnsController)1 Element (org.gephi.graph.api.Element)1 TimeFormat (org.gephi.graph.api.TimeFormat)1 IntervalDoubleMap (org.gephi.graph.api.types.IntervalDoubleMap)1 TimeMap (org.gephi.graph.api.types.TimeMap)1 TimestampDoubleMap (org.gephi.graph.api.types.TimestampDoubleMap)1 TimestampMap (org.gephi.graph.api.types.TimestampMap)1 ColumnDraft (org.gephi.io.importer.api.ColumnDraft)1 Issue (org.gephi.io.importer.api.Issue)1 DateTimeZone (org.joda.time.DateTimeZone)1