use of org.gephi.graph.api.Element in project gephi-plugins-bootcamp by gephi.
the class EqualValuesMergeStrategy method execute.
@Override
public void execute() {
Column column1, column2;
column1 = columns[0];
column2 = columns[1];
//Simplify code using data laboratory API utilities:
AttributeColumnsController ac = Lookup.getDefault().lookup(AttributeColumnsController.class);
//New column:
Column newColumn = ac.addAttributeColumn(table, columnTitle, Boolean.class);
//Fill rows of new column:
Element[] rows = ac.getTableAttributeRows(table);
for (int i = 0; i < rows.length; i++) {
rows[i].setAttribute(newColumn, valuesAreEqual(column1, column2, rows[i]));
}
}
use of org.gephi.graph.api.Element 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]);
}
}
use of org.gephi.graph.api.Element 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.Element 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.Element in project gephi by gephi.
the class AttributeColumnsControllerImpl method negateColumnBooleanType.
/**
* Used to negate the values of a single boolean column.
*/
private void negateColumnBooleanType(Table table, Column column) {
Object value;
Boolean newValue;
for (Element row : getTableAttributeRows(table)) {
value = row.getAttribute(column);
if (value != null) {
newValue = !((Boolean) value);
row.setAttribute(column, newValue);
}
}
}
Aggregations