use of org.eclipse.sirius.components.diagrams.Label in project sirius-components by eclipse-sirius.
the class ELKLayoutedDiagramProvider method getLayoutedNode.
private Node getLayoutedNode(Node node, ElkConnectableShape elkConnectableShape, Map<String, ElkGraphElement> id2ElkGraphElements) {
Size size = Size.of(elkConnectableShape.getWidth(), elkConnectableShape.getHeight());
Position position = Position.at(elkConnectableShape.getX(), elkConnectableShape.getY());
double xOffSet = 0;
if (!node.isBorderNode()) {
// The label is positioned at the center of the node and the front-end will apply a "'text-anchor':
// 'middle'" property.
xOffSet = node.getLabel().getSize().getWidth() / 2;
}
Label label = this.getLayoutedLabel(node.getLabel(), id2ElkGraphElements, xOffSet, 0);
List<Node> childNodes = this.getLayoutedNodes(node.getChildNodes(), id2ElkGraphElements);
List<Node> borderNodes = this.getLayoutedNodes(node.getBorderNodes(), id2ElkGraphElements);
// @formatter:off
return Node.newNode(node).label(label).size(size).position(position).childNodes(childNodes).borderNodes(borderNodes).build();
// @formatter:on
}
use of org.eclipse.sirius.components.diagrams.Label in project sirius-components by eclipse-sirius.
the class ELKLayoutedDiagramProvider method getLayoutedLabel.
private Label getLayoutedLabel(Label label, Map<String, ElkGraphElement> id2ElkGraphElements, double xOffset, double yOffset) {
Label layoutedLabel = label;
var optionalElkBeginLabel = Optional.of(id2ElkGraphElements.get(label.getId().toString())).filter(ElkLabel.class::isInstance).map(ElkLabel.class::cast);
if (optionalElkBeginLabel.isPresent()) {
ElkLabel elkLabel = optionalElkBeginLabel.get();
Size size = Size.of(elkLabel.getWidth(), elkLabel.getHeight());
Position position = Position.at(xOffset + elkLabel.getX(), yOffset + elkLabel.getY());
// @formatter:off
Position alignment = elkLabel.eAdapters().stream().findFirst().filter(AlignmentHolder.class::isInstance).map(AlignmentHolder.class::cast).map(AlignmentHolder::getAlignment).orElse(Position.UNDEFINED);
layoutedLabel = Label.newLabel(label).size(size).position(position).alignment(alignment).build();
// @formatter:on
}
return layoutedLabel;
}
use of org.eclipse.sirius.components.diagrams.Label in project sirius-components by eclipse-sirius.
the class IncrementalLayoutedDiagramProvider method getLayoutedEdge.
private Edge getLayoutedEdge(Edge edge, EdgeLayoutData edgeLayoutData, Map<String, ILayoutData> id2LayoutData) {
Label beginLabel = edge.getBeginLabel();
if (beginLabel != null) {
beginLabel = this.getLayoutedLabel(beginLabel, id2LayoutData);
}
Label centerLabel = edge.getCenterLabel();
if (centerLabel != null) {
centerLabel = this.getLayoutedLabel(centerLabel, id2LayoutData);
}
Label endLabel = edge.getEndLabel();
if (endLabel != null) {
endLabel = this.getLayoutedLabel(endLabel, id2LayoutData);
}
// @formatter:off
return Edge.newEdge(edge).beginLabel(beginLabel).centerLabel(centerLabel).endLabel(endLabel).routingPoints(edgeLayoutData.getRoutingPoints()).sourceAnchorRelativePosition(edgeLayoutData.getSourceAnchorRelativePosition()).targetAnchorRelativePosition(edgeLayoutData.getTargetAnchorRelativePosition()).build();
// @formatter:on
}
use of org.eclipse.sirius.components.diagrams.Label in project sirius-components by eclipse-sirius.
the class NodeComponent method doRender.
private Element doRender(VariableManager nodeVariableManager, String targetObjectId, Optional<Node> optionalPreviousNode) {
NodeDescription nodeDescription = this.props.getNodeDescription();
NodeContainmentKind containmentKind = this.props.getContainmentKind();
String nodeId = optionalPreviousNode.map(Node::getId).orElseGet(() -> this.computeNodeId(targetObjectId));
Optional<Label> optionalPreviousLabel = optionalPreviousNode.map(Node::getLabel);
String type = nodeDescription.getTypeProvider().apply(nodeVariableManager);
String targetObjectKind = nodeDescription.getTargetObjectKindProvider().apply(nodeVariableManager);
String targetObjectLabel = nodeDescription.getTargetObjectLabelProvider().apply(nodeVariableManager);
INodeStyle style = nodeDescription.getStyleProvider().apply(nodeVariableManager);
var borderNodes = this.getBorderNodes(optionalPreviousNode, nodeVariableManager, nodeId);
var childNodes = this.getChildNodes(optionalPreviousNode, nodeVariableManager, nodeId);
LabelDescription labelDescription = nodeDescription.getLabelDescription();
nodeVariableManager.put(LabelDescription.OWNER_ID, nodeId);
LabelType nodeLabelType = LabelType.INSIDE_CENTER;
if (containmentKind == NodeContainmentKind.BORDER_NODE) {
nodeLabelType = LabelType.OUTSIDE;
} else if (NodeType.NODE_IMAGE.equals(type)) {
nodeLabelType = LabelType.OUTSIDE_CENTER;
}
LabelComponentProps labelComponentProps = new LabelComponentProps(nodeVariableManager, labelDescription, optionalPreviousLabel, nodeLabelType.getValue());
Element labelElement = new Element(LabelComponent.class, labelComponentProps);
List<Element> nodeChildren = new ArrayList<>();
nodeChildren.add(labelElement);
nodeChildren.addAll(borderNodes);
nodeChildren.addAll(childNodes);
// @formatter:off
Position position = optionalPreviousNode.map(Node::getPosition).orElse(Position.UNDEFINED);
Size size = this.getSize(optionalPreviousNode, nodeDescription, nodeVariableManager);
Set<CustomizableProperties> customizableProperties = optionalPreviousNode.map(Node::getCustomizedProperties).orElse(Set.of());
NodeElementProps nodeElementProps = NodeElementProps.newNodeElementProps(nodeId).type(type).targetObjectId(targetObjectId).targetObjectKind(targetObjectKind).targetObjectLabel(targetObjectLabel).descriptionId(nodeDescription.getId()).borderNode(containmentKind == NodeContainmentKind.BORDER_NODE).style(style).position(position).size(size).children(nodeChildren).customizableProperties(customizableProperties).build();
// @formatter:on
return new Element(NodeElementProps.TYPE, nodeElementProps);
}
use of org.eclipse.sirius.components.diagrams.Label in project sirius-components by eclipse-sirius.
the class DiagramRendererNodeTests method testSimpleNodeRenderingWithSizeProvider.
@Test
public void testSimpleNodeRenderingWithSizeProvider() {
Function<VariableManager, INodeStyle> styleProvider = variableManager -> {
// @formatter:off
return RectangularNodeStyle.newRectangularNodeStyle().color(// $NON-NLS-1$
"").borderColor(// $NON-NLS-1$
"").borderSize(0).borderStyle(LineStyle.Solid).build();
// @formatter:on
};
Diagram diagram = this.createDiagram(styleProvider, variableManager -> NODE_RECTANGULAR, VariableManager -> Size.of(10, 200), Optional.empty());
assertThat(diagram).isNotNull();
assertThat(diagram.getId()).asString().isNotBlank();
assertThat(diagram.getLabel()).isEqualTo(DIAGRAM_LABEL);
assertThat(diagram.getTargetObjectId()).isNotBlank();
assertThat(diagram.getNodes()).hasSize(1);
assertThat(diagram.getNodes()).extracting(Node::getTargetObjectId).noneMatch(String::isBlank);
assertThat(diagram.getNodes()).extracting(Node::getDescriptionId).noneMatch(t -> t.toString().isBlank());
assertThat(diagram.getNodes()).extracting(Node::getType).noneMatch(String::isBlank);
assertThat(diagram.getNodes()).extracting(Node::getType).allMatch(t -> NODE_RECTANGULAR.equals(t));
assertThat(diagram.getNodes()).extracting(Node::getBorderNodes).allMatch(List::isEmpty);
assertThat(diagram.getNodes()).extracting(Node::getStyle).allMatch(s -> s instanceof RectangularNodeStyle);
assertThat(diagram.getNodes()).extracting(Node::getSize).allMatch(s -> s.getHeight() == 200 && s.getWidth() == 10);
assertThat(diagram.getNodes()).extracting(Node::getLabel).extracting(Label::getId).allMatch(id -> UUID.nameUUIDFromBytes(LABEL_ID.getBytes()).toString().equals(id));
assertThat(diagram.getNodes()).extracting(Node::getLabel).extracting(Label::getText).allMatch(text -> LABEL_TEXT.equals(text));
assertThat(diagram.getNodes()).extracting(Node::getLabel).extracting(Label::getStyle).extracting(LabelStyle::getColor).allMatch(color -> LABEL_COLOR.equals(color));
assertThat(diagram.getNodes()).extracting(Node::getLabel).extracting(Label::getStyle).extracting(LabelStyle::getFontSize).allMatch(size -> LABEL_FONT_SIZE == size);
assertThat(diagram.getNodes()).extracting(Node::getLabel).extracting(Label::getStyle).extracting(LabelStyle::isBold).allMatch(bold -> bold);
assertThat(diagram.getNodes()).extracting(Node::getLabel).extracting(Label::getStyle).extracting(LabelStyle::isItalic).allMatch(italic -> italic);
assertThat(diagram.getNodes()).extracting(Node::getLabel).extracting(Label::getStyle).extracting(LabelStyle::isUnderline).allMatch(underline -> underline);
assertThat(diagram.getNodes()).extracting(Node::getLabel).extracting(Label::getStyle).extracting(LabelStyle::isStrikeThrough).allMatch(strikeThrough -> strikeThrough);
}
Aggregations