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();
}
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;
}
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);
}
}
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;
}
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;
}
}
}
Aggregations