use of org.gephi.datalab.api.AttributeColumnsController 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.datalab.api.AttributeColumnsController 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.datalab.api.AttributeColumnsController 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.datalab.api.AttributeColumnsController 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.datalab.api.AttributeColumnsController in project gephi by gephi.
the class GraphElementsControllerImpl method mergeNodes.
@Override
public Node mergeNodes(Graph graph, Node[] nodes, Node selectedNode, Column[] columns, AttributeRowsMergeStrategy[] mergeStrategies, boolean deleteMergedNodes) {
Table edgesTable = graph.getModel().getEdgeTable();
if (selectedNode == null) {
// Use first node as selected node if null
selectedNode = nodes[0];
}
// Create empty new node:
Node newNode = createNode("", null, graph);
// Set properties (position, size and color) using the selected node properties:
newNode.setX(selectedNode.x());
newNode.setY(selectedNode.y());
newNode.setZ(selectedNode.z());
newNode.setSize(selectedNode.size());
newNode.setR(selectedNode.r());
newNode.setG(selectedNode.g());
newNode.setB(selectedNode.b());
newNode.setAlpha(selectedNode.alpha());
// Merge attributes:
AttributeColumnsController ac = Lookup.getDefault().lookup(AttributeColumnsController.class);
ac.mergeRowsValues(columns, mergeStrategies, nodes, selectedNode, newNode);
Set<Node> nodesSet = new HashSet<>();
nodesSet.addAll(Arrays.asList(nodes));
// Assign edges to the new node:
Edge newEdge;
for (Node node : nodes) {
for (Edge edge : getNodeEdges(node)) {
Node newEdgeSource;
Node newEdgeTarget;
if (edge.getSource() == node) {
newEdgeSource = newNode;
if (nodesSet.contains(edge.getTarget())) {
// Self loop because of edge between merged nodes
newEdgeTarget = newNode;
} else {
newEdgeTarget = edge.getTarget();
}
} else {
newEdgeTarget = newNode;
if (nodesSet.contains(edge.getSource())) {
// Self loop because of edge between merged nodes
newEdgeSource = newNode;
} else {
newEdgeSource = edge.getSource();
}
}
if (graph.getEdge(newEdgeSource, newEdgeTarget) != null) {
// This edge already exists
continue;
}
newEdge = createEdge(newEdgeSource, newEdgeTarget, edge.isDirected(), edge.getTypeLabel(), graph);
if (newEdge != null) {
// Copy edge attributes:
for (Column column : edgesTable) {
if (!column.isReadOnly()) {
Object value = edge.getAttribute(column);
if (value == null) {
newEdge.removeAttribute(column);
} else {
newEdge.setAttribute(column, edge.getAttribute(column));
}
}
}
}
}
}
// Finally delete merged nodes:
if (deleteMergedNodes) {
deleteNodes(nodes);
}
return newNode;
}
Aggregations