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