Search in sources :

Example 1 with LLabel

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

the class HierarchicalPortOrthogonalEdgeRouter method restoreDummy.

/**
 * Restores the given dummy.
 */
private void restoreDummy(final LNode dummy, final LGraph graph) {
    // Depending on the hierarchical port's side, we set the port side of the dummy's ports
    // to be able to route properly (northern dummies must have a southern port)
    PortSide portSide = dummy.getProperty(InternalProperties.EXT_PORT_SIDE);
    LPort dummyPort = dummy.getPorts().get(0);
    if (portSide == PortSide.NORTH) {
        dummyPort.setSide(PortSide.SOUTH);
    } else if (portSide == PortSide.SOUTH) {
        dummyPort.setSide(PortSide.NORTH);
    }
    // are not set acoordingly. That needs to be fixed (if port labels are to be taken into consideration)
    if (graph.getProperty(LayeredOptions.NODE_SIZE_CONSTRAINTS).contains(SizeConstraint.PORT_LABELS)) {
        // The ElkGraphImporter has set the relevant spacings on the dummy node
        double portLabelSpacing = dummy.getProperty(LayeredOptions.SPACING_LABEL_PORT);
        double labelLabelSpacing = dummy.getProperty(LayeredOptions.SPACING_LABEL_LABEL);
        Set<PortLabelPlacement> portLabelPlacement = graph.getProperty(LayeredOptions.PORT_LABELS_PLACEMENT);
        if (portLabelPlacement.contains(PortLabelPlacement.INSIDE)) {
            double currentY = portLabelSpacing;
            double xCenterRelativeToPort = dummy.getSize().x / 2 - dummyPort.getPosition().x;
            for (LLabel label : dummyPort.getLabels()) {
                label.getPosition().y = currentY;
                label.getPosition().x = xCenterRelativeToPort - label.getSize().x / 2;
                currentY += label.getSize().y + labelLabelSpacing;
            }
        } else if (portLabelPlacement.contains(PortLabelPlacement.OUTSIDE)) {
            // Port labels have a vertical size of 0, but we need to set their x coordinate
            for (LLabel label : dummyPort.getLabels()) {
                label.getPosition().x = portLabelSpacing + dummy.getSize().x - dummyPort.getPosition().x;
            }
        }
        // Calculate margins
        NodeDimensionCalculation.getNodeMarginCalculator(LGraphAdapters.adapt(graph, false)).processNode(LGraphAdapters.adapt(dummy, false));
    }
}
Also used : PortLabelPlacement(org.eclipse.elk.core.options.PortLabelPlacement) LLabel(org.eclipse.elk.alg.layered.graph.LLabel) LPort(org.eclipse.elk.alg.layered.graph.LPort) PortSide(org.eclipse.elk.core.options.PortSide)

Example 2 with LLabel

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

the class InvertedPortProcessor method createEastPortSideDummies.

/**
 * Creates the necessary dummy nodes for an input port on the east side of a node, provided that
 * the edge connects two different nodes.
 *
 * @param layeredGraph
 *            the layered graph.
 * @param eastwardPort
 *            the offending port.
 * @param edge
 *            the edge connected to the port.
 * @param layerNodeList
 *            list of unassigned nodes belonging to the layer of the node the port belongs to.
 *            The new dummy node is added to this list and must be assigned to the layer later.
 */
private void createEastPortSideDummies(final LGraph layeredGraph, final LPort eastwardPort, final LEdge edge, final List<LNode> layerNodeList) {
    assert edge.getTarget() == eastwardPort;
    // Ignore self loops
    if (edge.getSource().getNode() == eastwardPort.getNode()) {
        return;
    }
    // Dummy node in the same layer
    LNode dummy = new LNode(layeredGraph);
    dummy.setType(NodeType.LONG_EDGE);
    dummy.setProperty(InternalProperties.ORIGIN, edge);
    dummy.setProperty(LayeredOptions.PORT_CONSTRAINTS, PortConstraints.FIXED_POS);
    layerNodeList.add(dummy);
    LPort dummyInput = new LPort();
    dummyInput.setNode(dummy);
    dummyInput.setSide(PortSide.WEST);
    LPort dummyOutput = new LPort();
    dummyOutput.setNode(dummy);
    dummyOutput.setSide(PortSide.EAST);
    // Reroute the original edge
    edge.setTarget(dummyInput);
    // Connect the dummy with the original port
    LEdge dummyEdge = new LEdge();
    dummyEdge.copyProperties(edge);
    dummyEdge.setProperty(LayeredOptions.JUNCTION_POINTS, null);
    dummyEdge.setSource(dummyOutput);
    dummyEdge.setTarget(eastwardPort);
    // Set LONG_EDGE_SOURCE and LONG_EDGE_TARGET properties on the LONG_EDGE dummy
    setLongEdgeSourceAndTarget(dummy, dummyInput, dummyOutput, eastwardPort);
    // Move head labels from the old edge over to the new one
    ListIterator<LLabel> labelIterator = edge.getLabels().listIterator();
    while (labelIterator.hasNext()) {
        LLabel label = labelIterator.next();
        EdgeLabelPlacement labelPlacement = label.getProperty(LayeredOptions.EDGE_LABELS_PLACEMENT);
        if (labelPlacement == EdgeLabelPlacement.HEAD) {
            // Remember which edge the label originally belonged to, unless it already knows
            if (!label.hasProperty(InternalProperties.END_LABEL_EDGE)) {
                label.setProperty(InternalProperties.END_LABEL_EDGE, edge);
            }
            labelIterator.remove();
            dummyEdge.getLabels().add(label);
        }
    }
}
Also used : LLabel(org.eclipse.elk.alg.layered.graph.LLabel) LEdge(org.eclipse.elk.alg.layered.graph.LEdge) LPort(org.eclipse.elk.alg.layered.graph.LPort) LNode(org.eclipse.elk.alg.layered.graph.LNode) EdgeLabelPlacement(org.eclipse.elk.core.options.EdgeLabelPlacement)

Example 3 with LLabel

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

the class LabelAndNodeSizeProcessor method computePortLabelBox.

/**
 * Returns the amount of space required to place the labels later, or {@code null} if there are no labels.
 */
private ElkRectangle computePortLabelBox(final LPort dummyPort, final double labelLabelSpacing) {
    if (dummyPort.getLabels().isEmpty()) {
        return null;
    } else {
        ElkRectangle result = new ElkRectangle();
        for (LLabel label : dummyPort.getLabels()) {
            KVector labelSize = label.getSize();
            result.width = Math.max(result.width, labelSize.x);
            result.height += labelSize.y;
        }
        result.height += (dummyPort.getLabels().size() - 1) * labelLabelSpacing;
        return result;
    }
}
Also used : LLabel(org.eclipse.elk.alg.layered.graph.LLabel) ElkRectangle(org.eclipse.elk.core.math.ElkRectangle) KVector(org.eclipse.elk.core.math.KVector)

Example 4 with LLabel

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

the class LabelDummyRemover method placeLabelsForHorizontalLayout.

private void placeLabelsForHorizontalLayout(final List<LLabel> labels, final KVector labelPos, final double labelSpacing, final KVector labelSpace) {
    for (LLabel label : labels) {
        label.getPosition().x = labelPos.x + (labelSpace.x - label.getSize().x) / 2.0;
        label.getPosition().y = labelPos.y;
        labelPos.y += label.getSize().y + labelSpacing;
    }
}
Also used : LLabel(org.eclipse.elk.alg.layered.graph.LLabel)

Example 5 with LLabel

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

the class LabelManagementProcessor method manageCenterLabels.

// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Center Edge Labels
/**
 * Calls label management on all edge center labels.
 */
private void manageCenterLabels(final LGraph lGraph, final ILabelManager labelManager, final double edgeLabelSpacing, final double labelLabelSpacing) {
    boolean verticalLayout = lGraph.getProperty(LayeredOptions.DIRECTION).isVertical();
    // Iterate over the layers and find label dummy nodes
    for (Layer layer : lGraph) {
        // The maximum width is used as the target width for center edge labels
        double maxWidth = Math.max(MIN_WIDTH_EDGE_LABELS, LGraphUtil.findMaxNonDummyNodeWidth(layer, false));
        for (LNode node : layer) {
            if (node.getType() == NodeType.LABEL) {
                LEdge edge = node.getConnectedEdges().iterator().next();
                double edgeThickness = edge.getProperty(LayeredOptions.EDGE_THICKNESS).doubleValue();
                // The list of labels should never be empty (otherwise the label dummy wouldn't have been created
                // in the first place)
                Iterable<LLabel> labels = node.getProperty(InternalProperties.REPRESENTED_LABELS);
                KVector spaceRequiredForLabels = doManageLabels(labelManager, labels, maxWidth, labelLabelSpacing, verticalLayout);
                // Apply the space required for labels to the dummy node (we don't bother with the ports here since
                // they will be meddled with later by the LabelSideSelector anyway)
                node.getSize().x = spaceRequiredForLabels.x;
                node.getSize().y = spaceRequiredForLabels.y + edgeThickness + edgeLabelSpacing;
            }
        }
    }
}
Also used : LLabel(org.eclipse.elk.alg.layered.graph.LLabel) LEdge(org.eclipse.elk.alg.layered.graph.LEdge) LNode(org.eclipse.elk.alg.layered.graph.LNode) KVector(org.eclipse.elk.core.math.KVector) Layer(org.eclipse.elk.alg.layered.graph.Layer)

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