use of org.eclipse.elk.alg.layered.graph.LLabel in project elk by eclipse.
the class ElkGraphImporter method transformLabel.
// /////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Label Transformation
/**
* Transform the given {@code ElkLabel} into an {@code LLabel}.
*
* @param elklabel the label to transform.
* @return the created {@code LLabel}.
*/
private LLabel transformLabel(final ElkLabel elklabel) {
LLabel newLabel = new LLabel(elklabel.getText());
newLabel.copyProperties(elklabel);
newLabel.setProperty(InternalProperties.ORIGIN, elklabel);
newLabel.getSize().x = elklabel.getWidth();
newLabel.getSize().y = elklabel.getHeight();
newLabel.getPosition().x = elklabel.getX();
newLabel.getPosition().y = elklabel.getY();
return newLabel;
}
use of org.eclipse.elk.alg.layered.graph.LLabel in project elk by eclipse.
the class EndLabelPreprocessor method createConfiguredLabelCell.
/**
* Creates label cell for the given port with the given labels, if any. If there are no labels, this method returns
* {@code null}. The label cell will still have to have its alignment set up, but its size is already set to the
* size required to place its labels.
*/
private LabelCell createConfiguredLabelCell(final List<LLabel> labels, final double labelLabelSpacing, final boolean verticalLayout) {
if (labels == null || labels.isEmpty()) {
return null;
}
// Create the new label cell and setup its alignments depending on the port's side
LabelCell labelCell = new LabelCell(labelLabelSpacing, !verticalLayout);
for (LLabel label : labels) {
labelCell.addLabel(LGraphAdapters.adapt(label));
}
// Setup the label cell's size
ElkRectangle labelCellRect = labelCell.getCellRectangle();
labelCellRect.height = labelCell.getMinimumHeight();
labelCellRect.width = labelCell.getMinimumWidth();
return labelCell;
}
use of org.eclipse.elk.alg.layered.graph.LLabel in project elk by eclipse.
the class EndLabelPreprocessor method gatherLabels.
/**
* Returns a list that contains all end labels to be placed at the given port. If there are no such labels, the
* list will be empty. If there are not even any edges connected to the port, the return value will be {@code null}.
*
* <p>his method also takes care of north / south ports whose original edges have been rerouted to a north / south
* port dummy. The maximum thickness of any edge connected to the port is saved
* {@link InternalProperties#MAX_EDGE_THICKNESS as a property} if it has labels.</p>
*
* <p>This method is also used by {@link LabelSideSelector}.</p>
*/
static List<LLabel> gatherLabels(final LPort port) {
List<LLabel> labels = Lists.newArrayList();
// Gather labels of the port itself
double maxEdgeThickness = gatherLabels(port, labels);
// If it has a dummy associated with it, we need to go through the dummy's ports and process those that were
// created for the current port (see the NorthSouthPortPreprocessor)
LNode dummyNode = port.getProperty(InternalProperties.PORT_DUMMY);
if (dummyNode != null) {
for (LPort dummyPort : dummyNode.getPorts()) {
if (dummyPort.getProperty(InternalProperties.ORIGIN) == port) {
maxEdgeThickness = Math.max(maxEdgeThickness, gatherLabels(dummyPort, labels));
}
}
}
// Only save the maximum edge thickness if we'll be interested in it later
if (!labels.isEmpty()) {
port.setProperty(InternalProperties.MAX_EDGE_THICKNESS, maxEdgeThickness);
}
return maxEdgeThickness != NO_INCIDENT_EDGE_THICKNESS ? labels : null;
}
use of org.eclipse.elk.alg.layered.graph.LLabel in project elk by eclipse.
the class EndLabelPreprocessor method gatherLabels.
/**
* Puts all relevant end labels of edges connected to the given port into the given list. Returns the maximum edge
* thickness of any incident edge or {@link #NO_INCIDENT_EDGE_THICKNESS} if there is no incident edge.
*/
private static double gatherLabels(final LPort port, final List<LLabel> targetList) {
double maxEdgeThickness = -1;
List<LLabel> labels = new LinkedList<>();
for (LEdge incidentEdge : port.getConnectedEdges()) {
maxEdgeThickness = Math.max(maxEdgeThickness, incidentEdge.getProperty(LayeredOptions.EDGE_THICKNESS));
if (incidentEdge.getSource() == port) {
// It's an outgoing edge; all tail labels belong to this port
incidentEdge.getLabels().stream().filter(label -> label.getProperty(LayeredOptions.EDGE_LABELS_PLACEMENT) == EdgeLabelPlacement.TAIL).forEach(label -> labels.add(label));
} else {
// It's an incoming edge; all head labels belong to this port
incidentEdge.getLabels().stream().filter(label -> label.getProperty(LayeredOptions.EDGE_LABELS_PLACEMENT) == EdgeLabelPlacement.HEAD).forEach(label -> labels.add(label));
}
// Remember the edge each label came from
for (LLabel label : labels) {
if (!label.hasProperty(InternalProperties.END_LABEL_EDGE)) {
label.setProperty(InternalProperties.END_LABEL_EDGE, incidentEdge);
}
}
targetList.addAll(labels);
labels.clear();
}
return maxEdgeThickness;
}
use of org.eclipse.elk.alg.layered.graph.LLabel in project elk by eclipse.
the class GraphTransformer method transpose.
// /////////////////////////////////////////////////////////////////////////////
// Transpose
/**
* Transpose the x and y coordinates of the given graph.
*
* @param nodes the nodes of the graph to transpose
*/
private void transpose(final List<LNode> nodes) {
// Transpose nodes
for (LNode node : nodes) {
transpose(node.getPosition());
transpose(node.getSize());
transpose(node.getPadding());
transposeNodeLabelPlacement(node);
transposeProperties(node);
// Transpose ports
for (LPort port : node.getPorts()) {
transpose(port.getPosition());
transpose(port.getAnchor());
transpose(port.getSize());
transposePortSide(port);
reverseIndex(port);
// Transpose edges
for (LEdge edge : port.getOutgoingEdges()) {
// Transpose bend points
for (KVector bendPoint : edge.getBendPoints()) {
transpose(bendPoint);
}
// Transpose junction points
KVectorChain junctionPoints = edge.getProperty(LayeredOptions.JUNCTION_POINTS);
if (junctionPoints != null) {
for (KVector jp : junctionPoints) {
transpose(jp);
}
}
// Transpose edge labels
for (LLabel label : edge.getLabels()) {
transpose(label.getPosition());
transpose(label.getSize());
}
}
// Transpose port labels
for (LLabel label : port.getLabels()) {
transpose(label.getPosition());
transpose(label.getSize());
}
}
// External port dummy?
if (node.getType() == NodeType.EXTERNAL_PORT) {
transposeExternalPortSide(node);
transposeLayerConstraint(node);
}
// Transpose node labels
for (LLabel label : node.getLabels()) {
transposeNodeLabelPlacement(label);
transpose(label.getSize());
transpose(label.getPosition());
}
}
}
Aggregations