Search in sources :

Example 21 with LLabel

use of org.eclipse.elk.alg.layered.graph.LLabel in project elk by eclipse.

the class ElkGraphImporter method transformLabel.

// /////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Label Transformation
/**
 * Transform the given {@code ElkLabel} into an {@code LLabel}.
 *
 * @param elklabel the label to transform.
 * @return the created {@code LLabel}.
 */
private LLabel transformLabel(final ElkLabel elklabel) {
    LLabel newLabel = new LLabel(elklabel.getText());
    newLabel.copyProperties(elklabel);
    newLabel.setProperty(InternalProperties.ORIGIN, elklabel);
    newLabel.getSize().x = elklabel.getWidth();
    newLabel.getSize().y = elklabel.getHeight();
    newLabel.getPosition().x = elklabel.getX();
    newLabel.getPosition().y = elklabel.getY();
    return newLabel;
}
Also used : LLabel(org.eclipse.elk.alg.layered.graph.LLabel)

Example 22 with LLabel

use of org.eclipse.elk.alg.layered.graph.LLabel in project elk by eclipse.

the class EndLabelPreprocessor method createConfiguredLabelCell.

/**
 * Creates label cell for the given port with the given labels, if any. If there are no labels, this method returns
 * {@code null}. The label cell will still have to have its alignment set up, but its size is already set to the
 * size required to place its labels.
 */
private LabelCell createConfiguredLabelCell(final List<LLabel> labels, final double labelLabelSpacing, final boolean verticalLayout) {
    if (labels == null || labels.isEmpty()) {
        return null;
    }
    // Create the new label cell and setup its alignments depending on the port's side
    LabelCell labelCell = new LabelCell(labelLabelSpacing, !verticalLayout);
    for (LLabel label : labels) {
        labelCell.addLabel(LGraphAdapters.adapt(label));
    }
    // Setup the label cell's size
    ElkRectangle labelCellRect = labelCell.getCellRectangle();
    labelCellRect.height = labelCell.getMinimumHeight();
    labelCellRect.width = labelCell.getMinimumWidth();
    return labelCell;
}
Also used : LLabel(org.eclipse.elk.alg.layered.graph.LLabel) LabelCell(org.eclipse.elk.alg.common.nodespacing.cellsystem.LabelCell) ElkRectangle(org.eclipse.elk.core.math.ElkRectangle)

Example 23 with LLabel

use of org.eclipse.elk.alg.layered.graph.LLabel in project elk by eclipse.

the class EndLabelPreprocessor method gatherLabels.

/**
 * Returns a list that contains all end labels to be placed at the given port. If there are no such labels, the
 * list will be empty. If there are not even any edges connected to the port, the return value will be {@code null}.
 *
 *  <p>his method also takes care of north / south ports whose original edges have been rerouted to a north / south
 *  port dummy. The maximum thickness of any edge connected to the port is saved
 *  {@link InternalProperties#MAX_EDGE_THICKNESS as a property} if it has labels.</p>
 *
 * <p>This method is also used by {@link LabelSideSelector}.</p>
 */
static List<LLabel> gatherLabels(final LPort port) {
    List<LLabel> labels = Lists.newArrayList();
    // Gather labels of the port itself
    double maxEdgeThickness = gatherLabels(port, labels);
    // If it has a dummy associated with it, we need to go through the dummy's ports and process those that were
    // created for the current port (see the NorthSouthPortPreprocessor)
    LNode dummyNode = port.getProperty(InternalProperties.PORT_DUMMY);
    if (dummyNode != null) {
        for (LPort dummyPort : dummyNode.getPorts()) {
            if (dummyPort.getProperty(InternalProperties.ORIGIN) == port) {
                maxEdgeThickness = Math.max(maxEdgeThickness, gatherLabels(dummyPort, labels));
            }
        }
    }
    // Only save the maximum edge thickness if we'll be interested in it later
    if (!labels.isEmpty()) {
        port.setProperty(InternalProperties.MAX_EDGE_THICKNESS, maxEdgeThickness);
    }
    return maxEdgeThickness != NO_INCIDENT_EDGE_THICKNESS ? labels : null;
}
Also used : LLabel(org.eclipse.elk.alg.layered.graph.LLabel) LPort(org.eclipse.elk.alg.layered.graph.LPort) LNode(org.eclipse.elk.alg.layered.graph.LNode)

Example 24 with LLabel

use of org.eclipse.elk.alg.layered.graph.LLabel in project elk by eclipse.

the class EndLabelPreprocessor method gatherLabels.

/**
 * Puts all relevant end labels of edges connected to the given port into the given list. Returns the maximum edge
 * thickness of any incident edge or {@link #NO_INCIDENT_EDGE_THICKNESS} if there is no incident edge.
 */
private static double gatherLabels(final LPort port, final List<LLabel> targetList) {
    double maxEdgeThickness = -1;
    List<LLabel> labels = new LinkedList<>();
    for (LEdge incidentEdge : port.getConnectedEdges()) {
        maxEdgeThickness = Math.max(maxEdgeThickness, incidentEdge.getProperty(LayeredOptions.EDGE_THICKNESS));
        if (incidentEdge.getSource() == port) {
            // It's an outgoing edge; all tail labels belong to this port
            incidentEdge.getLabels().stream().filter(label -> label.getProperty(LayeredOptions.EDGE_LABELS_PLACEMENT) == EdgeLabelPlacement.TAIL).forEach(label -> labels.add(label));
        } else {
            // It's an incoming edge; all head labels belong to this port
            incidentEdge.getLabels().stream().filter(label -> label.getProperty(LayeredOptions.EDGE_LABELS_PLACEMENT) == EdgeLabelPlacement.HEAD).forEach(label -> labels.add(label));
        }
        // Remember the edge each label came from
        for (LLabel label : labels) {
            if (!label.hasProperty(InternalProperties.END_LABEL_EDGE)) {
                label.setProperty(InternalProperties.END_LABEL_EDGE, incidentEdge);
            }
        }
        targetList.addAll(labels);
        labels.clear();
    }
    return maxEdgeThickness;
}
Also used : LLabel(org.eclipse.elk.alg.layered.graph.LLabel) PortSide(org.eclipse.elk.core.options.PortSide) RectangleStripOverlapRemover(org.eclipse.elk.alg.common.overlaps.RectangleStripOverlapRemover) IElkProgressMonitor(org.eclipse.elk.core.util.IElkProgressMonitor) HorizontalLabelAlignment(org.eclipse.elk.alg.common.nodespacing.cellsystem.HorizontalLabelAlignment) HashMap(java.util.HashMap) LEdge(org.eclipse.elk.alg.layered.graph.LEdge) ILayoutProcessor(org.eclipse.elk.core.alg.ILayoutProcessor) LayeredOptions(org.eclipse.elk.alg.layered.options.LayeredOptions) OverlapRemovalDirection(org.eclipse.elk.alg.common.overlaps.RectangleStripOverlapRemover.OverlapRemovalDirection) ElkRectangle(org.eclipse.elk.core.math.ElkRectangle) VerticalLabelAlignment(org.eclipse.elk.alg.common.nodespacing.cellsystem.VerticalLabelAlignment) Lists(com.google.common.collect.Lists) InternalProperties(org.eclipse.elk.alg.layered.options.InternalProperties) LabelSide(org.eclipse.elk.core.options.LabelSide) Map(java.util.Map) LGraphAdapters(org.eclipse.elk.alg.layered.graph.LGraphAdapters) LinkedList(java.util.LinkedList) EnumSet(java.util.EnumSet) KVector(org.eclipse.elk.core.math.KVector) LMargin(org.eclipse.elk.alg.layered.graph.LMargin) LabelCell(org.eclipse.elk.alg.common.nodespacing.cellsystem.LabelCell) List(java.util.List) LGraph(org.eclipse.elk.alg.layered.graph.LGraph) LPort(org.eclipse.elk.alg.layered.graph.LPort) EdgeLabelPlacement(org.eclipse.elk.core.options.EdgeLabelPlacement) LNode(org.eclipse.elk.alg.layered.graph.LNode) LLabel(org.eclipse.elk.alg.layered.graph.LLabel) LEdge(org.eclipse.elk.alg.layered.graph.LEdge) LinkedList(java.util.LinkedList)

Example 25 with LLabel

use of org.eclipse.elk.alg.layered.graph.LLabel in project elk by eclipse.

the class GraphTransformer method transpose.

// /////////////////////////////////////////////////////////////////////////////
// Transpose
/**
 * Transpose the x and y coordinates of the given graph.
 *
 * @param nodes the nodes of the graph to transpose
 */
private void transpose(final List<LNode> nodes) {
    // Transpose nodes
    for (LNode node : nodes) {
        transpose(node.getPosition());
        transpose(node.getSize());
        transpose(node.getPadding());
        transposeNodeLabelPlacement(node);
        transposeProperties(node);
        // Transpose ports
        for (LPort port : node.getPorts()) {
            transpose(port.getPosition());
            transpose(port.getAnchor());
            transpose(port.getSize());
            transposePortSide(port);
            reverseIndex(port);
            // Transpose edges
            for (LEdge edge : port.getOutgoingEdges()) {
                // Transpose bend points
                for (KVector bendPoint : edge.getBendPoints()) {
                    transpose(bendPoint);
                }
                // Transpose junction points
                KVectorChain junctionPoints = edge.getProperty(LayeredOptions.JUNCTION_POINTS);
                if (junctionPoints != null) {
                    for (KVector jp : junctionPoints) {
                        transpose(jp);
                    }
                }
                // Transpose edge labels
                for (LLabel label : edge.getLabels()) {
                    transpose(label.getPosition());
                    transpose(label.getSize());
                }
            }
            // Transpose port labels
            for (LLabel label : port.getLabels()) {
                transpose(label.getPosition());
                transpose(label.getSize());
            }
        }
        // External port dummy?
        if (node.getType() == NodeType.EXTERNAL_PORT) {
            transposeExternalPortSide(node);
            transposeLayerConstraint(node);
        }
        // Transpose node labels
        for (LLabel label : node.getLabels()) {
            transposeNodeLabelPlacement(label);
            transpose(label.getSize());
            transpose(label.getPosition());
        }
    }
}
Also used : LLabel(org.eclipse.elk.alg.layered.graph.LLabel) LEdge(org.eclipse.elk.alg.layered.graph.LEdge) KVectorChain(org.eclipse.elk.core.math.KVectorChain) LPort(org.eclipse.elk.alg.layered.graph.LPort) LNode(org.eclipse.elk.alg.layered.graph.LNode) KVector(org.eclipse.elk.core.math.KVector)

Aggregations

LLabel (org.eclipse.elk.alg.layered.graph.LLabel)38 LPort (org.eclipse.elk.alg.layered.graph.LPort)20 LNode (org.eclipse.elk.alg.layered.graph.LNode)19 KVector (org.eclipse.elk.core.math.KVector)19 LEdge (org.eclipse.elk.alg.layered.graph.LEdge)14 KVectorChain (org.eclipse.elk.core.math.KVectorChain)8 PortSide (org.eclipse.elk.core.options.PortSide)5 List (java.util.List)4 ElkRectangle (org.eclipse.elk.core.math.ElkRectangle)4 ElkLabel (org.eclipse.elk.graph.ElkLabel)4 LabelCell (org.eclipse.elk.alg.common.nodespacing.cellsystem.LabelCell)3 LGraph (org.eclipse.elk.alg.layered.graph.LGraph)3 Layer (org.eclipse.elk.alg.layered.graph.Layer)3 EdgeLabelPlacement (org.eclipse.elk.core.options.EdgeLabelPlacement)3 Lists (com.google.common.collect.Lists)2 LMargin (org.eclipse.elk.alg.layered.graph.LMargin)2 InternalProperties (org.eclipse.elk.alg.layered.options.InternalProperties)2 LayeredOptions (org.eclipse.elk.alg.layered.options.LayeredOptions)2 Direction (org.eclipse.elk.core.options.Direction)2 PortConstraints (org.eclipse.elk.core.options.PortConstraints)2