diff --git a/plugins/org.eclipse.elk.alg.layered/src/org/eclipse/elk/alg/layered/ElkLayered.java b/plugins/org.eclipse.elk.alg.layered/src/org/eclipse/elk/alg/layered/ElkLayered.java index 09f486a999..09065c76f4 100644 --- a/plugins/org.eclipse.elk.alg.layered/src/org/eclipse/elk/alg/layered/ElkLayered.java +++ b/plugins/org.eclipse.elk.alg.layered/src/org/eclipse/elk/alg/layered/ElkLayered.java @@ -26,7 +26,6 @@ import org.eclipse.elk.alg.layered.graph.LNode.NodeType; import org.eclipse.elk.alg.layered.graph.LPadding; import org.eclipse.elk.alg.layered.graph.Layer; -import org.eclipse.elk.alg.layered.options.ContentAlignment; import org.eclipse.elk.alg.layered.options.CrossingMinimizationStrategy; import org.eclipse.elk.alg.layered.options.GraphProperties; import org.eclipse.elk.alg.layered.options.GreedySwitchType; @@ -34,6 +33,7 @@ import org.eclipse.elk.alg.layered.options.LayeredOptions; import org.eclipse.elk.core.alg.ILayoutProcessor; import org.eclipse.elk.core.math.KVector; +import org.eclipse.elk.core.options.ContentAlignment; import org.eclipse.elk.core.options.PortSide; import org.eclipse.elk.core.options.SizeConstraint; import org.eclipse.elk.core.options.SizeOptions; diff --git a/plugins/org.eclipse.elk.alg.layered/src/org/eclipse/elk/alg/layered/Layered.melk b/plugins/org.eclipse.elk.alg.layered/src/org/eclipse/elk/alg/layered/Layered.melk index 5dc005b61f..bba9560773 100644 --- a/plugins/org.eclipse.elk.alg.layered/src/org/eclipse/elk/alg/layered/Layered.melk +++ b/plugins/org.eclipse.elk.alg.layered/src/org/eclipse/elk/alg/layered/Layered.melk @@ -134,7 +134,7 @@ algorithm layered(LayeredLayoutProvider) { supports org.eclipse.elk.alg.layered.nodePlacement.linearSegments.deflectionDampening supports org.eclipse.elk.alg.layered.edgeRouting.selfLoopDistribution supports org.eclipse.elk.alg.layered.edgeRouting.selfLoopOrdering - supports contentAlignment + supports org.eclipse.elk.contentAlignment supports org.eclipse.elk.alg.layered.nodePlacement.bk.edgeStraightening supports org.eclipse.elk.alg.layered.compaction.postCompaction.strategy supports org.eclipse.elk.alg.layered.compaction.postCompaction.constraints @@ -841,14 +841,6 @@ group edgeLabels { /* ------------------------ * miscellaneous * ------------------------*/ -advanced option contentAlignment: EnumSet { - label "Content Alignment" - description "Specifies how the content of compound nodes is to be aligned, e.g. top-left." - default = EnumSet.noneOf(ContentAlignment) - targets parents - legacyIds de.cau.cs.kieler.klay.layered.contentAlignment -} - advanced option directionCongruency: DirectionCongruency { label "Direction Congruency" description diff --git a/plugins/org.eclipse.elk.alg.layered/src/org/eclipse/elk/alg/layered/intermediate/HierarchicalNodeResizingProcessor.java b/plugins/org.eclipse.elk.alg.layered/src/org/eclipse/elk/alg/layered/intermediate/HierarchicalNodeResizingProcessor.java index 1d7dc119f8..9829221ea5 100644 --- a/plugins/org.eclipse.elk.alg.layered/src/org/eclipse/elk/alg/layered/intermediate/HierarchicalNodeResizingProcessor.java +++ b/plugins/org.eclipse.elk.alg.layered/src/org/eclipse/elk/alg/layered/intermediate/HierarchicalNodeResizingProcessor.java @@ -18,12 +18,12 @@ import org.eclipse.elk.alg.layered.graph.LPadding; import org.eclipse.elk.alg.layered.graph.LPort; import org.eclipse.elk.alg.layered.graph.Layer; -import org.eclipse.elk.alg.layered.options.ContentAlignment; import org.eclipse.elk.alg.layered.options.GraphProperties; import org.eclipse.elk.alg.layered.options.InternalProperties; import org.eclipse.elk.alg.layered.options.LayeredOptions; import org.eclipse.elk.core.alg.ILayoutProcessor; import org.eclipse.elk.core.math.KVector; +import org.eclipse.elk.core.options.ContentAlignment; import org.eclipse.elk.core.options.PortConstraints; import org.eclipse.elk.core.options.PortSide; import org.eclipse.elk.core.options.SizeConstraint; diff --git a/plugins/org.eclipse.elk.alg.rectpacking/src/org/eclipse/elk/alg/rectpacking/util/BlockRow.java b/plugins/org.eclipse.elk.alg.rectpacking/src/org/eclipse/elk/alg/rectpacking/util/BlockRow.java index 825c0dca83..5cc2d69b50 100644 --- a/plugins/org.eclipse.elk.alg.rectpacking/src/org/eclipse/elk/alg/rectpacking/util/BlockRow.java +++ b/plugins/org.eclipse.elk.alg.rectpacking/src/org/eclipse/elk/alg/rectpacking/util/BlockRow.java @@ -12,6 +12,8 @@ import java.util.ArrayList; import java.util.List; +import org.eclipse.elk.core.math.KVector; +import org.eclipse.elk.core.util.ElkUtil; import org.eclipse.elk.graph.ElkNode; /** @@ -123,11 +125,16 @@ public void expand(final double widthForRow, final double additionalHeightForRow this.height += additionalHeightForRow; this.width = widthForRow; for (ElkNode rect : rects) { + double oldWidth = rect.getWidth(); + double oldHeight = rect.getHeight(); rect.setX(rect.getX() + i * additionalWidthForRect); rect.setY(rect.getY() + index * additionalHeightForRow); rect.setWidth(rect.getWidth() + additionalWidthForRect); rect.setHeight(this.height - nodeNodeSpacing); i++; + double newWidth = rect.getWidth(); + double newHeight = rect.getHeight(); + ElkUtil.translate(rect, new KVector(newWidth, newHeight), new KVector(oldWidth, oldHeight)); } } diff --git a/plugins/org.eclipse.elk.core/src/org/eclipse/elk/core/Core.melk b/plugins/org.eclipse.elk.core/src/org/eclipse/elk/core/Core.melk index 12c3c9563e..057ad67834 100644 --- a/plugins/org.eclipse.elk.core/src/org/eclipse/elk/core/Core.melk +++ b/plugins/org.eclipse.elk.core/src/org/eclipse/elk/core/Core.melk @@ -168,6 +168,13 @@ programmatic option bendPoints: KVectorChain { targets edges legacyIds de.cau.cs.kieler.bendPoints } +advanced option contentAlignment: EnumSet { + label "Content Alignment" + description "Specifies how the content of compound nodes is to be aligned, e.g. top-left." + default = EnumSet.of(ContentAlignment.H_CENTER, ContentAlignment.V_TOP) + targets parents + legacyIds de.cau.cs.kieler.klay.layered.contentAlignment +} advanced option debugMode: boolean { label "Debug Mode" description "Whether additional debug information shall be generated." diff --git a/plugins/org.eclipse.elk.alg.layered/src/org/eclipse/elk/alg/layered/options/ContentAlignment.java b/plugins/org.eclipse.elk.core/src/org/eclipse/elk/core/options/ContentAlignment.java similarity index 98% rename from plugins/org.eclipse.elk.alg.layered/src/org/eclipse/elk/alg/layered/options/ContentAlignment.java rename to plugins/org.eclipse.elk.core/src/org/eclipse/elk/core/options/ContentAlignment.java index 5884ee6a7d..44603132a6 100644 --- a/plugins/org.eclipse.elk.alg.layered/src/org/eclipse/elk/alg/layered/options/ContentAlignment.java +++ b/plugins/org.eclipse.elk.core/src/org/eclipse/elk/core/options/ContentAlignment.java @@ -7,7 +7,7 @@ * * SPDX-License-Identifier: EPL-2.0 *******************************************************************************/ -package org.eclipse.elk.alg.layered.options; +package org.eclipse.elk.core.options; import java.util.EnumSet; diff --git a/plugins/org.eclipse.elk.core/src/org/eclipse/elk/core/util/BoxLayoutProvider.java b/plugins/org.eclipse.elk.core/src/org/eclipse/elk/core/util/BoxLayoutProvider.java index 20a7ebe5fc..6170bade68 100644 --- a/plugins/org.eclipse.elk.core/src/org/eclipse/elk/core/util/BoxLayoutProvider.java +++ b/plugins/org.eclipse.elk.core/src/org/eclipse/elk/core/util/BoxLayoutProvider.java @@ -252,12 +252,15 @@ private KVector placeBoxes(final List sortedBoxes, final double minSpac nextRowIndex = rowIndexIter.next(); } ElkNode box = boxIter.next(); + double oldHeight = box.getHeight(); box.setHeight(rowHeight); + double newHeight = rowHeight; if (boxIter.nextIndex() == nextRowIndex) { double newWidth = broadestRow - xpos - padding.getRight(); double oldWidth = box.getWidth(); box.setWidth(newWidth); - ElkUtil.translate(box, (newWidth - oldWidth) / 2, 0.0); + // Content alignment + ElkUtil.translate(box, new KVector(newWidth, newHeight), new KVector(oldWidth, oldHeight)); } xpos += box.getWidth() + minSpacing; } diff --git a/plugins/org.eclipse.elk.core/src/org/eclipse/elk/core/util/ElkUtil.java b/plugins/org.eclipse.elk.core/src/org/eclipse/elk/core/util/ElkUtil.java index 67b66c9d60..286aebe458 100644 --- a/plugins/org.eclipse.elk.core/src/org/eclipse/elk/core/util/ElkUtil.java +++ b/plugins/org.eclipse.elk.core/src/org/eclipse/elk/core/util/ElkUtil.java @@ -21,6 +21,7 @@ import org.eclipse.elk.core.math.KVector; import org.eclipse.elk.core.math.KVectorChain; +import org.eclipse.elk.core.options.ContentAlignment; import org.eclipse.elk.core.options.CoreOptions; import org.eclipse.elk.core.options.Direction; import org.eclipse.elk.core.options.EdgeLabelPlacement; @@ -601,6 +602,40 @@ public static void translate(final ElkEdgeSection section, final double xoffset, // Translate target point section.setEndLocation(section.getEndX() + xoffset, section.getEndY() + yoffset); } + + /** + * Translates the contents of the given node based on the content alignment property without resizing the node itself. + * + * @param parent The parent node. + * @param newSize The new size. + * @param oldSize The old size. + */ + public static void translate(final ElkNode parent, final KVector newSize, final KVector oldSize) { + Set contentAlignment = + parent.getProperty(CoreOptions.CONTENT_ALIGNMENT); + double xTranslate = 0; + double yTranslate = 0; + + // Horizontal alignment + if (newSize.x > oldSize.x) { + if (contentAlignment.contains(ContentAlignment.H_CENTER)) { + xTranslate = (newSize.x - oldSize.x) / 2f; + } else if (contentAlignment.contains(ContentAlignment.H_RIGHT)) { + xTranslate = newSize.x - oldSize.x; + } + } + + // Vertical alignment + if (newSize.y > oldSize.y) { + if (contentAlignment.contains(ContentAlignment.V_CENTER)) { + yTranslate = (newSize.y - oldSize.y) / 2f; + } else if (contentAlignment.contains(ContentAlignment.V_BOTTOM)) { + yTranslate = newSize.y - oldSize.y; + } + } + + translate(parent, xTranslate, yTranslate); + } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////