use of org.eclipse.zest.layouts.dataStructures.InternalNode in project archi by archimatetool.
the class RadialLayoutAlgorithm method determineCenterPoint.
/**
* Find the center point between the roots
*/
private DisplayIndependentPoint determineCenterPoint(List roots) {
double totalX = 0, totalY = 0;
for (Iterator iterator = roots.iterator(); iterator.hasNext(); ) {
InternalNode entity = (InternalNode) iterator.next();
totalX += entity.getInternalX();
totalY += entity.getInternalY();
}
return new DisplayIndependentPoint(totalX / roots.size(), totalY / roots.size());
}
use of org.eclipse.zest.layouts.dataStructures.InternalNode in project archi by archimatetool.
the class RadialLayoutAlgorithm method computeRadialPositions.
/**
* Take the tree and make it round. This is done by determining the location of each entity in terms
* of its percentage in the tree layout. Then apply that percentage to the radius and distance from
* the center.
*/
protected void computeRadialPositions(InternalNode[] entities, DisplayIndependentRectangle bounds2) {
// TODO TODO TODO
DisplayIndependentRectangle bounds = new DisplayIndependentRectangle(getLayoutBounds(entities, true));
bounds.height = bounds2.height;
bounds.y = bounds2.y;
for (int i = 0; i < entities.length; i++) {
InternalNode entity = entities[i];
double percentTheta = (entity.getInternalX() - bounds.x) / bounds.width;
double distance = (entity.getInternalY() - bounds.y) / bounds.height;
double theta = startDegree + Math.abs(endDegree - startDegree) * percentTheta;
double newX = distance * Math.cos(theta);
double newY = distance * Math.sin(theta);
entity.setInternalLocation(newX, newY);
}
}
use of org.eclipse.zest.layouts.dataStructures.InternalNode in project archi by archimatetool.
the class DirectedGraphLayoutAlgorithm method applyLayoutInternal.
@Override
protected void applyLayoutInternal(InternalNode[] entitiesToLayout, InternalRelationship[] relationshipsToConsider, double boundsX, double boundsY, double boundsWidth, double boundsHeight) {
HashMap mapping = new HashMap(entitiesToLayout.length);
DirectedGraph graph = new DirectedGraph();
for (int i = 0; i < entitiesToLayout.length; i++) {
InternalNode internalNode = entitiesToLayout[i];
Node node = new Node(internalNode);
node.setSize(new Dimension(10, 10));
mapping.put(internalNode, node);
graph.nodes.add(node);
}
for (int i = 0; i < relationshipsToConsider.length; i++) {
InternalRelationship relationship = relationshipsToConsider[i];
Node source = (Node) mapping.get(relationship.getSource());
Node dest = (Node) mapping.get(relationship.getDestination());
Edge edge = new Edge(relationship, source, dest);
graph.edges.add(edge);
}
DirectedGraphLayout directedGraphLayout = new ExtendedDirectedGraphLayout();
directedGraphLayout.visit(graph);
for (Iterator iterator = graph.nodes.iterator(); iterator.hasNext(); ) {
Node node = (Node) iterator.next();
InternalNode internalNode = (InternalNode) node.data;
// For horizontal layout transpose the x and y coordinates
if ((layout_styles & SWT.HORIZONTAL) == SWT.HORIZONTAL) {
internalNode.setInternalLocation(node.y, node.x);
} else {
internalNode.setInternalLocation(node.x, node.y);
}
}
updateLayoutLocations(entitiesToLayout);
}
use of org.eclipse.zest.layouts.dataStructures.InternalNode in project archi by archimatetool.
the class SpringLayoutAlgorithm method convertToUnitCoordinates.
/**
* Converts the position for each node in this SpringLayoutAlgorithm
* to unit coordinates in double precision. The computed positions will be
* still stored in the data repository.
*/
protected void convertToUnitCoordinates(InternalNode[] entitiesToLayout) {
double minX = Double.MAX_VALUE;
double maxX = Double.MIN_VALUE;
double minY = Double.MAX_VALUE;
double maxY = Double.MIN_VALUE;
for (int i = 0; i < entitiesToLayout.length; i++) {
InternalNode layoutEntity = entitiesToLayout[i];
minX = Math.min(minX, layoutEntity.getInternalX());
minY = Math.min(minY, layoutEntity.getInternalY());
maxX = Math.max(maxX, layoutEntity.getInternalX());
maxY = Math.max(maxY, layoutEntity.getInternalY());
}
double spanX = maxX - minX;
double spanY = maxY - minY;
double maxSpan = Math.max(spanX, spanY);
if (maxSpan > EPSILON) {
for (int i = 0; i < entitiesToLayout.length; i++) {
InternalNode layoutEntity = entitiesToLayout[i];
double x = (layoutEntity.getInternalX() - minX) / spanX;
double y = (layoutEntity.getInternalY() - minY) / spanY;
tempLocationsX[i] = x;
tempLocationsY[i] = y;
}
} else {
placeRandomly(entitiesToLayout);
}
}
use of org.eclipse.zest.layouts.dataStructures.InternalNode in project archi by archimatetool.
the class SpringLayoutAlgorithm method checkPreferredLocation.
private void checkPreferredLocation(InternalNode[] entitiesToLayout, DisplayIndependentRectangle realBounds) {
// use 10% for the border - 5% on each side
double borderWidth = Math.min(realBounds.width, realBounds.height) / 10.0;
DisplayIndependentRectangle screenBounds = new DisplayIndependentRectangle(realBounds.x + borderWidth / 2.0, realBounds.y + borderWidth / 2.0, realBounds.width - borderWidth, realBounds.height - borderWidth);
DisplayIndependentRectangle layoutBounds = getLayoutBoundsTemp(entitiesToLayout, false);
for (int i = 0; i < entitiesToLayout.length; i++) {
InternalNode layoutEntity = entitiesToLayout[i];
if (layoutEntity.hasPreferredLocation()) {
convertNodePositionsBack(i, layoutEntity, layoutEntity.getPreferredX(), layoutEntity.getPreferredY(), screenBounds.width, screenBounds.height, layoutBounds);
}
}
}
Aggregations