Search in sources :

Example 11 with LEdge

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

the class LabelSideSelector method doesEdgePointRight.

/**
 * Checks if the given label dummy node is part of an edge segment that will point right in the
 * final drawing. We assume that this is the case if at least one of the incident edges points
 * rightwards according to {@link #doesEdgePointRight(LEdge)}.
 *
 * @param labelDummy the label dummy to check.
 * @return {@code true} if this label dummy node is part of an edge that will point right in the
 *         final drawing.
 */
private boolean doesEdgePointRight(final LNode labelDummy) {
    assert labelDummy.getType() == NodeType.LABEL;
    assert labelDummy.getIncomingEdges().iterator().hasNext();
    assert labelDummy.getOutgoingEdges().iterator().hasNext();
    // Find incoming and outgoing edge
    LEdge incoming = labelDummy.getIncomingEdges().iterator().next();
    LEdge outgoing = labelDummy.getOutgoingEdges().iterator().next();
    return doesEdgePointRight(incoming) || doesEdgePointRight(outgoing);
}
Also used : LEdge(org.eclipse.elk.alg.layered.graph.LEdge)

Example 12 with LEdge

use of org.eclipse.elk.alg.layered.graph.LEdge 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 13 with LEdge

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

the class LayerConstraintPostprocessor method restoreHiddenNodes.

/**
 * Restores nodes hidden by {@link LayerConstraintPreprocessor}.
 */
private void restoreHiddenNodes(final LGraph layeredGraph, final Layer firstSeparateLayer, final Layer lastSeparateLayer) {
    for (LNode hiddenNode : layeredGraph.getProperty(InternalProperties.HIDDEN_NODES)) {
        // Add the node to the appropriate layer
        switch(hiddenNode.getProperty(LayeredOptions.LAYERING_LAYER_CONSTRAINT)) {
            case FIRST_SEPARATE:
                hiddenNode.setLayer(firstSeparateLayer);
                break;
            case LAST_SEPARATE:
                hiddenNode.setLayer(lastSeparateLayer);
                break;
            default:
                // Only *_SEPARATE nodes should be in the list
                assert false;
        }
        // Restore the node's edges
        for (LEdge hiddenEdge : hiddenNode.getConnectedEdges()) {
            // responsible for hiding it. Thus, we may find an edge here that is already restored!
            if (hiddenEdge.getSource() != null && hiddenEdge.getTarget() != null) {
                continue;
            }
            // One end point is the hidden node, the other is null
            boolean isOutgoing = hiddenEdge.getTarget() == null;
            LPort originalOppositePort = hiddenEdge.getProperty(InternalProperties.ORIGINAL_OPPOSITE_PORT);
            if (isOutgoing) {
                hiddenEdge.setTarget(originalOppositePort);
            } else {
                hiddenEdge.setSource(originalOppositePort);
            }
        }
    }
}
Also used : LEdge(org.eclipse.elk.alg.layered.graph.LEdge) LPort(org.eclipse.elk.alg.layered.graph.LPort) LNode(org.eclipse.elk.alg.layered.graph.LNode)

Example 14 with LEdge

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

the class FinalSplineBendpointsCalculator method process.

@Override
public void process(final LGraph graph, final IElkProgressMonitor progressMonitor) {
    this.edgeEdgeSpacing = graph.getProperty(LayeredOptions.SPACING_EDGE_EDGE_BETWEEN_LAYERS);
    this.edgeNodeSpacing = graph.getProperty(LayeredOptions.SPACING_EDGE_NODE_BETWEEN_LAYERS);
    this.splineRoutingMode = graph.getProperty(LayeredOptions.EDGE_ROUTING_SPLINES_MODE);
    this.compactionStrategy = graph.getProperty(LayeredOptions.COMPACTION_POST_COMPACTION_STRATEGY);
    // assign indices to nodes to efficiently query neighbors within the same layer
    indexNodesPerLayer(graph);
    // collect all edges that represent the first segment of a spline
    List<LEdge> startEdges = graph.getLayers().stream().flatMap(l -> l.getNodes().stream()).flatMap(n -> StreamSupport.stream(n.getOutgoingEdges().spliterator(), false)).filter(e -> !e.isSelfLoop()).filter(e -> e.hasProperty(InternalProperties.SPLINE_ROUTE_START)).collect(Collectors.toList());
    // first determine the NUB control points
    for (LEdge e : startEdges) {
        List<SplineSegment> spline = e.getProperty(InternalProperties.SPLINE_ROUTE_START);
        spline.forEach(s -> calculateControlPoints(s));
        e.setProperty(InternalProperties.SPLINE_ROUTE_START, null);
    }
    // ... then convert them to bezier splines
    for (LEdge e : startEdges) {
        // may be null
        LEdge survivingEdge = e.getProperty(InternalProperties.SPLINE_SURVIVING_EDGE);
        List<LEdge> edgeChain = e.getProperty(InternalProperties.SPLINE_EDGE_CHAIN);
        calculateBezierBendPoints(edgeChain, survivingEdge);
        // clear property
        e.setProperty(InternalProperties.SPLINE_EDGE_CHAIN, null);
    }
}
Also used : Layer(org.eclipse.elk.alg.layered.graph.Layer) SplinesMath(org.eclipse.elk.alg.layered.p5edges.splines.SplinesMath) PortSide(org.eclipse.elk.core.options.PortSide) IElkProgressMonitor(org.eclipse.elk.core.util.IElkProgressMonitor) LEdge(org.eclipse.elk.alg.layered.graph.LEdge) ILayoutProcessor(org.eclipse.elk.core.alg.ILayoutProcessor) LayeredOptions(org.eclipse.elk.alg.layered.options.LayeredOptions) KVectorChain(org.eclipse.elk.core.math.KVectorChain) NubSpline(org.eclipse.elk.alg.layered.p5edges.splines.NubSpline) ElkRectangle(org.eclipse.elk.core.math.ElkRectangle) InternalProperties(org.eclipse.elk.alg.layered.options.InternalProperties) StreamSupport(java.util.stream.StreamSupport) Iterator(java.util.Iterator) EdgeInformation(org.eclipse.elk.alg.layered.p5edges.splines.SplineSegment.EdgeInformation) KVector(org.eclipse.elk.core.math.KVector) Collectors(java.util.stream.Collectors) LMargin(org.eclipse.elk.alg.layered.graph.LMargin) GraphCompactionStrategy(org.eclipse.elk.alg.layered.options.GraphCompactionStrategy) HorizontalGraphCompactor(org.eclipse.elk.alg.layered.intermediate.compaction.HorizontalGraphCompactor) ElkMath(org.eclipse.elk.core.math.ElkMath) SplineRoutingMode(org.eclipse.elk.alg.layered.options.SplineRoutingMode) List(java.util.List) SplineEdgeRouter(org.eclipse.elk.alg.layered.p5edges.splines.SplineEdgeRouter) LGraph(org.eclipse.elk.alg.layered.graph.LGraph) LPort(org.eclipse.elk.alg.layered.graph.LPort) LNode(org.eclipse.elk.alg.layered.graph.LNode) SplineSegment(org.eclipse.elk.alg.layered.p5edges.splines.SplineSegment) Collections(java.util.Collections) LEdge(org.eclipse.elk.alg.layered.graph.LEdge) SplineSegment(org.eclipse.elk.alg.layered.p5edges.splines.SplineSegment)

Example 15 with LEdge

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

the class InteractiveExternalPortPositioner method findNorthSouthPortXCoordinate.

private Optional<Double> findNorthSouthPortXCoordinate(final LNode dummy) {
    // external port dummies must have exactly one port
    assert dummy.getPorts().size() == 1;
    LPort port = dummy.getPorts().get(0);
    if (!port.getOutgoingEdges().isEmpty() && !port.getIncomingEdges().isEmpty()) {
        throw new IllegalStateException("Interactive layout does not support " + "NORTH/SOUTH ports with incoming _and_ outgoing edges.");
    }
    if (!port.getOutgoingEdges().isEmpty()) {
        // find the minimum position
        double min = Double.POSITIVE_INFINITY;
        for (LEdge e : port.getOutgoingEdges()) {
            LNode n = e.getTarget().getNode();
            ElkMargin margins = n.getProperty(LayeredOptions.MARGINS);
            min = Math.min(min, n.getPosition().x - margins.left);
        }
        return Optional.of(min);
    }
    if (!port.getIncomingEdges().isEmpty()) {
        // find the maximum value
        double max = Double.NEGATIVE_INFINITY;
        for (LEdge e : port.getIncomingEdges()) {
            LNode n = e.getSource().getNode();
            ElkMargin margins = n.getProperty(LayeredOptions.MARGINS);
            max = Math.max(max, n.getPosition().x + n.getSize().x + margins.right);
        }
        return Optional.of(max);
    }
    // we should never reach here
    return Optional.absent();
}
Also used : LEdge(org.eclipse.elk.alg.layered.graph.LEdge) LPort(org.eclipse.elk.alg.layered.graph.LPort) LNode(org.eclipse.elk.alg.layered.graph.LNode) ElkMargin(org.eclipse.elk.core.math.ElkMargin)

Aggregations

LEdge (org.eclipse.elk.alg.layered.graph.LEdge)148 LNode (org.eclipse.elk.alg.layered.graph.LNode)107 LPort (org.eclipse.elk.alg.layered.graph.LPort)80 Layer (org.eclipse.elk.alg.layered.graph.Layer)41 KVector (org.eclipse.elk.core.math.KVector)34 KVectorChain (org.eclipse.elk.core.math.KVectorChain)20 LLabel (org.eclipse.elk.alg.layered.graph.LLabel)17 LGraph (org.eclipse.elk.alg.layered.graph.LGraph)16 PortSide (org.eclipse.elk.core.options.PortSide)11 ArrayList (java.util.ArrayList)9 List (java.util.List)9 InternalProperties (org.eclipse.elk.alg.layered.options.InternalProperties)8 Set (java.util.Set)7 LayeredOptions (org.eclipse.elk.alg.layered.options.LayeredOptions)7 Map (java.util.Map)6 IElkProgressMonitor (org.eclipse.elk.core.util.IElkProgressMonitor)6 Lists (com.google.common.collect.Lists)5 Iterator (java.util.Iterator)5 ElkRectangle (org.eclipse.elk.core.math.ElkRectangle)5 Pair (org.eclipse.elk.core.util.Pair)5