}
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);
}
}