use of org.gephi.graph.api.Interval in project gephi by gephi.
the class DynamicClusteringCoefficient method loop.
@Override
public void loop(GraphView window, Interval interval) {
Graph graph;
if (isDirected) {
graph = graphModel.getDirectedGraph(window);
} else {
graph = graphModel.getUndirectedGraph(window);
}
TimeRepresentation tr = graphModel.getConfiguration().getTimeRepresentation();
graph.readLock();
try {
clusteringCoefficientStat = new ClusteringCoefficient();
clusteringCoefficientStat.setDirected(isDirected);
clusteringCoefficientStat.triangles(graph);
//Columns
if (!averageOnly) {
double[] coefficients = clusteringCoefficientStat.getCoefficientReuslts();
int i = 0;
for (Node n : graph.getNodes()) {
double coef = coefficients[i++];
switch(tr) {
case INTERVAL:
n.setAttribute(dynamicCoefficientColumn, coef, new Interval(interval.getLow(), interval.getLow() + tick));
break;
case TIMESTAMP:
n.setAttribute(dynamicCoefficientColumn, coef, interval.getLow());
n.setAttribute(dynamicCoefficientColumn, coef, interval.getHigh());
break;
}
if (cancel) {
break;
}
}
}
} finally {
graph.readUnlockAll();
}
//Average
double avg = clusteringCoefficientStat.getAverageClusteringCoefficient();
graphModel.getGraphVisible().setAttribute(DYNAMIC_AVG_CLUSTERING_COEFFICIENT, avg, interval.getLow());
graphModel.getGraphVisible().setAttribute(DYNAMIC_AVG_CLUSTERING_COEFFICIENT, avg, interval.getHigh());
averages.put(interval.getLow(), avg);
averages.put(interval.getHigh(), avg);
}
use of org.gephi.graph.api.Interval in project gephi by gephi.
the class DynamicDegree method loop.
@Override
public void loop(GraphView window, Interval interval) {
Graph graph = graphModel.getGraph(window);
DirectedGraph directedGraph = null;
if (isDirected) {
directedGraph = graphModel.getDirectedGraph(window);
}
TimeRepresentation tr = graphModel.getConfiguration().getTimeRepresentation();
long sum = 0;
for (Node n : graph.getNodes().toArray()) {
int degree = graph.getDegree(n);
if (!averageOnly) {
switch(tr) {
case INTERVAL:
n.setAttribute(dynamicDegreeColumn, degree, new Interval(interval.getLow(), interval.getLow() + tick));
break;
case TIMESTAMP:
n.setAttribute(dynamicDegreeColumn, degree, interval.getLow());
n.setAttribute(dynamicDegreeColumn, degree, interval.getHigh());
break;
}
if (isDirected) {
int indegree = directedGraph.getInDegree(n);
int outdegree = directedGraph.getOutDegree(n);
switch(tr) {
case INTERVAL:
n.setAttribute(dynamicInDegreeColumn, indegree, new Interval(interval.getLow(), interval.getLow() + tick));
n.setAttribute(dynamicOutDegreeColumn, outdegree, new Interval(interval.getLow(), interval.getLow() + tick));
break;
case TIMESTAMP:
n.setAttribute(dynamicInDegreeColumn, indegree, interval.getLow());
n.setAttribute(dynamicInDegreeColumn, indegree, interval.getHigh());
n.setAttribute(dynamicOutDegreeColumn, outdegree, interval.getLow());
n.setAttribute(dynamicOutDegreeColumn, outdegree, interval.getHigh());
break;
}
}
}
sum += degree;
if (cancel) {
break;
}
}
double avg = sum / (double) graph.getNodeCount();
averages.put(interval.getLow(), avg);
averages.put(interval.getHigh(), avg);
graphModel.getGraphVisible().setAttribute(DYNAMIC_AVGDEGREE, avg, interval.getLow());
graphModel.getGraphVisible().setAttribute(DYNAMIC_AVGDEGREE, avg, interval.getHigh());
}
use of org.gephi.graph.api.Interval 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;
}
use of org.gephi.graph.api.Interval in project gephi by gephi.
the class GraphObserverThread method run.
@Override
public void run() {
while (!stop) {
GraphModel graphModel = timelineModel.getGraphModel();
Interval bounds = graphModel.getTimeBounds();
if (!bounds.equals(interval)) {
interval = bounds;
timelineController.setMinMax(interval.getLow(), interval.getHigh());
}
try {
Thread.sleep(1000);
} catch (InterruptedException ex) {
}
}
}
use of org.gephi.graph.api.Interval in project gephi by gephi.
the class AbstractElementsDataTable method refreshModel.
public void refreshModel(T[] elements, Column[] cols, GraphModel graphModel, DataTablesModel dataTablesModel) {
this.graphModel = graphModel;
showingColumns = cols;
Interval timeBounds = graphModel.getTimeBounds();
double min = timeBounds != null ? timeBounds.getLow() : 0;
double max = timeBounds != null ? timeBounds.getHigh() : 0;
refreshCellRenderersConfiguration(graphModel, min, max);
refreshingTable = true;
if (selectedElements == null) {
selectedElements = getElementsFromSelectedRows();
}
ArrayList<ElementDataColumn<T>> columns = new ArrayList<>();
columns.addAll(getFakeDataColumns(graphModel, dataTablesModel));
for (Column c : cols) {
columns.add(new AttributeDataColumn<T>(attributeColumnsController, c));
}
if (model == null) {
model = new ElementsDataTableModel<>(elements, columns.toArray(new ElementDataColumn[0]));
table.setModel(model);
} else {
model.configure(elements, columns.toArray(new ElementDataColumn[0]));
}
//Keep row selection before refreshing.
setElementsSelection(selectedElements);
selectedElements = null;
refreshingTable = false;
}
Aggregations