Search in sources :

Example 6 with LabelCell

use of org.eclipse.elk.alg.common.nodespacing.cellsystem.LabelCell 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 7 with LabelCell

use of org.eclipse.elk.alg.common.nodespacing.cellsystem.LabelCell in project elk by eclipse.

the class EndLabelPreprocessor method processNode.

private void processNode(final LNode node, final double edgeLabelSpacing, final double labelLabelSpacing, final boolean verticalLayout) {
    // Iterate over all ports and collect their labels in label cells
    int portCount = node.getPorts().size();
    LabelCell[] portLabelCells = new LabelCell[portCount];
    for (int portIndex = 0; portIndex < portCount; portIndex++) {
        LPort port = node.getPorts().get(portIndex);
        port.id = portIndex;
        portLabelCells[portIndex] = createConfiguredLabelCell(gatherLabels(port), labelLabelSpacing, verticalLayout);
    }
    // Actually go off and place them labels!
    placeLabels(node, portLabelCells, labelLabelSpacing, edgeLabelSpacing, verticalLayout);
    // Turn the array into a map and save that in the node
    Map<LPort, LabelCell> portToLabelCellMap = new HashMap<>();
    for (int index = 0; index < portLabelCells.length; index++) {
        if (portLabelCells[index] != null) {
            portToLabelCellMap.put(node.getPorts().get(index), portLabelCells[index]);
        }
    }
    if (!portToLabelCellMap.isEmpty()) {
        node.setProperty(InternalProperties.END_LABELS, portToLabelCellMap);
        // Update the node's margins
        updateNodeMargins(node, portLabelCells);
    }
}
Also used : HashMap(java.util.HashMap) LabelCell(org.eclipse.elk.alg.common.nodespacing.cellsystem.LabelCell) LPort(org.eclipse.elk.alg.layered.graph.LPort)

Example 8 with LabelCell

use of org.eclipse.elk.alg.common.nodespacing.cellsystem.LabelCell in project elk by eclipse.

the class EndLabelPostprocessor method processNode.

private void processNode(final LNode node) {
    assert node.hasProperty(InternalProperties.END_LABELS);
    // The node should have a non-empty list of label cells, or something went TERRIBLY WRONG!!!
    Map<LPort, LabelCell> endLabelCells = node.getProperty(InternalProperties.END_LABELS);
    assert !endLabelCells.isEmpty();
    KVector nodePos = node.getPosition();
    for (LabelCell labelCell : endLabelCells.values()) {
        ElkRectangle labelCellRect = labelCell.getCellRectangle();
        labelCellRect.move(nodePos);
        labelCell.applyLabelLayout();
    }
    // Remove label cells
    node.setProperty(InternalProperties.END_LABELS, null);
}
Also used : LabelCell(org.eclipse.elk.alg.common.nodespacing.cellsystem.LabelCell) LPort(org.eclipse.elk.alg.layered.graph.LPort) KVector(org.eclipse.elk.core.math.KVector) ElkRectangle(org.eclipse.elk.core.math.ElkRectangle)

Example 9 with LabelCell

use of org.eclipse.elk.alg.common.nodespacing.cellsystem.LabelCell in project elk by eclipse.

the class EndLabelSorter method processNode.

// ////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Node Processing and Initialization
private void processNode(final LNode node) {
    boolean initializeMethodCalled = false;
    if (node.hasProperty(InternalProperties.END_LABELS)) {
        Map<LPort, LabelCell> labelCellMap = node.getProperty(InternalProperties.END_LABELS);
        // Iterate over all ports and check for each port if it requires its labels to be sorted
        for (LPort port : node.getPorts()) {
            if (needsSorting(port)) {
                // Check if we need to initialize
                if (!initializeMethodCalled) {
                    initialize(node.getGraph());
                    initializeMethodCalled = true;
                }
                sort(port, labelCellMap.get(port));
            }
        }
    }
}
Also used : LabelCell(org.eclipse.elk.alg.common.nodespacing.cellsystem.LabelCell) LPort(org.eclipse.elk.alg.layered.graph.LPort)

Example 10 with LabelCell

use of org.eclipse.elk.alg.common.nodespacing.cellsystem.LabelCell in project elk by eclipse.

the class NodeLabelCellCreator method retrieveNodeLabelCell.

/**
 * Retrieves the node label cell for the given location. If it doesn't exist yet, it is created.
 */
private static LabelCell retrieveNodeLabelCell(final NodeContext nodeContext, final NodeLabelLocation nodeLabelLocation, final boolean horizontalLayoutMode) {
    LabelCell nodeLabelCell = nodeContext.nodeLabelCells.get(nodeLabelLocation);
    if (nodeLabelCell == null) {
        // The node label cell doesn't exist yet, so create one and add it to the relevant container
        nodeLabelCell = new LabelCell(nodeContext.labelLabelSpacing, nodeLabelLocation, horizontalLayoutMode);
        nodeContext.nodeLabelCells.put(nodeLabelLocation, nodeLabelCell);
        // Find the correct container and add the cell to it
        if (nodeLabelLocation.isInsideLocation()) {
            nodeContext.insideNodeLabelContainer.setCell(nodeLabelLocation.getContainerRow(), nodeLabelLocation.getContainerColumn(), nodeLabelCell);
        } else {
            PortSide outsideSide = nodeLabelLocation.getOutsideSide();
            StripContainerCell containerCell = nodeContext.outsideNodeLabelContainers.get(outsideSide);
            switch(outsideSide) {
                case NORTH:
                case SOUTH:
                    nodeLabelCell.setContributesToMinimumHeight(true);
                    containerCell.setCell(nodeLabelLocation.getContainerColumn(), nodeLabelCell);
                    break;
                case WEST:
                case EAST:
                    nodeLabelCell.setContributesToMinimumWidth(true);
                    containerCell.setCell(nodeLabelLocation.getContainerRow(), nodeLabelCell);
                    break;
            }
        }
    }
    return nodeLabelCell;
}
Also used : LabelCell(org.eclipse.elk.alg.common.nodespacing.cellsystem.LabelCell) PortSide(org.eclipse.elk.core.options.PortSide) StripContainerCell(org.eclipse.elk.alg.common.nodespacing.cellsystem.StripContainerCell)

Aggregations

LabelCell (org.eclipse.elk.alg.common.nodespacing.cellsystem.LabelCell)13 ElkRectangle (org.eclipse.elk.core.math.ElkRectangle)7 KVector (org.eclipse.elk.core.math.KVector)6 PortContext (org.eclipse.elk.alg.common.nodespacing.internal.PortContext)5 LPort (org.eclipse.elk.alg.layered.graph.LPort)3 VerticalLabelAlignment (org.eclipse.elk.alg.common.nodespacing.cellsystem.VerticalLabelAlignment)2 RectangleStripOverlapRemover (org.eclipse.elk.alg.common.overlaps.RectangleStripOverlapRemover)2 OverlapRemovalDirection (org.eclipse.elk.alg.common.overlaps.RectangleStripOverlapRemover.OverlapRemovalDirection)2 LLabel (org.eclipse.elk.alg.layered.graph.LLabel)2 Lists (com.google.common.collect.Lists)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 AtomicCell (org.eclipse.elk.alg.common.nodespacing.cellsystem.AtomicCell)1 StripContainerCell (org.eclipse.elk.alg.common.nodespacing.cellsystem.StripContainerCell)1 NodeLabelLocation (org.eclipse.elk.alg.common.nodespacing.internal.NodeLabelLocation)1 LGraph (org.eclipse.elk.alg.layered.graph.LGraph)1 LMargin (org.eclipse.elk.alg.layered.graph.LMargin)1 LNode (org.eclipse.elk.alg.layered.graph.LNode)1