Skip to content

Commit

Permalink
[1741] Fix ELK border node placement not taken into account anymore
Browse files Browse the repository at this point in the history
Bug: eclipse-sirius#1741
Signed-off-by: Axel RICHARD <axel.richard@obeo.fr>
  • Loading branch information
AxelRICHARD authored and sbegaudeau committed Feb 22, 2023
1 parent 85c2903 commit 3312e9f
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ It was not actually used, as tools have long been found in `DiagramDescription.g
- https://github.com/eclipse-sirius/sirius-components/issues/1686[#1686] [diagram] Fix SVG export of the wrapped labels
- https://github.com/eclipse-sirius/sirius-components/issues/1692[#1692] [core] JPEG images where previously ignored if using a `.jpg` extension instead of `.jpeg`.
They are now correctly supported
- https://github.com/eclipse-sirius/sirius-components/issues/1741[#1741] [diagram] Border node placement specified with ELK configuration not taken into account anymore

=== New Features

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,12 @@ private void convertNode(Node node, ElkNode parent, Map<String, ElkConnectableSh

TextBounds textBounds = null;
Label label = node.getLabel();
String labelType = this.elkPropertiesService.getNodeLabelType(node, layoutConfigurator);
String labelType;
if (node.isBorderNode()) {
labelType = this.elkPropertiesService.getBorderNodeLabelType(node, layoutConfigurator);
} else {
labelType = this.elkPropertiesService.getNodeLabelType(node, layoutConfigurator);
}
if (labelType.startsWith("label:inside-v")) {
double maxPadding = this.elkPropertiesService.getMaxPadding(node, layoutConfigurator);
textBounds = this.textBoundsService.getAutoWrapBounds(label, node.getSize().getWidth() - maxPadding * 2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,12 @@ private Label getNodeLayoutedLabel(Node node, Map<String, ElkGraphElement> id2El
ElkLabel elkLabel = optionalElkLabel.get();

Size size = Size.of(elkLabel.getWidth(), elkLabel.getHeight());
String nodeLabelType = this.elkPropertiesService.getNodeLabelType(node, layoutConfigurator);
String nodeLabelType;
if (node.isBorderNode()) {
nodeLabelType = this.elkPropertiesService.getBorderNodeLabelType(node, layoutConfigurator);
} else {
nodeLabelType = this.elkPropertiesService.getNodeLabelType(node, layoutConfigurator);
}

// @formatter:off
Position position = Optional.of(elkLabel.getParent())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.eclipse.elk.core.math.ElkPadding;
import org.eclipse.elk.core.options.CoreOptions;
import org.eclipse.elk.core.options.NodeLabelPlacement;
import org.eclipse.elk.core.options.PortLabelPlacement;
import org.eclipse.sirius.components.diagrams.INodeStyle;
import org.eclipse.sirius.components.diagrams.Node;
import org.eclipse.sirius.components.diagrams.NodeType;
Expand Down Expand Up @@ -65,6 +66,19 @@ public String getNodeLabelType(Node node, ISiriusWebLayoutConfigurator layoutCon
return labelType;
}

public String getBorderNodeLabelType(Node node, ISiriusWebLayoutConfigurator layoutConfigurator) {
String labelType = "label:";
String nodeType = node.getType();
EnumSet<PortLabelPlacement> portLabelPlacementSet = layoutConfigurator.configureByType(nodeType).getProperty(CoreOptions.PORT_LABELS_PLACEMENT);
if (portLabelPlacementSet.contains(PortLabelPlacement.OUTSIDE)) {
labelType += "outside";
} else {
labelType += "inside";
}

return labelType;
}

public boolean hasHeader(Node node) {
INodeStyle nodeStyle = node.getStyle();
if (nodeStyle instanceof RectangularNodeStyle rectangularNodeStyle) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,12 @@ private LabelLayoutData convertNodeLabel(Node node, Map<String, ILayoutData> id2
id2LayoutData.put(id, layoutData);

layoutData.setPosition(label.getPosition());
String labelType = this.elkPropertiesService.getNodeLabelType(node, layoutConfigurator);
String labelType;
if (node.isBorderNode()) {
labelType = this.elkPropertiesService.getBorderNodeLabelType(node, layoutConfigurator);
} else {
labelType = this.elkPropertiesService.getNodeLabelType(node, layoutConfigurator);
}
layoutData.setLabelType(labelType);

TextBounds textBounds = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.eclipse.sirius.components.diagrams.Position;
import org.eclipse.sirius.components.diagrams.Size;
import org.eclipse.sirius.components.diagrams.TextBounds;
import org.eclipse.sirius.components.diagrams.components.LabelType;
import org.eclipse.sirius.components.diagrams.events.IDiagramEvent;
import org.eclipse.sirius.components.diagrams.events.MoveEvent;
import org.eclipse.sirius.components.diagrams.events.ResizeEvent;
Expand Down Expand Up @@ -99,6 +100,7 @@ public void testSnap() {
private void checkBorderNodeLabel(LabelLayoutData labelLayoutData, Position borderNodeLabelTextPosition, TextBounds borderNodeLabelTextBounds) {
assertThat(labelLayoutData.getPosition()).isEqualTo(borderNodeLabelTextPosition);
assertThat(labelLayoutData.getTextBounds()).isEqualTo(borderNodeLabelTextBounds);
assertThat(labelLayoutData.getLabelType()).isEqualTo(LabelType.OUTSIDE.getValue());
}

@Test
Expand All @@ -108,7 +110,7 @@ public void testBorderNodeCreationEvent() {
List<NodeLayoutData> borderNodes = initializeDiagram.getChildrenNodes().get(0).getBorderNodes();

// add a border node with an non positioned label
LabelLayoutData labelLayoutData = this.createLabelLayoutData(Position.at(-1, -1), "any", BORDER_NODE_LABEL_TEXT_BOUNDS);
LabelLayoutData labelLayoutData = this.createLabelLayoutData(Position.at(-1, -1), "label:outside", BORDER_NODE_LABEL_TEXT_BOUNDS);
borderNodes.add(this.createBorderNodeLayoutData(BORDER_NODE_LABEL_TEXT_POSITION, DEFAULT_BORDER_NODE_SIZE, initializeDiagram, NodeType.NODE_RECTANGLE, labelLayoutData));

ImageSizeProvider imageSizeProvider = new ImageSizeProvider();
Expand Down Expand Up @@ -387,7 +389,7 @@ private NodeLayoutData createBorderNodeLayoutData(Position position, Size size,

private NodeLayoutData createBorderNodeLayoutData(Position position, Size size, IContainerLayoutData parent, String nodeType) {
NodeLayoutData nodeLayoutData = this.createBorderNodeLayoutData(position, size, parent, nodeType,
this.createLabelLayoutData(BORDER_NODE_LABEL_TEXT_POSITION, "any", BORDER_NODE_LABEL_TEXT_BOUNDS));
this.createLabelLayoutData(BORDER_NODE_LABEL_TEXT_POSITION, "label:outside", BORDER_NODE_LABEL_TEXT_BOUNDS));
return nodeLayoutData;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import org.assertj.core.data.Offset;
import org.eclipse.elk.alg.layered.options.LayeredOptions;
import org.eclipse.elk.core.data.LayoutMetaDataService;
import org.eclipse.elk.core.options.CoreOptions;
import org.eclipse.elk.core.options.PortLabelPlacement;
import org.eclipse.elk.graph.ElkEdge;
import org.eclipse.elk.graph.ElkGraphElement;
import org.eclipse.elk.graph.ElkLabel;
Expand Down Expand Up @@ -243,6 +245,7 @@ public void testDiagramOneNodeAndOneBorderNode() {

ElkPort elkPort = elkNode.getPorts().get(0);
assertThat(elkPort.getIdentifier()).isEqualTo(borderNode.getId().toString());
assertThat(elkPort.getLabels().get(0).getProperty(CoreOptions.PORT_LABELS_PLACEMENT)).isEqualTo(PortLabelPlacement.outside());

imageSizeProvider.dispose();
}
Expand Down

0 comments on commit 3312e9f

Please sign in to comment.