Skip to content

Commit

Permalink
Added content aligment for rectpacking and box.
Browse files Browse the repository at this point in the history
Signed-off-by: Soeren Domroes <[email protected]>
  • Loading branch information
soerendomroes committed Mar 31, 2020
1 parent c47e53e commit f748dc3
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@
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;
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.PortSide;
import org.eclipse.elk.core.options.SizeConstraint;
import org.eclipse.elk.core.options.SizeOptions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -841,14 +841,6 @@ group edgeLabels {
/* ------------------------
* miscellaneous
* ------------------------*/
advanced option contentAlignment: EnumSet<ContentAlignment> {
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,13 @@ programmatic option bendPoints: KVectorChain {
targets edges
legacyIds de.cau.cs.kieler.bendPoints
}
advanced option contentAlignment: EnumSet<ContentAlignment> {
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."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,12 +252,15 @@ private KVector placeBoxes(final List<ElkNode> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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> 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);
}


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit f748dc3

Please sign in to comment.