use of org.eclipse.elk.core.math.ElkMargin in project elk by eclipse.
the class NetworkSimplexPlacer method transformPorts.
private void transformPorts(final Iterable<LPort> ports, final NodeRep corners) {
if (Iterables.isEmpty(ports)) {
// the top and bottom border of the node are already safely spaced apart
return;
}
final double portSpacing = Spacings.getIndividualOrDefault(corners.origin, LayeredOptions.SPACING_PORT_PORT);
ElkMargin portSurrounding = Spacings.getIndividualOrDefault(corners.origin, LayeredOptions.SPACING_PORTS_SURROUNDING);
if (portSurrounding == null) {
// No additional port spacing set
portSurrounding = new ElkMargin();
}
NNode lastNNode = corners.head;
LPort lastPort = null;
for (LPort port : ports) {
// spacing between the current pair of ports (or to the top border of the node)
double spacing = 0;
if (lastPort == null) {
spacing = portSurrounding.top;
} else {
spacing = portSpacing;
spacing += lastPort.getSize().y;
// TODO only if PORT_LABELS is set?
// + lastPort.getMargin().bottom
// + port.getMargin().top;
}
// create NNode for the port
NNode nNode = NNode.of().origin(port).type("port").create(nGraph);
portMap.put(port, nNode);
// connect with previous NNode
NEdge.of().weight(0).delta((int) Math.ceil(spacing)).source(lastNNode).target(nNode).create();
lastPort = port;
lastNNode = nNode;
}
// and connect to the bottom border
NEdge.of().weight(0).delta((int) Math.ceil(portSurrounding.bottom + lastPort.getSize().y)).source(lastNNode).target(corners.tail).create();
}
use of org.eclipse.elk.core.math.ElkMargin in project elk by eclipse.
the class InteractiveExternalPortPositioner method process.
@Override
public void process(final LGraph layeredGraph, final IElkProgressMonitor progressMonitor) {
// if the graph does not contain any external ports ...
if (!layeredGraph.getProperty(InternalProperties.GRAPH_PROPERTIES).contains(GraphProperties.EXTERNAL_PORTS)) {
// ... nothing we can do about it
return;
}
// find the minimum and maximum x coordinates of the graph
for (LNode node : layeredGraph.getLayerlessNodes()) {
if (node.getType() == NodeType.NORMAL) {
ElkMargin margins = node.getProperty(LayeredOptions.MARGINS);
minX = Math.min(minX, node.getPosition().x - margins.left);
maxX = Math.max(maxX, node.getPosition().x + node.getSize().x + margins.right);
minY = Math.min(minY, node.getPosition().y - margins.top);
maxY = Math.max(maxY, node.getPosition().y + node.getSize().y + margins.bottom);
}
}
// assign reasonable coordinates to external port dummies
for (LNode node : layeredGraph.getLayerlessNodes()) {
if (node.getType() != NodeType.NORMAL) {
switch(node.getType()) {
// SUPPRESS CHECKSTYLE NEXT 50 InnerAssignment
case EXTERNAL_PORT:
LayerConstraint lc = node.getProperty(LayeredOptions.LAYERING_LAYER_CONSTRAINT);
if (lc == LayerConstraint.FIRST_SEPARATE) {
// it's a WEST port
node.getPosition().x = minX - ARBITRARY_SPACING;
findYCoordinate(node, (e) -> e.getTarget().getNode()).transform((d) -> node.getPosition().y = d);
break;
}
if (lc == LayerConstraint.LAST_SEPARATE) {
// it's a EAST port
node.getPosition().x = maxX + ARBITRARY_SPACING;
findYCoordinate(node, (e) -> e.getSource().getNode()).transform((d) -> node.getPosition().y = d);
break;
}
InLayerConstraint ilc = node.getProperty(InternalProperties.IN_LAYER_CONSTRAINT);
if (ilc == InLayerConstraint.TOP) {
findNorthSouthPortXCoordinate(node).transform((x) -> node.getPosition().x = x + ARBITRARY_SPACING);
node.getPosition().y = minY - ARBITRARY_SPACING;
break;
}
if (ilc == InLayerConstraint.BOTTOM) {
findNorthSouthPortXCoordinate(node).transform((x) -> node.getPosition().x = x + ARBITRARY_SPACING);
node.getPosition().y = maxY + ARBITRARY_SPACING;
break;
}
break;
default:
throw new IllegalArgumentException("The node type " + node.getType() + " is not supported by the " + this.getClass());
}
}
}
}
use of org.eclipse.elk.core.math.ElkMargin in project elk by eclipse.
the class LayoutMetaDataService method initElkReflect.
/**
* Registers all basic data types with {@link ElkReflect}. This method should only be called from the outside if
* layout algorithms are supposed to be called directly, which we don't recommend.
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
public static void initElkReflect() {
// every class that implements IDataObject
// or is used for internal properties must be registered here
// IDataObject
ElkReflect.register(KVector.class, () -> new KVector(), (v) -> ((KVector) v).clone());
ElkReflect.register(KVectorChain.class, () -> new KVectorChain(), (vc) -> new KVectorChain((KVectorChain) vc));
ElkReflect.register(ElkMargin.class, () -> new ElkMargin(), (m) -> new ElkMargin((ElkMargin) m));
ElkReflect.register(ElkPadding.class, () -> new ElkPadding(), (p) -> new ElkPadding((ElkPadding) p));
ElkReflect.register(IndividualSpacings.class, () -> new IndividualSpacings(), (is) -> new IndividualSpacings((IndividualSpacings) is));
// Commonly used classes for internal properties
ElkReflect.register(ArrayList.class, () -> new ArrayList(), (al) -> ((ArrayList) al).clone());
ElkReflect.register(LinkedList.class, () -> new LinkedList(), (ll) -> Lists.newLinkedList((LinkedList) ll));
ElkReflect.register(HashSet.class, () -> new HashSet(), (hs) -> Sets.newHashSet((HashSet) hs));
ElkReflect.register(LinkedHashSet.class, () -> new LinkedHashSet(), (hs) -> Sets.newLinkedHashSet((HashSet) hs));
ElkReflect.register(TreeSet.class, () -> new TreeSet(), (ts) -> Sets.newTreeSet((TreeSet) ts));
}
Aggregations