Search in sources :

Example 21 with ElkLabel

use of org.eclipse.elk.graph.ElkLabel in project elk by eclipse.

the class FixedLayoutProvider method processEdge.

/**
 * Process an edge and its labels.
 *
 * @param edge an edge
 * @param edgeRouting the global edge routing setting
 */
private KVector processEdge(final ElkEdge edge, final EdgeRouting edgeRouting) {
    // MIGRATE Does this properly support hyperedges?
    ElkNode sourceParent = ElkGraphUtil.connectableShapeToNode(edge.getSources().get(0)).getParent();
    ElkNode targetParent = ElkGraphUtil.connectableShapeToNode(edge.getTargets().get(0)).getParent();
    boolean sameHierarchy = sourceParent == targetParent;
    KVector maxv = new KVector();
    KVectorChain bendPoints = edge.getProperty(FixedLayouterOptions.BEND_POINTS);
    // we need at least two bend points, since the source point and target point must be included
    if (bendPoints != null && bendPoints.size() >= 2) {
        if (edge.getSections().isEmpty()) {
            // We need an edge section to apply the bend points to
            ElkEdgeSection edgeSection = ElkGraphFactory.eINSTANCE.createElkEdgeSection();
            edge.getSections().add(edgeSection);
        } else if (edge.getSections().size() > 1) {
            // We can only apply bend points to a single edge section, so throw away all except for the last one
            ListIterator<ElkEdgeSection> sections = edge.getSections().listIterator();
            while (sections.hasNext()) {
                sections.remove();
            }
        }
        ElkUtil.applyVectorChain(bendPoints, edge.getSections().get(0));
    }
    // determine maximal coordinates
    if (sameHierarchy) {
        for (ElkEdgeSection edgeSection : edge.getSections()) {
            for (ElkBendPoint point : edgeSection.getBendPoints()) {
                maxv.x = Math.max(maxv.x, point.getX());
                maxv.y = Math.max(maxv.y, point.getY());
            }
        }
    }
    // set the fixed position of the edge labels, or leave them as they are
    for (ElkLabel label : edge.getLabels()) {
        KVector pos = label.getProperty(FixedLayouterOptions.POSITION);
        if (pos != null) {
            label.setLocation(pos.x, pos.y);
        }
        if (sameHierarchy) {
            maxv.x = Math.max(maxv.x, label.getX() + label.getWidth());
            maxv.y = Math.max(maxv.y, label.getY() + label.getHeight());
        }
    }
    return maxv;
}
Also used : ElkNode(org.eclipse.elk.graph.ElkNode) ElkLabel(org.eclipse.elk.graph.ElkLabel) KVectorChain(org.eclipse.elk.core.math.KVectorChain) ElkBendPoint(org.eclipse.elk.graph.ElkBendPoint) KVector(org.eclipse.elk.core.math.KVector) ListIterator(java.util.ListIterator) ElkEdgeSection(org.eclipse.elk.graph.ElkEdgeSection)

Example 22 with ElkLabel

use of org.eclipse.elk.graph.ElkLabel in project elk by eclipse.

the class FixedLayoutProvider method layout.

@Override
public void layout(final ElkNode layoutNode, final IElkProgressMonitor progressMonitor) {
    progressMonitor.begin("Fixed Layout", 1);
    EdgeRouting edgeRouting = layoutNode.getProperty(CoreOptions.EDGE_ROUTING);
    double maxx = 0;
    double maxy = 0;
    for (ElkNode node : layoutNode.getChildren()) {
        // set the fixed position of the node, or leave it as it is
        KVector pos = node.getProperty(FixedLayouterOptions.POSITION);
        if (pos != null) {
            node.setLocation(pos.x, pos.y);
            // set the fixed size of the node
            if (node.getProperty(FixedLayouterOptions.NODE_SIZE_CONSTRAINTS).contains(SizeConstraint.MINIMUM_SIZE)) {
                KVector minSize = node.getProperty(FixedLayouterOptions.NODE_SIZE_MINIMUM);
                if (minSize.x > 0 && minSize.y > 0) {
                    ElkUtil.resizeNode(node, minSize.x, minSize.y, true, true);
                }
            }
        }
        maxx = Math.max(maxx, node.getX() + node.getWidth());
        maxy = Math.max(maxy, node.getY() + node.getHeight());
        // set the fixed position of the node labels, or leave them as they are
        for (ElkLabel label : node.getLabels()) {
            pos = label.getProperty(FixedLayouterOptions.POSITION);
            if (pos != null) {
                label.setLocation(pos.x, pos.y);
            }
            maxx = Math.max(maxx, node.getX() + label.getX() + label.getWidth());
            maxy = Math.max(maxy, node.getY() + label.getY() + label.getHeight());
        }
        // set the fixed position of the ports, or leave them as they are
        for (ElkPort port : node.getPorts()) {
            pos = port.getProperty(FixedLayouterOptions.POSITION);
            if (pos != null) {
                port.setLocation(pos.x, pos.y);
            }
            double portx = node.getX() + port.getX();
            double porty = node.getY() + port.getY();
            maxx = Math.max(maxx, portx + port.getWidth());
            maxy = Math.max(maxy, porty + port.getHeight());
            // set the fixed position of the port labels, or leave them as they are
            for (ElkLabel label : port.getLabels()) {
                pos = label.getProperty(FixedLayouterOptions.POSITION);
                if (pos != null) {
                    label.setLocation(pos.x, pos.y);
                }
                maxx = Math.max(maxx, portx + label.getX() + label.getWidth());
                maxy = Math.max(maxy, porty + label.getY() + label.getHeight());
            }
        }
        // set fixed routing for the node's outgoing edges (both simple and hierarchical), or leave them as they are
        for (ElkEdge edge : ElkGraphUtil.allOutgoingEdges(node)) {
            KVector maxv = processEdge(edge, edgeRouting);
            maxx = Math.max(maxx, maxv.x);
            maxy = Math.max(maxy, maxv.y);
        }
        // note that this potentially results in hierarchical edges being handled twice
        for (ElkEdge edge : ElkGraphUtil.allIncomingEdges(node)) {
            if (ElkGraphUtil.getSourceNode(edge).getParent() != layoutNode) {
                KVector maxv = processEdge(edge, edgeRouting);
                maxx = Math.max(maxx, maxv.x);
                maxy = Math.max(maxy, maxv.y);
            }
        }
    }
    // if orthogonal routing is selected, determine the junction points
    if (edgeRouting == EdgeRouting.ORTHOGONAL) {
        for (ElkNode node : layoutNode.getChildren()) {
            for (ElkEdge edge : ElkGraphUtil.allOutgoingEdges(node)) {
                generateJunctionPoints(edge);
            }
        }
    }
    // set size of the parent node unless its size should be fixed as well
    if (!layoutNode.getProperty(FixedLayouterOptions.NODE_SIZE_FIXED_GRAPH_SIZE)) {
        ElkPadding padding = layoutNode.getProperty(FixedLayouterOptions.PADDING);
        double newWidth = maxx + padding.getLeft() + padding.getRight();
        double newHeight = maxy + padding.getTop() + padding.getBottom();
        ElkUtil.resizeNode(layoutNode, newWidth, newHeight, true, true);
    }
    progressMonitor.done();
}
Also used : ElkNode(org.eclipse.elk.graph.ElkNode) ElkLabel(org.eclipse.elk.graph.ElkLabel) ElkPort(org.eclipse.elk.graph.ElkPort) EdgeRouting(org.eclipse.elk.core.options.EdgeRouting) KVector(org.eclipse.elk.core.math.KVector) ElkPadding(org.eclipse.elk.core.math.ElkPadding) ElkEdge(org.eclipse.elk.graph.ElkEdge)

Example 23 with ElkLabel

use of org.eclipse.elk.graph.ElkLabel in project elk by eclipse.

the class DisCoGraphRenderer method renderNodeChildren.

// filling alpha added by mic
/**
 * Paints all children of the given parent node that fall into the given dirty
 * area.
 *
 * @param parent
 *            the node whose children to paint
 * @param graphics
 *            the graphics context used to paint
 * @param area
 *            dirty area that needs painting
 * @param offset
 *            offset to be added to relative coordinates
 * @param edgeSet
 *            set to be filled with edges that are found on the way
 * @param nodeAlpha
 *            alpha value for nodes
 * @param fillingAlpha
 *            alpha value for node fillings
 */
private void renderNodeChildren(final ElkNode parent, final GC graphics, final Rectangle area, final KVector offset, final Set<ElkEdge> edgeSet, final int nodeAlpha, final int fillingAlpha) {
    for (ElkNode child : parent.getChildren()) {
        PaintRectangle rect = boundsMap.get(child);
        if (rect == null) {
            rect = new PaintRectangle(child, offset, getScale());
            boundsMap.put(child, rect);
        }
        KVector childOffset = new KVector(rect.x, rect.y);
        // render the child node and its content
        if (!rect.painted && rect.intersects(area)) {
            // paint this node
            graphics.setAlpha(fillingAlpha);
            if (configurator.getNodeFillColor() != null) {
                graphics.setBackground(configurator.getNodeFillColor());
                graphics.fillRectangle(rect.x, rect.y, rect.width, rect.height);
            }
            graphics.setAlpha(nodeAlpha);
            if (configurator.getNodeBorderColor() != null) {
                graphics.setForeground(configurator.getNodeBorderColor());
                graphics.drawRectangle(rect.x, rect.y, rect.width, rect.height);
            }
            rect.painted = true;
        }
        // render node labels
        if (configurator.getNodeLabelFont() != null) {
            graphics.setFont(configurator.getNodeLabelFont());
            for (ElkLabel label : child.getLabels()) {
                renderLabel(label, graphics, area, childOffset, nodeAlpha);
            }
        }
        // render ports
        for (ElkPort port : child.getPorts()) {
            renderPort(port, graphics, area, childOffset, nodeAlpha);
        }
        // store all incident edges to render them later
        edgeSet.addAll(Sets.newHashSet(ElkGraphUtil.allIncidentEdges(child)));
    }
}
Also used : ElkNode(org.eclipse.elk.graph.ElkNode) ElkLabel(org.eclipse.elk.graph.ElkLabel) ElkPort(org.eclipse.elk.graph.ElkPort) KVector(org.eclipse.elk.core.math.KVector)

Example 24 with ElkLabel

use of org.eclipse.elk.graph.ElkLabel in project elk by eclipse.

the class AbstractElkGraphSemanticSequencer method sequence.

@Override
public void sequence(ISerializationContext context, EObject semanticObject) {
    EPackage epackage = semanticObject.eClass().getEPackage();
    ParserRule rule = context.getParserRule();
    Action action = context.getAssignedAction();
    Set<Parameter> parameters = context.getEnabledBooleanParameters();
    if (epackage == ElkGraphPackage.eINSTANCE)
        switch(semanticObject.eClass().getClassifierID()) {
            case ElkGraphPackage.ELK_BEND_POINT:
                sequence_ElkBendPoint(context, (ElkBendPoint) semanticObject);
                return;
            case ElkGraphPackage.ELK_EDGE:
                sequence_EdgeLayout_ElkEdge(context, (ElkEdge) semanticObject);
                return;
            case ElkGraphPackage.ELK_EDGE_SECTION:
                if (rule == grammarAccess.getElkEdgeSectionRule()) {
                    sequence_ElkEdgeSection(context, (ElkEdgeSection) semanticObject);
                    return;
                } else if (rule == grammarAccess.getElkSingleEdgeSectionRule()) {
                    sequence_ElkSingleEdgeSection(context, (ElkEdgeSection) semanticObject);
                    return;
                } else
                    break;
            case ElkGraphPackage.ELK_LABEL:
                sequence_ElkLabel_ShapeLayout(context, (ElkLabel) semanticObject);
                return;
            case ElkGraphPackage.ELK_NODE:
                if (rule == grammarAccess.getElkNodeRule()) {
                    sequence_ElkNode_ShapeLayout(context, (ElkNode) semanticObject);
                    return;
                } else if (rule == grammarAccess.getRootNodeRule()) {
                    sequence_RootNode_ShapeLayout(context, (ElkNode) semanticObject);
                    return;
                } else
                    break;
            case ElkGraphPackage.ELK_PORT:
                sequence_ElkPort_ShapeLayout(context, (ElkPort) semanticObject);
                return;
            case ElkGraphPackage.ELK_PROPERTY_TO_VALUE_MAP_ENTRY:
                sequence_Property(context, (Map.Entry) semanticObject);
                return;
        }
    if (errorAcceptor != null)
        errorAcceptor.accept(diagnosticProvider.createInvalidContextOrTypeDiagnostic(semanticObject, context));
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) Action(org.eclipse.xtext.Action) ElkNode(org.eclipse.elk.graph.ElkNode) ElkLabel(org.eclipse.elk.graph.ElkLabel) ElkPort(org.eclipse.elk.graph.ElkPort) Parameter(org.eclipse.xtext.Parameter) ElkBendPoint(org.eclipse.elk.graph.ElkBendPoint) ElkEdgeSection(org.eclipse.elk.graph.ElkEdgeSection) EPackage(org.eclipse.emf.ecore.EPackage) ElkEdge(org.eclipse.elk.graph.ElkEdge)

Example 25 with ElkLabel

use of org.eclipse.elk.graph.ElkLabel in project elk by eclipse.

the class ElkGraphUtil method createLabel.

/**
 * Creates a new label with the given text for the given graph element.
 *
 * @param text the label's text.
 * @param parent the parent element. May be {@code null}, in which case the new label is not added to anything.
 * @return the new label.
 */
public static ElkLabel createLabel(final String text, final ElkGraphElement parent) {
    ElkLabel label = createLabel(parent);
    label.setText(text);
    return label;
}
Also used : ElkLabel(org.eclipse.elk.graph.ElkLabel)

Aggregations

ElkLabel (org.eclipse.elk.graph.ElkLabel)64 ElkNode (org.eclipse.elk.graph.ElkNode)33 KVector (org.eclipse.elk.core.math.KVector)25 ElkPort (org.eclipse.elk.graph.ElkPort)23 ElkEdge (org.eclipse.elk.graph.ElkEdge)20 ElkEdgeSection (org.eclipse.elk.graph.ElkEdgeSection)14 KVectorChain (org.eclipse.elk.core.math.KVectorChain)12 ElkPadding (org.eclipse.elk.core.math.ElkPadding)10 ElkGraphElement (org.eclipse.elk.graph.ElkGraphElement)9 SizeConstraint (org.eclipse.elk.core.options.SizeConstraint)7 PortSide (org.eclipse.elk.core.options.PortSide)6 List (java.util.List)5 LLabel (org.eclipse.elk.alg.layered.graph.LLabel)5 LPort (org.eclipse.elk.alg.layered.graph.LPort)5 ElkBendPoint (org.eclipse.elk.graph.ElkBendPoint)5 ElkConnectableShape (org.eclipse.elk.graph.ElkConnectableShape)5 Test (org.junit.Test)5 Lists (com.google.common.collect.Lists)4 Rectangle (org.eclipse.draw2d.geometry.Rectangle)4 DCElement (org.eclipse.elk.alg.disco.graph.DCElement)4