use of org.gephi.graph.api.Element in project gephi by gephi.
the class AttributeColumnsMergeStrategiesControllerImpl method interQuartileRangeNumberMerge.
@Override
public Column interQuartileRangeNumberMerge(Table table, Column[] columnsToMerge, String newColumnTitle) {
checkTableAndColumnsAreNumberOrNumberList(table, columnsToMerge);
AttributeColumnsController ac = Lookup.getDefault().lookup(AttributeColumnsController.class);
Column newColumn;
//Create as BIGDECIMAL column by default. Then it can be duplicated to other type.
newColumn = ac.addAttributeColumn(table, newColumnTitle, BigDecimal.class);
if (newColumn == null) {
return null;
}
BigDecimal IQR, Q1, Q3;
Number[] rowNumbers;
for (Element row : ac.getTableAttributeRows(table)) {
rowNumbers = ac.getRowNumbers(row, columnsToMerge);
Q3 = StatisticsUtils.quartile3(rowNumbers);
Q1 = StatisticsUtils.quartile1(rowNumbers);
if (Q3 != null && Q1 != null) {
IQR = Q3.subtract(Q1);
} else {
IQR = null;
}
row.setAttribute(newColumn, IQR);
}
return newColumn;
}
use of org.gephi.graph.api.Element in project gephi by gephi.
the class AttributeColumnsMergeStrategiesControllerImpl method medianNumberMerge.
@Override
public Column medianNumberMerge(Table table, Column[] columnsToMerge, String newColumnTitle) {
checkTableAndColumnsAreNumberOrNumberList(table, columnsToMerge);
AttributeColumnsController ac = Lookup.getDefault().lookup(AttributeColumnsController.class);
Column newColumn;
//Create as BIGDECIMAL column by default. Then it can be duplicated to other type.
newColumn = ac.addAttributeColumn(table, newColumnTitle, BigDecimal.class);
if (newColumn == null) {
return null;
}
final int newColumnIndex = newColumn.getIndex();
BigDecimal median;
for (Element row : ac.getTableAttributeRows(table)) {
median = StatisticsUtils.median(ac.getRowNumbers(row, columnsToMerge));
row.setAttribute(newColumn, median);
}
return newColumn;
}
use of org.gephi.graph.api.Element in project gephi by gephi.
the class AttributeColumnsMergeStrategiesControllerImpl method sumNumbersMerge.
@Override
public Column sumNumbersMerge(Table table, Column[] columnsToMerge, String newColumnTitle) {
checkTableAndColumnsAreNumberOrNumberList(table, columnsToMerge);
AttributeColumnsController ac = Lookup.getDefault().lookup(AttributeColumnsController.class);
Column newColumn;
//Create as BIGDECIMAL column by default. Then it can be duplicated to other type.
newColumn = ac.addAttributeColumn(table, newColumnTitle, BigDecimal.class);
if (newColumn == null) {
return null;
}
BigDecimal sum;
for (Element row : ac.getTableAttributeRows(table)) {
sum = StatisticsUtils.sum(ac.getRowNumbers(row, columnsToMerge));
row.setAttribute(newColumn, sum);
}
return newColumn;
}
use of org.gephi.graph.api.Element in project gephi by gephi.
the class AttributeColumnsMergeStrategiesControllerImpl method thirdQuartileNumberMerge.
@Override
public Column thirdQuartileNumberMerge(Table table, Column[] columnsToMerge, String newColumnTitle) {
checkTableAndColumnsAreNumberOrNumberList(table, columnsToMerge);
AttributeColumnsController ac = Lookup.getDefault().lookup(AttributeColumnsController.class);
Column newColumn;
//Create as BIGDECIMAL column by default. Then it can be duplicated to other type.
newColumn = ac.addAttributeColumn(table, newColumnTitle, BigDecimal.class);
if (newColumn == null) {
return null;
}
BigDecimal Q3;
for (Element row : ac.getTableAttributeRows(table)) {
Q3 = StatisticsUtils.quartile3(ac.getRowNumbers(row, columnsToMerge));
row.setAttribute(newColumn, Q3);
}
return newColumn;
}
use of org.gephi.graph.api.Element in project gephi by gephi.
the class AttributeColumnsControllerImpl method copyRowDataToOtherRows.
@Override
public void copyRowDataToOtherRows(Element row, Element[] otherRows, Column[] columnsToCopy) {
if (columnsToCopy != null) {
for (Column column : columnsToCopy) {
//Copy all except id and computed attributes:
if (canChangeColumnData(column)) {
for (Element otherRow : otherRows) {
Object value = row.getAttribute(column);
setAttributeValue(value, otherRow, column);
}
}
}
} else {
Table table;
if (row instanceof Node) {
table = Lookup.getDefault().lookup(GraphController.class).getGraphModel().getNodeTable();
} else {
table = Lookup.getDefault().lookup(GraphController.class).getGraphModel().getNodeTable();
}
for (Column column : table) {
if (canChangeColumnData(column)) {
for (Element otherRow : otherRows) {
otherRow.removeAttribute(column);
}
}
}
}
}
Aggregations