Search in sources :

Example 11 with Label

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
}
Also used : Position(org.eclipse.sirius.components.diagrams.Position) Size(org.eclipse.sirius.components.diagrams.Size) Node(org.eclipse.sirius.components.diagrams.Node) ElkNode(org.eclipse.elk.graph.ElkNode) ElkLabel(org.eclipse.elk.graph.ElkLabel) Label(org.eclipse.sirius.components.diagrams.Label)

Example 12 with Label

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;
}
Also used : ElkLabel(org.eclipse.elk.graph.ElkLabel) Position(org.eclipse.sirius.components.diagrams.Position) Size(org.eclipse.sirius.components.diagrams.Size) ElkLabel(org.eclipse.elk.graph.ElkLabel) Label(org.eclipse.sirius.components.diagrams.Label)

Example 13 with Label

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
}
Also used : Label(org.eclipse.sirius.components.diagrams.Label)

Example 14 with Label

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);
}
Also used : NodeElementProps(org.eclipse.sirius.components.diagrams.elements.NodeElementProps) Position(org.eclipse.sirius.components.diagrams.Position) Size(org.eclipse.sirius.components.diagrams.Size) Node(org.eclipse.sirius.components.diagrams.Node) Element(org.eclipse.sirius.components.representations.Element) Label(org.eclipse.sirius.components.diagrams.Label) ArrayList(java.util.ArrayList) CustomizableProperties(org.eclipse.sirius.components.diagrams.CustomizableProperties) NodeDescription(org.eclipse.sirius.components.diagrams.description.NodeDescription) LabelDescription(org.eclipse.sirius.components.diagrams.description.LabelDescription) INodeStyle(org.eclipse.sirius.components.diagrams.INodeStyle)

Example 15 with Label

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);
}
Also used : VariableManager(org.eclipse.sirius.components.representations.VariableManager) LabelDescription(org.eclipse.sirius.components.diagrams.description.LabelDescription) Node(org.eclipse.sirius.components.diagrams.Node) Size(org.eclipse.sirius.components.diagrams.Size) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) DiagramDescription(org.eclipse.sirius.components.diagrams.description.DiagramDescription) INodeStyle(org.eclipse.sirius.components.diagrams.INodeStyle) Function(java.util.function.Function) NodeDescription(org.eclipse.sirius.components.diagrams.description.NodeDescription) ArrayList(java.util.ArrayList) RectangularNodeStyle(org.eclipse.sirius.components.diagrams.RectangularNodeStyle) Diagram(org.eclipse.sirius.components.diagrams.Diagram) LineStyle(org.eclipse.sirius.components.diagrams.LineStyle) Label(org.eclipse.sirius.components.diagrams.Label) LabelStyle(org.eclipse.sirius.components.diagrams.LabelStyle) Failure(org.eclipse.sirius.components.representations.Failure) ImageNodeStyle(org.eclipse.sirius.components.diagrams.ImageNodeStyle) Success(org.eclipse.sirius.components.representations.Success) Set(java.util.Set) LabelStyleDescription(org.eclipse.sirius.components.diagrams.description.LabelStyleDescription) UUID(java.util.UUID) CustomizableProperties(org.eclipse.sirius.components.diagrams.CustomizableProperties) Element(org.eclipse.sirius.components.representations.Element) Test(org.junit.jupiter.api.Test) List(java.util.List) DiagramComponentProps(org.eclipse.sirius.components.diagrams.components.DiagramComponentProps) Optional(java.util.Optional) DiagramComponent(org.eclipse.sirius.components.diagrams.components.DiagramComponent) VariableManager(org.eclipse.sirius.components.representations.VariableManager) Node(org.eclipse.sirius.components.diagrams.Node) INodeStyle(org.eclipse.sirius.components.diagrams.INodeStyle) Label(org.eclipse.sirius.components.diagrams.Label) RectangularNodeStyle(org.eclipse.sirius.components.diagrams.RectangularNodeStyle) ArrayList(java.util.ArrayList) List(java.util.List) Diagram(org.eclipse.sirius.components.diagrams.Diagram) Test(org.junit.jupiter.api.Test)

Aggregations

Label (org.eclipse.sirius.components.diagrams.Label)19 Size (org.eclipse.sirius.components.diagrams.Size)11 Node (org.eclipse.sirius.components.diagrams.Node)10 Position (org.eclipse.sirius.components.diagrams.Position)10 ArrayList (java.util.ArrayList)8 List (java.util.List)7 UUID (java.util.UUID)7 CustomizableProperties (org.eclipse.sirius.components.diagrams.CustomizableProperties)7 INodeStyle (org.eclipse.sirius.components.diagrams.INodeStyle)7 LabelDescription (org.eclipse.sirius.components.diagrams.description.LabelDescription)7 Optional (java.util.Optional)6 NodeDescription (org.eclipse.sirius.components.diagrams.description.NodeDescription)6 Element (org.eclipse.sirius.components.representations.Element)6 VariableManager (org.eclipse.sirius.components.representations.VariableManager)6 Set (java.util.Set)5 ImageNodeStyle (org.eclipse.sirius.components.diagrams.ImageNodeStyle)5 LabelStyle (org.eclipse.sirius.components.diagrams.LabelStyle)5 LineStyle (org.eclipse.sirius.components.diagrams.LineStyle)5 RectangularNodeStyle (org.eclipse.sirius.components.diagrams.RectangularNodeStyle)5 DiagramDescription (org.eclipse.sirius.components.diagrams.description.DiagramDescription)5