Search in sources :

Example 1 with LabelSide

use of org.eclipse.elk.core.options.LabelSide in project elk by eclipse.

the class LabelSideSelector method applyLabelSide.

// //////////////////////////////////////////////////////////////////////////////////////
// Helper Methods
/**
 * Applies the given label side to the given label dummy node. If necessary, its ports are moved to reserve space
 * for the label on the correct side.
 */
private void applyLabelSide(final LNode labelDummy, final LabelSide side) {
    // This method only does things to label dummy nodes
    if (labelDummy.getType() == NodeType.LABEL) {
        LabelSide effectiveSide = areLabelsPlacedInline(labelDummy) ? LabelSide.INLINE : side;
        labelDummy.setProperty(InternalProperties.LABEL_SIDE, effectiveSide);
        // If the label is not below the edge, the ports need to be moved
        if (effectiveSide != LabelSide.BELOW) {
            LEdge originEdge = (LEdge) labelDummy.getProperty(InternalProperties.ORIGIN);
            double thickness = originEdge.getProperty(LayeredOptions.EDGE_THICKNESS);
            // The new port position depends on the new placement
            double portPos = 0;
            if (effectiveSide == LabelSide.ABOVE) {
                portPos = labelDummy.getSize().y - Math.ceil(thickness / 2);
            } else if (effectiveSide == LabelSide.INLINE) {
                // The label dummy has a superfluous label-edge spacing
                labelDummy.getSize().y -= labelDummy.getGraph().getProperty(LayeredOptions.SPACING_EDGE_LABEL);
                portPos = (labelDummy.getSize().y - Math.ceil(thickness)) / 2;
            }
            for (LPort port : labelDummy.getPorts()) {
                port.getPosition().y = portPos;
            }
        }
    }
}
Also used : LabelSide(org.eclipse.elk.core.options.LabelSide) LEdge(org.eclipse.elk.alg.layered.graph.LEdge) LPort(org.eclipse.elk.alg.layered.graph.LPort)

Example 2 with LabelSide

use of org.eclipse.elk.core.options.LabelSide in project elk by eclipse.

the class LabelSideSelector method basedOnDirection.

/**
 * Configures all labels to be placed according to their edge's direction. If their edge points right, the labels
 * will be placed on the side passed to this method. Otherwise, they will be placed on the opposite side.
 */
private void basedOnDirection(final LGraph graph, final LabelSide sideForRightwardEdges) {
    for (Layer layer : graph) {
        for (LNode node : layer) {
            if (node.getType() == NodeType.LABEL) {
                LabelSide side = doesEdgePointRight(node) ? sideForRightwardEdges : sideForRightwardEdges.opposite();
                applyLabelSide(node, side);
            }
            for (LEdge edge : node.getOutgoingEdges()) {
                LabelSide side = doesEdgePointRight(edge) ? sideForRightwardEdges : sideForRightwardEdges.opposite();
                applyLabelSide(edge, side);
            }
        }
    }
}
Also used : LabelSide(org.eclipse.elk.core.options.LabelSide) LEdge(org.eclipse.elk.alg.layered.graph.LEdge) LNode(org.eclipse.elk.alg.layered.graph.LNode) Layer(org.eclipse.elk.alg.layered.graph.Layer)

Example 3 with LabelSide

use of org.eclipse.elk.core.options.LabelSide in project elk by eclipse.

the class LabelSideSelectorTest method testRemovedNodes.

// ////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Tests
/**
 * All labels on ports and edges have an assigned {@link LabelSide}.
 */
@TestAfterProcessor(LabelSideSelector.class)
public void testRemovedNodes(final Object graph) {
    LGraph lGraph = (LGraph) graph;
    lGraph.getLayers().stream().flatMap(layer -> layer.getNodes().stream()).flatMap(node -> Streams.stream(node.getOutgoingEdges())).flatMap(edge -> edge.getLabels().stream()).forEach(label -> assertTrue(label.getProperty(InternalProperties.LABEL_SIDE) != LabelSide.UNKNOWN));
}
Also used : LayoutTestRunner(org.eclipse.elk.alg.test.framework.LayoutTestRunner) ModelResourcePath(org.eclipse.elk.alg.test.framework.io.ModelResourcePath) Algorithm(org.eclipse.elk.alg.test.framework.annotations.Algorithm) RunWith(org.junit.runner.RunWith) Random(java.util.Random) ElkNode(org.eclipse.elk.graph.ElkNode) Deque(java.util.Deque) DefaultConfiguration(org.eclipse.elk.alg.test.framework.annotations.DefaultConfiguration) LayeredOptions(org.eclipse.elk.alg.layered.options.LayeredOptions) AbstractResourcePath(org.eclipse.elk.alg.test.framework.io.AbstractResourcePath) Lists(com.google.common.collect.Lists) InternalProperties(org.eclipse.elk.alg.layered.options.InternalProperties) TestAfterProcessor(org.eclipse.elk.alg.test.framework.annotations.TestAfterProcessor) LabelSide(org.eclipse.elk.core.options.LabelSide) LinkedList(java.util.LinkedList) ElkLabel(org.eclipse.elk.graph.ElkLabel) Assert.assertTrue(org.junit.Assert.assertTrue) Streams(com.google.common.collect.Streams) List(java.util.List) LGraph(org.eclipse.elk.alg.layered.graph.LGraph) FileExtensionFilter(org.eclipse.elk.alg.test.framework.io.FileExtensionFilter) EdgeLabelPlacement(org.eclipse.elk.core.options.EdgeLabelPlacement) ElkEdge(org.eclipse.elk.graph.ElkEdge) Configurator(org.eclipse.elk.alg.test.framework.annotations.Configurator) ElkGraphUtil(org.eclipse.elk.graph.util.ElkGraphUtil) GraphResourceProvider(org.eclipse.elk.alg.test.framework.annotations.GraphResourceProvider) LGraph(org.eclipse.elk.alg.layered.graph.LGraph) TestAfterProcessor(org.eclipse.elk.alg.test.framework.annotations.TestAfterProcessor)

Aggregations

LabelSide (org.eclipse.elk.core.options.LabelSide)3 LEdge (org.eclipse.elk.alg.layered.graph.LEdge)2 Lists (com.google.common.collect.Lists)1 Streams (com.google.common.collect.Streams)1 Deque (java.util.Deque)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Random (java.util.Random)1 LGraph (org.eclipse.elk.alg.layered.graph.LGraph)1 LNode (org.eclipse.elk.alg.layered.graph.LNode)1 LPort (org.eclipse.elk.alg.layered.graph.LPort)1 Layer (org.eclipse.elk.alg.layered.graph.Layer)1 InternalProperties (org.eclipse.elk.alg.layered.options.InternalProperties)1 LayeredOptions (org.eclipse.elk.alg.layered.options.LayeredOptions)1 LayoutTestRunner (org.eclipse.elk.alg.test.framework.LayoutTestRunner)1 Algorithm (org.eclipse.elk.alg.test.framework.annotations.Algorithm)1 Configurator (org.eclipse.elk.alg.test.framework.annotations.Configurator)1 DefaultConfiguration (org.eclipse.elk.alg.test.framework.annotations.DefaultConfiguration)1 GraphResourceProvider (org.eclipse.elk.alg.test.framework.annotations.GraphResourceProvider)1 TestAfterProcessor (org.eclipse.elk.alg.test.framework.annotations.TestAfterProcessor)1