use of org.eclipse.elk.core.math.KVector in project elk by eclipse.
the class ElkLayered method resizeGraph.
// //////////////////////////////////////////////////////////////////////////////
// Graph Postprocessing (Size and External Ports)
/**
* Sets the size of the given graph such that size constraints are adhered to.
* Furthermore, the border spacing is added to the graph size and the graph offset.
* Afterwards, the border spacing property is reset to 0.
*
* <p>Major parts of this method are adapted from
* {@link ElkUtil#resizeNode(org.eclipse.elk.graph.ElkNode, double, double, boolean, boolean)}.</p>
*
* <p>Note: This method doesn't care about labels of compound nodes since those labels are not
* attached to the graph.</p>
*
* @param lgraph the graph to resize.
*/
private void resizeGraph(final LGraph lgraph) {
Set<SizeConstraint> sizeConstraint = lgraph.getProperty(LayeredOptions.NODE_SIZE_CONSTRAINTS);
Set<SizeOptions> sizeOptions = lgraph.getProperty(LayeredOptions.NODE_SIZE_OPTIONS);
KVector calculatedSize = lgraph.getActualSize();
KVector adjustedSize = new KVector(calculatedSize);
// calculate the new size
if (sizeConstraint.contains(SizeConstraint.MINIMUM_SIZE)) {
KVector minSize = lgraph.getProperty(LayeredOptions.NODE_SIZE_MINIMUM);
// if minimum width or height are not set, maybe default to default values
if (sizeOptions.contains(SizeOptions.DEFAULT_MINIMUM_SIZE)) {
if (minSize.x <= 0) {
minSize.x = ElkUtil.DEFAULT_MIN_WIDTH;
}
if (minSize.y <= 0) {
minSize.y = ElkUtil.DEFAULT_MIN_HEIGHT;
}
}
// apply new size including border spacing
adjustedSize.x = Math.max(calculatedSize.x, minSize.x);
adjustedSize.y = Math.max(calculatedSize.y, minSize.y);
}
resizeGraphNoReallyIMeanIt(lgraph, calculatedSize, adjustedSize);
}
use of org.eclipse.elk.core.math.KVector in project elk by eclipse.
the class InteractiveLayeredGraphVisitor method setCoordinatesOrthogonalToLayoutDirection.
/**
* Sets the positions of the nodes in their layer.
*
* @param nodesOfLayer
* The list containing nodes that are in the same layer.
* @param direction
* The layout direction.
*/
private void setCoordinatesOrthogonalToLayoutDirection(final List<ElkNode> nodesOfLayer, final int layerId, final Direction direction) {
// Separate nodes with and without position constraints.
List<ElkNode> nodesWithPositionConstraint = new ArrayList<ElkNode>();
List<ElkNode> nodes = new ArrayList<ElkNode>();
for (ElkNode node : nodesOfLayer) {
if (node.getProperty(LayeredOptions.CROSSING_MINIMIZATION_POSITION_CHOICE_CONSTRAINT) != -1) {
nodesWithPositionConstraint.add(node);
} else {
nodes.add(node);
}
}
// Determine the order of the nodes.
sortNodesInLayer(nodesWithPositionConstraint, nodes, direction);
// Add the nodes with position constraint at the desired position in their layer.
for (ElkNode node : nodesWithPositionConstraint) {
int pos = node.getProperty(LayeredOptions.CROSSING_MINIMIZATION_POSITION_CHOICE_CONSTRAINT);
if (pos < nodes.size()) {
nodes.add(pos, node);
} else {
nodes.add(node);
}
}
// Set the y/x positions according to the order of the nodes.
switch(direction) {
case UNDEFINED:
case RIGHT:
case LEFT:
double yPos = nodes.get(0).getY();
for (ElkNode node : nodes) {
node.setProperty(LayeredOptions.POSITION, new KVector(node.getX(), yPos));
yPos += node.getHeight() + PSEUDO_POSITION_SPACING;
}
break;
case DOWN:
case UP:
double xPos = nodes.get(0).getX() + 2 * layerId * PSEUDO_POSITION_SPACING;
for (ElkNode node : nodes) {
node.setProperty(LayeredOptions.POSITION, new KVector(xPos, node.getY()));
xPos += node.getWidth() + PSEUDO_POSITION_SPACING;
}
break;
}
}
use of org.eclipse.elk.core.math.KVector in project elk by eclipse.
the class JsonDebugUtil method calculateGraphSize.
/**
* Calculate the overall size of the given graph. Returns a {@link KVectorChain} with two
* elements where the first one represents the minimal coordinates used by any node, edge or
* port contained in the graph and the second one represents the maximal coordinates.
*
* @param lgraph
* the graph to calculate the size for.
* @return a {@link KVectorChain} with two elements, the minimal and the maximal coordinates.
*/
private static KVectorChain calculateGraphSize(final LGraph lgraph) {
KVector min = new KVector();
KVector max = new KVector();
for (LNode node : lgraph.getLayerlessNodes()) {
calculateMinMaxPositions(min, max, node);
}
for (Layer layer : lgraph) {
for (LNode node : layer) {
calculateMinMaxPositions(min, max, node);
}
}
max.x -= min.x;
max.y -= min.y;
return new KVectorChain(min, max);
}
use of org.eclipse.elk.core.math.KVector in project elk by eclipse.
the class JsonDebugUtil method calculateMinMaxPositions.
/**
* Inspects the given node, its outgoing edges and its ports for minimal and maximal coordinates
* and adjusts the given vectors {@code min} and {@code max} if necessary.
*
* @param min
* the minimal coordinates used by the graph.
* @param max
* the maximal coordinates used by the graph.
* @param node
* the current node to inspect.
*/
private static void calculateMinMaxPositions(final KVector min, final KVector max, final LNode node) {
min.x = Math.min(min.x, node.getPosition().x - node.getMargin().left);
max.x = Math.max(max.x, node.getPosition().x + node.getSize().x + node.getMargin().right);
min.y = Math.min(min.y, node.getPosition().y - node.getMargin().top);
max.y = Math.max(max.y, node.getPosition().y + node.getSize().y + node.getMargin().bottom);
for (LPort port : node.getPorts()) {
min.x = Math.min(min.x, node.getPosition().x + port.getPosition().x - port.getMargin().left);
max.x = Math.max(max.x, node.getPosition().x + port.getPosition().x + port.getSize().x + port.getMargin().right);
min.y = Math.min(min.y, node.getPosition().y + port.getPosition().y - port.getMargin().top);
max.y = Math.max(max.y, node.getPosition().y + port.getPosition().y + port.getSize().y + port.getMargin().bottom);
}
for (LEdge edge : node.getOutgoingEdges()) {
for (KVector bendpoint : edge.getBendPoints()) {
min.x = Math.min(min.x, bendpoint.x);
max.x = Math.max(max.x, bendpoint.x);
min.y = Math.min(min.y, bendpoint.y);
max.y = Math.max(max.y, bendpoint.y);
}
}
}
use of org.eclipse.elk.core.math.KVector in project elk by eclipse.
the class JsonDebugUtil method writeBendPoints.
/**
* Writes the given bendpoints as JSON formatted string to the given writer.
*
* @param writer
* the writer to write to.
* @param bendPoints
* the bendpoints to write.
* @param indentation
* the indentation level to use.
* @param offset
* the combined offset of the containing LGraph.
*/
private static void writeBendPoints(final StringWriter writer, final KVectorChain bendPoints, final int indentation, final KVector offset) {
String indent0 = Strings.repeat(INDENT, indentation);
String indent1 = Strings.repeat(INDENT, indentation + 1);
writer.write(indent0 + "\"bendPoints\": [");
Iterator<KVector> pointsIterator = bendPoints.iterator();
while (pointsIterator.hasNext()) {
KVector point = new KVector(pointsIterator.next()).add(offset);
writer.write("\n" + indent1 + "{ \"x\": " + point.x + ", \"y\": " + point.y + "}");
if (pointsIterator.hasNext()) {
writer.write(",");
}
}
writer.write("\n" + indent0 + "]");
}
Aggregations