Skip to content

Commit

Permalink
[897] Handle Dot style for Bordered Nodes
Browse files Browse the repository at this point in the history
Bug: #897
Signed-off-by: Axel RICHARD <axel.richard@obeo.fr>
  • Loading branch information
AxelRICHARD authored and sbegaudeau committed Dec 20, 2021
1 parent bcc6c04 commit df050fd
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Currently it is not possible to compute different values for width and height.
- [form] Add a tooltip to always make the full label available
- [core] Customize the Spring `ObjectMapper` instead of creating a brand new one from scratch in our `ObjectMapperConfiguration`
- https://github.com/eclipse-sirius/sirius-components/issues/896[#896] [diagram] Allow to make specific changes before and after the layout
- https://github.com/eclipse-sirius/sirius-components/issues/897[#897] [compatibility] The Bordered Node Dot Style is now handled in the compatibility layer

=== Bug fixes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.util.function.Function;

import org.eclipse.sirius.diagram.description.AbstractNodeMapping;
import org.eclipse.sirius.diagram.description.style.DotDescription;
import org.eclipse.sirius.diagram.description.style.FlatContainerStyleDescription;
import org.eclipse.sirius.diagram.description.style.SquareDescription;
import org.eclipse.sirius.viewpoint.description.style.LabelStyleDescription;
Expand Down Expand Up @@ -84,6 +85,17 @@ public Size apply(VariableManager variableManager) {
height = computedHeight * SIZE_FACTOR;
}
size = Size.of(width, height);
} else if (labelStyleDescription instanceof DotDescription) {
int width = -1;
int height = -1;
DotDescription dotDescription = (DotDescription) labelStyleDescription;
Result result = this.interpreter.evaluateExpression(variableManager.getVariables(), dotDescription.getSizeComputationExpression());
int computedSize = result.asInt().getAsInt();
if (computedSize > 0) {
width = computedSize * SIZE_FACTOR;
height = computedSize * SIZE_FACTOR;
}
size = Size.of(width, height);
}
return size;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.eclipse.sirius.diagram.business.api.query.ContainerMappingQuery;
import org.eclipse.sirius.diagram.description.AbstractNodeMapping;
import org.eclipse.sirius.diagram.description.ContainerMapping;
import org.eclipse.sirius.diagram.description.style.DotDescription;
import org.eclipse.sirius.diagram.description.style.FlatContainerStyleDescription;
import org.eclipse.sirius.diagram.description.style.SquareDescription;
import org.eclipse.sirius.diagram.description.style.StylePackage;
Expand Down Expand Up @@ -63,6 +64,9 @@ private INodeStyle getNodeStyle(VariableManager variableManager, LabelStyleDescr
} else if (nodeStyleDescription instanceof SquareDescription) {
SquareDescription squareDescription = (SquareDescription) nodeStyleDescription;
style = this.createRectangularNodeStyle(variableManager, squareDescription);
} else if (nodeStyleDescription instanceof DotDescription) {
DotDescription dotDescription = (DotDescription) nodeStyleDescription;
style = this.createRectangularNodeStyle(variableManager, dotDescription);
} else if (nodeStyleDescription instanceof FlatContainerStyleDescription) {
FlatContainerStyleDescription flatContainerStyleDescription = (FlatContainerStyleDescription) nodeStyleDescription;
if (this.abstractNodeMapping instanceof ContainerMapping && new ContainerMappingQuery((ContainerMapping) this.abstractNodeMapping).isListContainer()) {
Expand Down Expand Up @@ -197,4 +201,27 @@ private RectangularNodeStyle createRectangularNodeStyle(VariableManager variable
// @formatter:on
}

private RectangularNodeStyle createRectangularNodeStyle(VariableManager variableManager, DotDescription dotDescription) {
Map<String, Object> variables = variableManager.getVariables();
ColorDescriptionConverter colorProvider = new ColorDescriptionConverter(this.interpreter, variables);

String color = colorProvider.convert(dotDescription.getBackgroundColor());
String borderColor = colorProvider.convert(dotDescription.getBorderColor());

LineStyle borderStyle = new LineStyleConverter().getStyle(dotDescription.getBorderLineStyle());
int borderRadius = 100;
Result result = this.interpreter.evaluateExpression(variables, dotDescription.getBorderSizeComputationExpression());
int borderSize = result.asInt().getAsInt();

// @formatter:off
return RectangularNodeStyle.newRectangularNodeStyle()
.color(color)
.borderColor(borderColor)
.borderSize(borderSize)
.borderRadius(borderRadius)
.borderStyle(borderStyle)
.build();
// @formatter:on
}

}

0 comments on commit df050fd

Please sign in to comment.