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