use of org.eclipse.elk.graph.ElkNode in project elk by eclipse.
the class BlockRow method updateRow.
/**
* Updates the coordinates of all rectangles and the height and width of the row.
*/
public void updateRow() {
double width = 0;
double height = 0;
for (ElkNode rect : rects) {
rect.setX(x + width);
rect.setY(this.y);
width += rect.getWidth() + nodeNodeSpacing;
height = Math.max(height, rect.getHeight() + nodeNodeSpacing);
}
this.width = width - nodeNodeSpacing;
this.height = height - nodeNodeSpacing;
}
use of org.eclipse.elk.graph.ElkNode in project elk by eclipse.
the class AnnulusWedgeCompaction method compact.
@Override
public void compact(final ElkNode graph) {
// Get values of the graph
root = graph.getProperty(InternalProperties.ROOT_NODE);
setRoot(root);
this.sorter = graph.getProperty(RadialOptions.SORTER).create();
Integer stepSize = graph.getProperty(RadialOptions.COMPACTION_STEP_SIZE);
if (stepSize != null) {
setCompactionStep(stepSize);
}
Double spacing = graph.getProperty(CoreOptions.SPACING_NODE_NODE);
setSpacing(spacing);
// Calculate the first level nodes
List<ElkNode> successors = RadialUtil.getSuccessors(root);
if (sorter != null) {
sorter.sort(successors);
}
constructContour(successors);
// contract each wedge
List<ElkNode> rootList = Arrays.asList(new ElkNode[] { root });
// do it two times to assure each node is compacted as much as possible
for (int k = 0; k < 2; k++) {
for (int i = 0; i < successors.size(); i++) {
List<ElkNode> nodeAsList = Arrays.asList(new ElkNode[] { successors.get(i) });
ElkNode rightParent = i < successors.size() - 1 ? successors.get(i + 1) : successors.get(0);
ElkNode leftParent = i == 0 ? successors.get(successors.size() - 1) : successors.get(i - 1);
contractWedge(successors.get(i), rootList, leftParent, rightParent, nodeAsList);
}
}
}
use of org.eclipse.elk.graph.ElkNode in project elk by eclipse.
the class AnnulusWedgeCompaction method constructContour.
/**
* Calculate the left and right contour of each node from the first layer.
*
* @param nodes
* The list of first layer nodes.
*/
private void constructContour(final List<ElkNode> nodes) {
for (ElkNode node : nodes) {
leftContour.put(node, node);
rightContour.put(node, node);
List<ElkNode> successors = RadialUtil.getSuccessors(node);
if (!successors.isEmpty()) {
if (sorter != null) {
sorter.sort(successors);
}
leftContour.put(node, successors.get(0));
rightContour.put(node, successors.get(successors.size() - 1));
while (!RadialUtil.getNextLevelNodes(successors).isEmpty()) {
successors = RadialUtil.getNextLevelNodes(successors);
if (sorter != null) {
sorter.sort(successors);
}
leftContour.put(node, successors.get(0));
rightContour.put(node, successors.get(successors.size() - 1));
}
}
}
}
use of org.eclipse.elk.graph.ElkNode in project elk by eclipse.
the class RadialCompaction method calculateRadius.
/**
* Calculate the radius by help of a node.
*
* @param node
* A node of the radius which will be determined.
* @return the radius the given node is placed on.
*/
private double calculateRadius(final ElkNode node) {
double xPos = node.getX();
double yPos = node.getY();
ElkNode root = getRoot();
double rootX = root.getX();
double rootY = root.getY();
double vectorX = xPos - rootX;
double vectorY = yPos - rootY;
double radius = Math.sqrt(vectorX * vectorX + vectorY * vectorY);
return radius;
}
use of org.eclipse.elk.graph.ElkNode in project elk by eclipse.
the class EdgeLengthOptimization method evaluate.
/**
* This evaluation method calculates the sum of the length of each outgoing edge from the root node.
*/
@Override
public double evaluate(final ElkNode root) {
double edgeLength = 0;
for (ElkEdge edge : ElkGraphUtil.allOutgoingEdges(root)) {
ElkNode target = ElkGraphUtil.connectableShapeToNode(edge.getTargets().get(0));
double targetX = target.getX() + target.getWidth() / 2;
double targetY = target.getY() + target.getHeight() / 2;
double rootX = root.getX() + root.getWidth() / 2;
double rootY = root.getY() + root.getHeight() / 2;
// Clipping
KVector vector = new KVector();
vector.x = targetX - rootX;
vector.y = targetY - rootY;
KVector sourceClip = new KVector(vector.x, vector.y);
ElkMath.clipVector(sourceClip, root.getWidth(), root.getHeight());
vector.x -= sourceClip.x;
vector.y -= sourceClip.y;
rootX = targetX - vector.x;
rootY = targetY - vector.y;
KVector targetClip = new KVector(vector.x, vector.y);
ElkMath.clipVector(targetClip, target.getWidth(), target.getHeight());
vector.x -= targetClip.x;
vector.y -= targetClip.y;
targetX = rootX + vector.x;
targetY = rootY + vector.y;
double vectorX = targetX - rootX;
double vectorY = targetY - rootY;
edgeLength += Math.sqrt(vectorX * vectorX + vectorY * vectorY);
}
return edgeLength;
}
Aggregations