use of org.gephi.graph.api.types.TimeMap 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);
}
use of org.gephi.graph.api.types.TimeMap 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;
}
use of org.gephi.graph.api.types.TimeMap in project gephi by gephi.
the class EdgeWeightRankingImpl method refresh.
@Override
protected void refresh() {
if (graph.getEdgeCount() > 0) {
double minV = Double.MAX_VALUE;
double maxV = Double.MIN_VALUE;
for (Edge e : graph.getEdges()) {
if (e.hasDynamicWeight()) {
TimeMap timeMap = (TimeMap) e.getAttribute("weight");
if (timeMap != null) {
Double numMin = (Double) timeMap.get(graph.getView().getTimeInterval(), Estimator.MIN);
Double numMax = (Double) timeMap.get(graph.getView().getTimeInterval(), Estimator.MAX);
minV = Math.min(numMin, minV);
maxV = Math.max(numMax, maxV);
}
} else {
minV = Math.min(e.getWeight(), minV);
maxV = Math.max(e.getWeight(), maxV);
}
}
min = minV;
max = maxV;
}
}
use of org.gephi.graph.api.types.TimeMap in project gephi by gephi.
the class TimeMapStringConverter method getString.
@Override
public String getString(Object value) {
String str = null;
if (value != null) {
TimeMap timeMap = (TimeMap) value;
str = timeMap.toString(graphModelProvider.getGraphModel().getTimeFormat(), graphModelProvider.getGraphModel().getTimeZone());
}
return str;
}
use of org.gephi.graph.api.types.TimeMap in project gephi by gephi.
the class ImportContainerImpl method mergeParallelEdges.
protected void mergeParallelEdges(EdgeDraftImpl[] sources, EdgeDraftImpl dest) {
Object val = dest.getValue("weight");
if (val == null || !(val instanceof TimeMap)) {
EdgeWeightMergeStrategy mergeStrategy = parameters.getEdgesMergeStrategy();
int count = 1 + sources.length;
double sum = dest.getWeight();
double min = dest.getWeight();
double max = dest.getWeight();
for (EdgeDraftImpl edge : sources) {
sum += edge.getWeight();
min = Math.min(min, edge.getWeight());
max = Math.max(max, edge.getWeight());
}
double result = dest.getWeight();
switch(mergeStrategy) {
case AVG:
result = sum / count;
break;
case MAX:
result = max;
break;
case MIN:
result = min;
break;
case SUM:
result = sum;
break;
default:
break;
}
dest.setWeight(result);
}
//Add dest to sources for convenience
sources = Arrays.copyOf(sources, sources.length + 1);
sources[sources.length - 1] = dest;
//Merge dynamic attributes
for (ColumnDraft columnDraft : getEdgeColumns()) {
if (columnDraft.isDynamic()) {
TimeMap timeMap = null;
for (EdgeDraftImpl edge : sources) {
TimeMap t = (TimeMap) edge.getValue(columnDraft.getId());
if (t != null && timeMap == null) {
timeMap = t;
} else if (t != null && timeMap != null) {
for (Object key : t.toKeysArray()) {
timeMap.put(key, t.get(key, null));
}
}
}
if (timeMap != null) {
dest.setValue(columnDraft.getId(), timeMap);
}
}
}
//Merge timeset
TimeSet timeSet = null;
for (EdgeDraftImpl edge : sources) {
TimeSet t = edge.getTimeSet();
if (t != null && timeSet == null) {
timeSet = t;
} else if (t != null && timeSet != null) {
for (Object key : t.toArray()) {
timeSet.add(key);
}
}
}
if (timeSet != null) {
dest.timeSet = timeSet;
}
}
Aggregations