use of org.eclipse.zest.layouts.dataStructures.InternalNode in project archi by archimatetool.
the class HorizontalTreeLayoutAlgorithm method postLayoutAlgorithm.
@Override
protected void postLayoutAlgorithm(InternalNode[] entitiesToLayout, InternalRelationship[] relationshipsToConsider) {
// swap x->y and width->height
for (int i = 0; i < entitiesToLayout.length; i++) {
InternalNode entity = entitiesToLayout[i];
entity.setInternalLocation(entity.getInternalY(), entity.getInternalX());
entity.setInternalSize(entity.getInternalWidth(), entity.getInternalHeight());
}
super.postLayoutAlgorithm(entitiesToLayout, relationshipsToConsider);
}
use of org.eclipse.zest.layouts.dataStructures.InternalNode in project archi by archimatetool.
the class SpringLayoutAlgorithm method preCompute.
private void preCompute(InternalNode[] entitiesToLayout) {
// count number of relationships between all nodes and the average
// weight between them
srcDestToNumRels = new int[entitiesToLayout.length][entitiesToLayout.length];
srcDestToRelsAvgWeight = new double[entitiesToLayout.length][entitiesToLayout.length];
for (int i = 0; i < entitiesToLayout.length - 1; i++) {
InternalNode layoutEntity1 = entitiesToLayout[i];
for (int j = i + 1; j < entitiesToLayout.length; j++) {
InternalNode layoutEntity2 = entitiesToLayout[j];
srcDestToNumRels[i][j] = numRelations(layoutEntity1, layoutEntity2);
srcDestToNumRels[i][j] += numRelations(layoutEntity2, layoutEntity1);
srcDestToRelsAvgWeight[i][j] = avgWeight(layoutEntity1, layoutEntity2);
}
}
if (sprRandom)
// put vertices in random places
placeRandomly(entitiesToLayout);
else
convertToUnitCoordinates(entitiesToLayout);
iteration = 1;
largestMovement = Double.MAX_VALUE;
}
use of org.eclipse.zest.layouts.dataStructures.InternalNode in project archi by archimatetool.
the class SpringLayoutAlgorithm method computeForces.
// /////////////////////////////////////////////////////////////////
// /// Protected Methods /////
// /////////////////////////////////////////////////////////////////
/**
* Computes the force for each node in this SpringLayoutAlgorithm. The
* computed force will be stored in the data repository
*/
protected void computeForces(InternalNode[] entitiesToLayout) {
// initialize all forces to zero
for (int i = 0; i < entitiesToLayout.length; i++) {
forcesX[i] = 0.0;
forcesY[i] = 0.0;
}
for (int i = 0; i < entitiesToLayout.length - 1; i++) {
InternalNode sourceEntity = entitiesToLayout[i];
double srcLocationX = tempLocationsX[i];
double srcLocationY = tempLocationsY[i];
// force in x direction
double fx = forcesX[i];
// force in y direction
double fy = forcesY[i];
for (int j = i + 1; j < entitiesToLayout.length; j++) {
InternalNode destinationEntity = entitiesToLayout[j];
if (!destinationEntity.equals(sourceEntity)) {
double destLocationX = tempLocationsX[j];
double destLocationY = tempLocationsY[j];
double dx = srcLocationX - destLocationX;
double dy = srcLocationY - destLocationY;
double distance = Math.sqrt(dx * dx + dy * dy);
double distance_sq = distance * distance;
// make sure distance and distance squared not too small
distance = Math.max(MIN_DISTANCE, distance);
// If there are relationships between srcObj and destObj
// then decrease force on srcObj (a pull) in direction of destObj
// If no relation between srcObj and destObj then increase
// force on srcObj (a push) from direction of destObj.
int numRels = srcDestToNumRels[i][j];
double avgWeight = srcDestToRelsAvgWeight[i][j];
if (numRels > 0) {
// nodes are pulled towards each other
double f = sprStrain * Math.log(distance / sprLength) * numRels * avgWeight;
fx = fx - (f * dx / distance);
fy = fy - (f * dy / distance);
} else {
// nodes are repelled from each other
// double f = Math.min(100, sprGravitation / (distance*distance));
double f = sprGravitation / (distance_sq);
fx = fx + (f * dx / distance);
fy = fy + (f * dy / distance);
}
// According to Newton, "for every action, there is an equal
// and opposite reaction."
// so give the dest an opposite force
forcesX[j] = forcesX[j] - fx;
forcesY[j] = forcesY[j] - fy;
}
}
/*
* //make sure forces aren't too big if (fx > 0 ) fx = Math.min(fx,
* 10*sprMove); else fx = Math.max(fx, -10*sprMove); if (fy > 0) fy =
* Math.min(fy, 10*sprMove); else fy = Math.max(fy, -10*sprMove);
*/
forcesX[i] = fx;
forcesY[i] = fy;
// Remove the src object from the list of destinations since
// we've already calculated the force from it on all other
// objects.
// dests.remove(srcObj);
}
}
Aggregations