Search in sources :

Example 1 with LGraph

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

the class LabelAndNodeSizeProcessor method process.

@Override
public void process(final LGraph layeredGraph, final IElkProgressMonitor monitor) {
    monitor.begin("Node and Port Label Placement and Node Sizing", 1);
    NodeDimensionCalculation.calculateLabelAndNodeSizes(LGraphAdapters.adapt(layeredGraph, true, true, node -> node.getType() == NodeType.NORMAL));
    // which is the reason why we haven't handed them to the label and node size processing code
    if (layeredGraph.getProperty(InternalProperties.GRAPH_PROPERTIES).contains(GraphProperties.EXTERNAL_PORTS)) {
        Set<PortLabelPlacement> portLabelPlacement = layeredGraph.getProperty(LayeredOptions.PORT_LABELS_PLACEMENT);
        boolean placeNextToPort = portLabelPlacement.contains(PortLabelPlacement.NEXT_TO_PORT_IF_POSSIBLE);
        boolean treatAsGroup = layeredGraph.getProperty(LayeredOptions.PORT_LABELS_TREAT_AS_GROUP);
        for (Layer layer : layeredGraph.getLayers()) {
            layer.getNodes().stream().filter(node -> node.getType() == NodeType.EXTERNAL_PORT).forEach(dummy -> placeExternalPortDummyLabels(dummy, portLabelPlacement, placeNextToPort, treatAsGroup));
        }
    }
    monitor.done();
}
Also used : NodeDimensionCalculation(org.eclipse.elk.alg.common.nodespacing.NodeDimensionCalculation) GraphProperties(org.eclipse.elk.alg.layered.options.GraphProperties) Layer(org.eclipse.elk.alg.layered.graph.Layer) LLabel(org.eclipse.elk.alg.layered.graph.LLabel) KVector(org.eclipse.elk.core.math.KVector) IElkProgressMonitor(org.eclipse.elk.core.util.IElkProgressMonitor) Set(java.util.Set) ILayoutProcessor(org.eclipse.elk.core.alg.ILayoutProcessor) PortLabelPlacement(org.eclipse.elk.core.options.PortLabelPlacement) LayeredOptions(org.eclipse.elk.alg.layered.options.LayeredOptions) ElkRectangle(org.eclipse.elk.core.math.ElkRectangle) InternalProperties(org.eclipse.elk.alg.layered.options.InternalProperties) LGraph(org.eclipse.elk.alg.layered.graph.LGraph) LPort(org.eclipse.elk.alg.layered.graph.LPort) LGraphAdapters(org.eclipse.elk.alg.layered.graph.LGraphAdapters) LNode(org.eclipse.elk.alg.layered.graph.LNode) NodeType(org.eclipse.elk.alg.layered.graph.LNode.NodeType) PortLabelPlacement(org.eclipse.elk.core.options.PortLabelPlacement) Layer(org.eclipse.elk.alg.layered.graph.Layer)

Example 2 with LGraph

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

the class LabelDummySwitcher method computeLayerWidthSums.

/**
 * Computes an array in which entry i refers to the combined width of layers [0, i]. The combined width is
 * estimated based on the currently estimated layer width and a wild guess as to the layer spacing.
 */
private double[] computeLayerWidthSums(final LabelDummyInfo labelDummyInfo) {
    // The minimum space that we think will be left between
    LGraph lgraph = labelDummyInfo.labelDummy.getGraph();
    double edgeNodeSpacing = lgraph.getProperty(LayeredOptions.SPACING_EDGE_NODE_BETWEEN_LAYERS) * 2;
    double nodeNodeSpacing = lgraph.getProperty(LayeredOptions.SPACING_NODE_NODE_BETWEEN_LAYERS);
    double minSpaceBetweenLayers = Math.max(edgeNodeSpacing, nodeNodeSpacing);
    // The array that will hold the accumulated widths
    double[] layerWidthSums = new double[labelDummyInfo.totalDummyCount()];
    double currentWidthSum = -minSpaceBetweenLayers;
    int currentIndex = 0;
    for (LNode leftDummy : labelDummyInfo.leftLongEdgeDummies) {
        currentWidthSum += layerWidths[leftDummy.getLayer().id] + minSpaceBetweenLayers;
        layerWidthSums[currentIndex++] = currentWidthSum;
    }
    currentWidthSum += layerWidths[labelDummyInfo.labelDummy.getLayer().id] + minSpaceBetweenLayers;
    layerWidthSums[currentIndex++] = currentWidthSum;
    for (LNode rightDummy : labelDummyInfo.rightLongEdgeDummies) {
        currentWidthSum += layerWidths[rightDummy.getLayer().id] + minSpaceBetweenLayers;
        layerWidthSums[currentIndex++] = currentWidthSum;
    }
    return layerWidthSums;
}
Also used : LNode(org.eclipse.elk.alg.layered.graph.LNode) LGraph(org.eclipse.elk.alg.layered.graph.LGraph)

Example 3 with LGraph

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

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

the class ComponentGroupTest method generateGraph.

/**
 * Creates a new layered graph with its external port side connections property set to the
 * given set of connections.
 *
 * @param connections the set of connections.
 * @return the layered graph.
 */
private static LGraph generateGraph(final Set<PortSide> connections) {
    LGraph graph = new LGraph();
    graph.setProperty(InternalProperties.EXT_PORT_CONNECTIONS, connections);
    return graph;
}
Also used : LGraph(org.eclipse.elk.alg.layered.graph.LGraph)

Example 5 with LGraph

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

the class InLayerConstraintProcessorTest method testValidNodeOrder.

// ////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Tests
@TestAfterProcessor(InLayerConstraintProcessor.class)
public void testValidNodeOrder(final Object graph) {
    LGraph lGraph = (LGraph) graph;
    for (Layer layer : lGraph) {
        InLayerConstraint lastConstraint = null;
        for (LNode node : layer) {
            InLayerConstraint currentConstraint = node.getProperty(InternalProperties.IN_LAYER_CONSTRAINT);
            if (lastConstraint != null && currentConstraint != lastConstraint) {
                // if the value changes check valid transitions
                String error = "Invalid constraint transition: " + lastConstraint.name() + " -> " + currentConstraint.name();
                if (currentConstraint == InLayerConstraint.NONE) {
                    assertTrue(error, lastConstraint == InLayerConstraint.TOP);
                } else if (currentConstraint == InLayerConstraint.BOTTOM) {
                    assertTrue(error, lastConstraint == InLayerConstraint.TOP || lastConstraint == InLayerConstraint.NONE);
                }
                lastConstraint = currentConstraint;
            }
            lastConstraint = currentConstraint;
        }
    }
}
Also used : InLayerConstraint(org.eclipse.elk.alg.layered.options.InLayerConstraint) LNode(org.eclipse.elk.alg.layered.graph.LNode) LGraph(org.eclipse.elk.alg.layered.graph.LGraph) Layer(org.eclipse.elk.alg.layered.graph.Layer) TestAfterProcessor(org.eclipse.elk.alg.test.framework.annotations.TestAfterProcessor)

Aggregations

LGraph (org.eclipse.elk.alg.layered.graph.LGraph)115 LNode (org.eclipse.elk.alg.layered.graph.LNode)90 LPort (org.eclipse.elk.alg.layered.graph.LPort)49 Layer (org.eclipse.elk.alg.layered.graph.Layer)38 Test (org.junit.Test)36 TestAfterProcessor (org.eclipse.elk.alg.test.framework.annotations.TestAfterProcessor)19 LEdge (org.eclipse.elk.alg.layered.graph.LEdge)17 KVector (org.eclipse.elk.core.math.KVector)15 InternalProperties (org.eclipse.elk.alg.layered.options.InternalProperties)14 LayeredOptions (org.eclipse.elk.alg.layered.options.LayeredOptions)13 List (java.util.List)11 ILayoutProcessor (org.eclipse.elk.core.alg.ILayoutProcessor)11 IElkProgressMonitor (org.eclipse.elk.core.util.IElkProgressMonitor)10 NodeType (org.eclipse.elk.alg.layered.graph.LNode.NodeType)9 Lists (com.google.common.collect.Lists)7 Set (java.util.Set)7 GraphProperties (org.eclipse.elk.alg.layered.options.GraphProperties)7 GraphInfoHolder (org.eclipse.elk.alg.layered.p3order.GraphInfoHolder)7 PortSide (org.eclipse.elk.core.options.PortSide)7 ElkNode (org.eclipse.elk.graph.ElkNode)7