use of org.eclipse.zest.layouts.dataStructures.InternalNode in project archi by archimatetool.
the class TreeLayoutAlgorithm method getNumDescendentsAndLevelRecursive.
private void getNumDescendentsAndLevelRecursive(InternalNode layoutEntity, InternalRelationship[] relationships, Set seenAlready, int[] numDescendentsAndLevel, int currentLevel) {
if (seenAlready.contains(layoutEntity)) {
return;
}
seenAlready.add(layoutEntity);
numDescendentsAndLevel[NUM_LEVELS_INDEX] = Math.max(numDescendentsAndLevel[NUM_LEVELS_INDEX], currentLevel);
Collection rels = findRelationships(layoutEntity, AS_SOURCE, relationships);
for (Iterator iter = rels.iterator(); iter.hasNext(); ) {
InternalRelationship layoutRel = (InternalRelationship) iter.next();
InternalNode childEntity = layoutRel.getDestination();
numDescendentsAndLevel[NUM_DESCENDENTS_INDEX]++;
getNumDescendentsAndLevelRecursive(childEntity, relationships, seenAlready, numDescendentsAndLevel, currentLevel + 1);
}
}
use of org.eclipse.zest.layouts.dataStructures.InternalNode in project archi by archimatetool.
the class TreeLayoutAlgorithm method modifyWeightRecursively.
/**
* Modifies the weight value of the marked node recursively.
*/
private void modifyWeightRecursively(InternalNode layoutEntity, int i, double weight, Set descendentsSeenSoFar, InternalNode[] entities, InternalRelationship[] relationships) {
// No need to do further computation!
if (layoutEntity == null) {
return;
}
if (descendentsSeenSoFar.contains(layoutEntity)) {
// No need to do further computation.
return;
}
descendentsSeenSoFar.add(layoutEntity);
// No need to do further computation!
if (weight < weights[i]) {
return;
}
weights[i] = weight;
Collection rels = findRelationships(layoutEntity, AS_SOURCE, relationships);
for (Iterator iter = rels.iterator(); iter.hasNext(); ) {
InternalRelationship tmpRel = (InternalRelationship) iter.next();
InternalNode tmpEntity = tmpRel.getDestination();
int tmpEntityIndex = indexOfInternalNode(entities, tmpEntity);
modifyWeightRecursively(tmpEntity, tmpEntityIndex, weight + 1, descendentsSeenSoFar, entities, relationships);
}
}
use of org.eclipse.zest.layouts.dataStructures.InternalNode in project archi by archimatetool.
the class TreeLayoutAlgorithm method getMaxiumWeightRecursive.
/**
* Gets the maxium weight of a tree in the forest of this TreeLayoutAlgorithm.
*/
private double getMaxiumWeightRecursive(InternalNode layoutEntity, int i, Set seenAlready, InternalNode[] entities) {
double result = 0;
if (seenAlready.contains(layoutEntity)) {
return result;
}
seenAlready.add(layoutEntity);
List children = childrenLists[i];
if (children.isEmpty()) {
result = weights[i];
} else {
// TODO: SLOW
for (Iterator iter = children.iterator(); iter.hasNext(); ) {
InternalNode childEntity = (InternalNode) iter.next();
int childEntityIndex = indexOfInternalNode(entities, childEntity);
result = Math.max(result, getMaxiumWeightRecursive(childEntity, childEntityIndex, seenAlready, entities));
}
}
return result;
}
use of org.eclipse.zest.layouts.dataStructures.InternalNode in project archi by archimatetool.
the class TreeLayoutAlgorithm method computePositions.
/**
* Computes positions for each node in this TreeLayoutAlgorithm by
* referencing the forest that holds those nodes.
*/
private void computePositions(List roots, InternalNode[] entities) {
// No need to do further computation!
if (roots.size() == 0) {
return;
}
int totalLeafCount = 0;
double maxWeight = 0;
for (int i = 0; i < roots.size(); i++) {
InternalNode rootEntity = (InternalNode) roots.get(i);
int rootEntityIndex = indexOfInternalNode(entities, rootEntity);
totalLeafCount = totalLeafCount + getNumberOfLeaves(rootEntity, rootEntityIndex, entities);
maxWeight = Math.max(maxWeight, getMaxiumWeightRecursive(rootEntity, rootEntityIndex, new HashSet(), entities) + 1.0);
}
double width = 1.0 / totalLeafCount;
double height = 1.0 / maxWeight;
int leafCountSoFar = 0;
// TODO: SLOW!
for (int i = 0; i < roots.size(); i++) {
InternalNode rootEntity = (InternalNode) roots.get(i);
int rootEntityIndex = indexOfInternalNode(entities, rootEntity);
computePositionRecursively(rootEntity, rootEntityIndex, leafCountSoFar, width, height, new HashSet(), entities);
leafCountSoFar = leafCountSoFar + getNumberOfLeaves(rootEntity, rootEntityIndex, entities);
}
}
use of org.eclipse.zest.layouts.dataStructures.InternalNode in project archi by archimatetool.
the class TreeLayoutAlgorithm method computePositionRecursively.
/**
* Computes positions recursively until the leaf nodes are reached.
*/
private void computePositionRecursively(InternalNode layoutEntity, int i, int relativePosition, double width, double height, Set seenAlready, InternalNode[] entities) {
if (seenAlready.contains(layoutEntity)) {
return;
}
seenAlready.add(layoutEntity);
double level = getLevel(layoutEntity, i, entities);
int breadth = getNumberOfLeaves(layoutEntity, i, entities);
double absHPosition = relativePosition + breadth / 2.0;
double absVPosition = (level + 0.5);
double posx = absHPosition * width;
double posy = absVPosition * height;
double weight = weights[i];
posy = posy + height * (weight - level);
layoutEntity.setInternalLocation(posx, posy);
int relativeCount = 0;
List children = childrenLists[i];
// TODO: Slow
for (Iterator iter = children.iterator(); iter.hasNext(); ) {
InternalNode childEntity = (InternalNode) iter.next();
int childEntityIndex = indexOfInternalNode(entities, childEntity);
computePositionRecursively(childEntity, childEntityIndex, relativePosition + relativeCount, width, height, seenAlready, entities);
relativeCount = relativeCount + getNumberOfLeaves(childEntity, childEntityIndex, entities);
}
}
Aggregations