Search in sources :

Example 6 with TimeRepresentation

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

the class SupportedColumnTypeWrapper method buildOrderedSupportedTypesList.

/**
     * Build a list of column type wrappers from GraphStore supported types.
     *
     * @param graphModel
     * @return Ordered column type wrappers list
     */
public static List<SupportedColumnTypeWrapper> buildOrderedSupportedTypesList(GraphModel graphModel) {
    List<SupportedColumnTypeWrapper> supportedTypesWrappers = new ArrayList<>();
    TimeRepresentation timeRepresentation = graphModel.getConfiguration().getTimeRepresentation();
    for (Class<?> type : AttributeUtils.getSupportedTypes()) {
        if (type.equals(Map.class) || type.equals(List.class) || type.equals(Set.class)) {
            continue;
        //Not yet supported in Gephi
        }
        if (AttributeUtils.isStandardizedType(type) && isTypeAvailable(type, timeRepresentation)) {
            supportedTypesWrappers.add(new SupportedColumnTypeWrapper(type));
        }
    }
    Collections.sort(supportedTypesWrappers);
    return supportedTypesWrappers;
}
Also used : TimestampSet(org.gephi.graph.api.types.TimestampSet) Set(java.util.Set) IntervalSet(org.gephi.graph.api.types.IntervalSet) TimeRepresentation(org.gephi.graph.api.TimeRepresentation) ArrayList(java.util.ArrayList)

Example 7 with TimeRepresentation

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

the class AttributeColumnsControllerImpl method convertColumnToDynamic.

private Column convertColumnToDynamic(Table table, Column column, double low, double high, String newColumnTitle) {
    Class oldType = column.getTypeClass();
    TimeRepresentation timeRepresentation = Lookup.getDefault().lookup(GraphController.class).getGraphModel().getConfiguration().getTimeRepresentation();
    Class<?> newType;
    if (timeRepresentation == TimeRepresentation.TIMESTAMP) {
        newType = AttributeUtils.getTimestampMapType(oldType);
    } else {
        newType = AttributeUtils.getIntervalMapType(oldType);
    }
    if (newColumnTitle != null) {
        if (newColumnTitle.equals(column.getTitle())) {
            throw new IllegalArgumentException("Column titles can't be equal");
        }
    }
    Element[] rows = getTableAttributeRows(table);
    Object[] oldValues = new Object[rows.length];
    for (int i = 0; i < rows.length; i++) {
        oldValues[i] = rows[i].getAttribute(column);
    }
    Column newColumn;
    if (newColumnTitle == null) {
        table.removeColumn(column);
        newColumn = table.addColumn(column.getTitle(), newType, column.getOrigin());
    } else {
        newColumn = table.addColumn(newColumnTitle, newType, column.getOrigin());
    }
    if (timeRepresentation == TimeRepresentation.TIMESTAMP) {
        for (int i = 0; i < rows.length; i++) {
            if (oldValues[i] != null) {
                rows[i].setAttribute(newColumn, oldValues[i], low);
            }
        }
    } else {
        Interval interval = new Interval(low, high);
        for (int i = 0; i < rows.length; i++) {
            if (oldValues[i] != null) {
                rows[i].setAttribute(newColumn, oldValues[i], interval);
            }
        }
    }
    return newColumn;
}
Also used : Column(org.gephi.graph.api.Column) TimeRepresentation(org.gephi.graph.api.TimeRepresentation) Element(org.gephi.graph.api.Element) GraphController(org.gephi.graph.api.GraphController) Interval(org.gephi.graph.api.Interval)

Aggregations

TimeRepresentation (org.gephi.graph.api.TimeRepresentation)7 Interval (org.gephi.graph.api.Interval)3 Table (org.gephi.graph.api.Table)3 Graph (org.gephi.graph.api.Graph)2 Node (org.gephi.graph.api.Node)2 ArrayList (java.util.ArrayList)1 Set (java.util.Set)1 Column (org.gephi.graph.api.Column)1 DirectedGraph (org.gephi.graph.api.DirectedGraph)1 Element (org.gephi.graph.api.Element)1 GraphController (org.gephi.graph.api.GraphController)1 IntervalSet (org.gephi.graph.api.types.IntervalSet)1 TimestampSet (org.gephi.graph.api.types.TimestampSet)1 ColumnDraft (org.gephi.io.importer.api.ColumnDraft)1 ClusteringCoefficient (org.gephi.statistics.plugin.ClusteringCoefficient)1