use of org.eclipse.elk.alg.layered.graph.LLabel in project elk by eclipse.
the class GraphTransformer method mirrorX.
// /////////////////////////////////////////////////////////////////////////////
// Mirror Horizontally
/**
* Mirror the x coordinates of the given graph.
*
* @param nodes the nodes of the graph to transpose
* @param graph the graph the nodes are part of
*/
private void mirrorX(final List<LNode> nodes, final LGraph graph) {
/* Assuming that no nodes extend into negative x coordinates, mirroring a node means that the
* space left to its left border equals the space right to its right border when mirrored. In
* mathematical terms:
* oldPosition.x = graphWidth - newPosition.x - nodeWidth
* We use the offset variable to store graphWidth, since that's the constant offset against which
* we calculate the new node positions.
* This, however, stops to work once nodes are allowed to extend into negative coordinates. Then,
* we have to subtract from the graphWidth the amount of space the graph extends into negative
* coordinates. This amount is saved in the graph's graphOffset. Thus, our offset here becomes:
* offset = graphWidth - graphOffset.x
*/
double offset = 0;
// over its nodes
if (graph.getSize().x == 0) {
for (LNode node : nodes) {
offset = Math.max(offset, node.getPosition().x + node.getSize().x + node.getMargin().right);
}
} else {
offset = graph.getSize().x - graph.getOffset().x;
}
offset -= graph.getOffset().x;
// mirror all nodes, ports, edges, and labels
for (LNode node : nodes) {
mirrorX(node.getPosition(), offset - node.getSize().x);
mirrorX(node.getPadding());
mirrorNodeLabelPlacementX(node);
// mirror position
if (node.getAllProperties().containsKey(LayeredOptions.POSITION)) {
mirrorX(node.getProperty(LayeredOptions.POSITION), offset - node.getSize().x);
}
// mirror the alignment
switch(node.getProperty(LayeredOptions.ALIGNMENT)) {
case LEFT:
node.setProperty(LayeredOptions.ALIGNMENT, Alignment.RIGHT);
break;
case RIGHT:
node.setProperty(LayeredOptions.ALIGNMENT, Alignment.LEFT);
break;
}
KVector nodeSize = node.getSize();
for (LPort port : node.getPorts()) {
mirrorX(port.getPosition(), nodeSize.x - port.getSize().x);
mirrorX(port.getAnchor(), port.getSize().x);
mirrorPortSideX(port);
reverseIndex(port);
for (LEdge edge : port.getOutgoingEdges()) {
// Mirror bend points
for (KVector bendPoint : edge.getBendPoints()) {
mirrorX(bendPoint, offset);
}
// Mirror junction points
KVectorChain junctionPoints = edge.getProperty(LayeredOptions.JUNCTION_POINTS);
if (junctionPoints != null) {
for (KVector jp : junctionPoints) {
mirrorX(jp, offset);
}
}
// Mirror edge label positions
for (LLabel label : edge.getLabels()) {
mirrorX(label.getPosition(), offset - label.getSize().x);
}
}
// Mirror port label positions
for (LLabel label : port.getLabels()) {
mirrorX(label.getPosition(), port.getSize().x - label.getSize().x);
}
}
// External port dummy?
if (node.getType() == NodeType.EXTERNAL_PORT) {
mirrorExternalPortSideX(node);
mirrorLayerConstraintX(node);
}
// Mirror node labels
for (LLabel label : node.getLabels()) {
mirrorNodeLabelPlacementX(label);
mirrorX(label.getPosition(), nodeSize.x - label.getSize().x);
}
}
}
use of org.eclipse.elk.alg.layered.graph.LLabel in project elk by eclipse.
the class GraphTransformer method mirrorY.
// /////////////////////////////////////////////////////////////////////////////
// Mirror Vertically
/**
* Mirror the y coordinates of the given graph.
*
* @param nodes the nodes of the graph to transpose
* @param graph the graph the nodes are part of
*/
private void mirrorY(final List<LNode> nodes, final LGraph graph) {
// See mirrorX for an explanation of how the offset is calculated
double offset = 0;
if (graph.getSize().y == 0) {
for (LNode node : nodes) {
offset = Math.max(offset, node.getPosition().y + node.getSize().y + node.getMargin().bottom);
}
} else {
offset = graph.getSize().y - graph.getOffset().y;
}
offset -= graph.getOffset().y;
// mirror all nodes, ports, edges, and labels
for (LNode node : nodes) {
mirrorY(node.getPosition(), offset - node.getSize().y);
mirrorY(node.getPadding());
mirrorNodeLabelPlacementY(node);
// mirror position
if (node.getAllProperties().containsKey(LayeredOptions.POSITION)) {
mirrorY(node.getProperty(LayeredOptions.POSITION), offset - node.getSize().y);
}
// mirror the alignment
switch(node.getProperty(LayeredOptions.ALIGNMENT)) {
case TOP:
node.setProperty(LayeredOptions.ALIGNMENT, Alignment.BOTTOM);
break;
case BOTTOM:
node.setProperty(LayeredOptions.ALIGNMENT, Alignment.TOP);
break;
}
KVector nodeSize = node.getSize();
for (LPort port : node.getPorts()) {
mirrorY(port.getPosition(), nodeSize.y - port.getSize().y);
mirrorY(port.getAnchor(), port.getSize().y);
mirrorPortSideY(port);
reverseIndex(port);
for (LEdge edge : port.getOutgoingEdges()) {
// Mirror bend points
for (KVector bendPoint : edge.getBendPoints()) {
mirrorY(bendPoint, offset);
}
// Mirror junction points
KVectorChain junctionPoints = edge.getProperty(LayeredOptions.JUNCTION_POINTS);
if (junctionPoints != null) {
for (KVector jp : junctionPoints) {
mirrorY(jp, offset);
}
}
// Mirror edge label positions
for (LLabel label : edge.getLabels()) {
mirrorY(label.getPosition(), offset - label.getSize().y);
}
}
// Mirror port label positions
for (LLabel label : port.getLabels()) {
mirrorY(label.getPosition(), port.getSize().y - label.getSize().y);
}
}
// External port dummy?
if (node.getType() == NodeType.EXTERNAL_PORT) {
mirrorExternalPortSideY(node);
mirrorInLayerConstraintY(node);
}
// Mirror node labels
for (LLabel label : node.getLabels()) {
mirrorNodeLabelPlacementY(label);
mirrorY(label.getPosition(), nodeSize.y - label.getSize().y);
}
}
}
use of org.eclipse.elk.alg.layered.graph.LLabel in project elk by eclipse.
the class EndLabelSorterTest method testNode.
private void testNode(final LNode node) {
switch(node.getType()) {
case NORMAL:
// Build a list of label strings that we can check
if (node.hasProperty(InternalProperties.END_LABELS)) {
for (LabelCell labelCell : node.getProperty(InternalProperties.END_LABELS).values()) {
List<String> labelStrings = labelCell.getLabels().stream().map(label -> label.getText()).collect(Collectors.toList());
failIfUnsorted(labelStrings);
}
}
break;
case LABEL:
List<LLabel> labels = node.getProperty(InternalProperties.REPRESENTED_LABELS);
assertNotNull(labels);
List<String> labelStrings = labels.stream().map(label -> label.getText()).collect(Collectors.toList());
failIfUnsorted(labelStrings);
break;
}
}
use of org.eclipse.elk.alg.layered.graph.LLabel in project elk by eclipse.
the class NetworkSimplexPlacer method applyPositions.
// ------------------------------------------------------------------------------------------------
// Apply Layout
// ------------------------------------------------------------------------------------------------
private void applyPositions() {
for (Layer l : lGraph) {
for (LNode lNode : l) {
// find the node's corners
NodeRep nodeRep = nodeReps[lNode.id];
double minY = nodeRep.head.layer;
double maxY = nodeRep.tail.layer;
// set new position and size
lNode.getPosition().y = minY;
double sizeDelta = (maxY - minY) - lNode.getSize().y;
boolean flexibleNode = isFlexibleNode(lNode);
NodeFlexibility nf = getNodeFlexibility(lNode);
// modify the size?
if (flexibleNode && nf.isFlexibleSizeWhereSpacePermits()) {
lNode.getSize().y += sizeDelta;
}
// reposition ports if allowed
if (flexibleNode && nf.isFlexiblePorts()) {
for (LPort p : lNode.getPorts()) {
if (PortSide.SIDES_EAST_WEST.contains(p.getSide())) {
NNode nNode = portMap.get(p);
p.getPosition().y = nNode.layer - minY;
}
}
// when the node got resized, the positions of labels and south ports have to be adjusted
for (LLabel label : lNode.getLabels()) {
adjustLabelPosition(lNode, label, sizeDelta);
}
if (nf.isFlexibleSizeWhereSpacePermits()) {
lNode.getPortSideView(PortSide.SOUTH).forEach(p -> p.getPosition().y += sizeDelta);
}
}
}
}
}
use of org.eclipse.elk.alg.layered.graph.LLabel in project elk by eclipse.
the class ElkGraphImporter method transformExternalPort.
/**
* Transforms the given external port into a dummy node.
*
* @param elkgraph
* the original KGraph
* @param lgraph
* the corresponding layered graph
* @param elkport
* the port to be transformed
*/
private void transformExternalPort(final ElkNode elkgraph, final LGraph lgraph, final ElkPort elkport) {
// We need some information about the port
KVector elkportPosition = new KVector(elkport.getX() + elkport.getWidth() / 2.0, elkport.getY() + elkport.getHeight() / 2.0);
int netFlow = calculateNetFlow(elkport);
PortConstraints portConstraints = elkgraph.getProperty(LayeredOptions.PORT_CONSTRAINTS);
// If we don't have a proper port side, calculate one
PortSide portSide = elkport.getProperty(LayeredOptions.PORT_SIDE);
assert portSide != PortSide.UNDEFINED;
// If we don't have a port offset, infer one
if (!elkport.getAllProperties().containsKey(LayeredOptions.PORT_BORDER_OFFSET)) {
double portOffset;
// if port coordinates are (0,0), we default to port offset 0 to make the common case frustration-free
if (elkport.getX() == 0.0 && elkport.getY() == 0.0) {
portOffset = 0.0;
} else {
portOffset = ElkUtil.calcPortOffset(elkport, portSide);
}
elkport.setProperty(LayeredOptions.PORT_BORDER_OFFSET, portOffset);
}
// Create the external port dummy node
KVector graphSize = new KVector(elkgraph.getWidth(), elkgraph.getHeight());
LNode dummy = LGraphUtil.createExternalPortDummy(elkport, portConstraints, portSide, netFlow, graphSize, elkportPosition, new KVector(elkport.getWidth(), elkport.getHeight()), lgraph.getProperty(LayeredOptions.DIRECTION), lgraph);
dummy.setProperty(InternalProperties.ORIGIN, elkport);
// The dummy only has one port
LPort dummyPort = dummy.getPorts().get(0);
dummyPort.setConnectedToExternalNodes(isConnectedToExternalNodes(elkport));
dummy.setProperty(LayeredOptions.PORT_LABELS_PLACEMENT, PortLabelPlacement.outside());
// If the compound node wants to have its port labels placed on the inside, we need to leave
// enough space for them by creating an LLabel for the KLabels. If the compound node wants to
// have its port labels placed on the outside, we still need to leave enough space for them
// so the port placement does not cause problems on the outside, but we also don't want to waste
// space inside. Thus, for east and west ports, we reduce the label width to zero, otherwise
// we reduce the label height to zero
boolean insidePortLabels = elkgraph.getProperty(LayeredOptions.PORT_LABELS_PLACEMENT).contains(PortLabelPlacement.INSIDE);
// Transform all of the port's labels
for (ElkLabel elklabel : elkport.getLabels()) {
if (!elklabel.getProperty(LayeredOptions.NO_LAYOUT) && !Strings.isNullOrEmpty(elklabel.getText())) {
LLabel llabel = transformLabel(elklabel);
dummyPort.getLabels().add(llabel);
// If the port labels are fixed, we should consider the part that is inside the node and not 0.
if (!insidePortLabels) {
double insidePart = 0;
if (PortLabelPlacement.isFixed(elkgraph.getProperty(LayeredOptions.PORT_LABELS_PLACEMENT))) {
// We use 0 as port border offset here, as we only want the label part that is
// inside the node "after" the port.
insidePart = ElkUtil.computeInsidePart(new KVector(elklabel.getX(), elklabel.getY()), new KVector(elklabel.getWidth(), elklabel.getHeight()), new KVector(elkport.getWidth(), elkport.getHeight()), 0, portSide);
}
switch(portSide) {
case EAST:
case WEST:
llabel.getSize().x = insidePart;
break;
case NORTH:
case SOUTH:
llabel.getSize().y = insidePart;
break;
}
}
}
}
// Remember the relevant spacings that will apply to the labels here. It's not the spacings in the graph, but
// in the parent
dummy.setProperty(LayeredOptions.SPACING_LABEL_PORT, elkgraph.getParent().getProperty(LayeredOptions.SPACING_LABEL_PORT));
dummy.setProperty(LayeredOptions.SPACING_LABEL_LABEL, elkgraph.getParent().getProperty(LayeredOptions.SPACING_LABEL_LABEL));
// Put the external port dummy into our graph and associate it with the original KPort
lgraph.getLayerlessNodes().add(dummy);
nodeAndPortMap.put(elkport, dummy);
}
Aggregations