use of org.eclipse.elk.core.options.PortConstraints in project elk by eclipse.
the class ElkGraphImporter method transformNodes.
/**
* Transforms the nodes and ports defined by the given layout node.
*
* @param parentNode the layout node whose edges to transform.
* @param fgraph the force graph.
* @param elemMap the element map that maps the original {@code KGraph} elements to the
* transformed {@code FGraph} elements.
*/
private void transformNodes(final ElkNode parentNode, final FGraph fgraph, final Map<ElkNode, FNode> elemMap) {
int index = 0;
for (ElkNode knode : parentNode.getChildren()) {
String label = "";
if (!knode.getLabels().isEmpty()) {
label = knode.getLabels().get(0).getText();
}
FNode newNode = new FNode(label);
newNode.copyProperties(knode);
newNode.setProperty(InternalProperties.ORIGIN, knode);
newNode.id = index++;
newNode.getPosition().x = knode.getX() + knode.getWidth() / 2;
newNode.getPosition().y = knode.getY() + knode.getHeight() / 2;
newNode.getSize().x = Math.max(knode.getWidth(), 1);
newNode.getSize().y = Math.max(knode.getHeight(), 1);
fgraph.getNodes().add(newNode);
elemMap.put(knode, newNode);
// port constraints cannot be undefined
PortConstraints portConstraints = knode.getProperty(ForceOptions.PORT_CONSTRAINTS);
if (portConstraints == PortConstraints.UNDEFINED) {
portConstraints = PortConstraints.FREE;
}
// TODO consider ports
}
}
use of org.eclipse.elk.core.options.PortConstraints in project elk by eclipse.
the class ElkUtil method resizeNode.
/**
* Sets the size of a given node, depending on the minimal size, the number of ports
* on each side and the label.
*
* @param node the node that shall be resized
* @return a vector holding the width and height resizing ratio, or {@code null} if the size
* constraint is set to {@code FIXED}
*/
public static KVector resizeNode(final ElkNode node) {
Set<SizeConstraint> sizeConstraint = node.getProperty(CoreOptions.NODE_SIZE_CONSTRAINTS);
if (sizeConstraint.isEmpty()) {
return null;
}
double newWidth = 0, newHeight = 0;
if (sizeConstraint.contains(SizeConstraint.PORTS)) {
PortConstraints portConstraints = node.getProperty(CoreOptions.PORT_CONSTRAINTS);
double minNorth = 2, minEast = 2, minSouth = 2, minWest = 2;
Direction direction = node.getParent() == null ? node.getProperty(CoreOptions.DIRECTION) : node.getParent().getProperty(CoreOptions.DIRECTION);
for (ElkPort port : node.getPorts()) {
PortSide portSide = port.getProperty(CoreOptions.PORT_SIDE);
if (portSide == PortSide.UNDEFINED) {
portSide = calcPortSide(port, direction);
port.setProperty(CoreOptions.PORT_SIDE, portSide);
}
if (portConstraints == PortConstraints.FIXED_POS) {
switch(portSide) {
case NORTH:
minNorth = Math.max(minNorth, port.getX() + port.getWidth());
break;
case EAST:
minEast = Math.max(minEast, port.getY() + port.getHeight());
break;
case SOUTH:
minSouth = Math.max(minSouth, port.getX() + port.getWidth());
break;
case WEST:
minWest = Math.max(minWest, port.getY() + port.getHeight());
break;
}
} else {
switch(portSide) {
case NORTH:
minNorth += port.getWidth() + 2;
break;
case EAST:
minEast += port.getHeight() + 2;
break;
case SOUTH:
minSouth += port.getWidth() + 2;
break;
case WEST:
minWest += port.getHeight() + 2;
break;
}
}
}
newWidth = Math.max(minNorth, minSouth);
newHeight = Math.max(minEast, minWest);
}
return resizeNode(node, newWidth, newHeight, true, true);
}
use of org.eclipse.elk.core.options.PortConstraints in project elk by eclipse.
the class RandomGraphGenerator method createNode.
/**
* Creates a node.
*
* @param parent
* the parent node
* @return the node
*/
private ElkNode createNode(final ElkNode parent) {
ElkNode node = ElkGraphUtil.createNode(null);
float hypernodeChance = get(GeneratorOptions.HYPERNODE_CHANCE);
if (hypernodeChance > 0.0f && random.nextFloat() < hypernodeChance) {
node.setProperty(CoreOptions.HYPERNODE, true);
}
// create label and identifier
String nodeid = String.valueOf(nodeLabelCounter++);
if (get(GeneratorOptions.CREATE_NODE_LABELS)) {
ElkGraphUtil.createLabel("N" + nodeid, node);
}
node.setIdentifier("n" + nodeid);
// set size of the node
if (get(GeneratorOptions.SET_NODE_SIZE)) {
node.setWidth(get(GeneratorOptions.NODE_WIDTH).floatVal(random));
node.setHeight(get(GeneratorOptions.NODE_HEIGHT).floatVal(random));
}
// set port constraints
PortConstraints portConstraints = get(GeneratorOptions.PORT_CONSTRAINTS);
if (portConstraints != PortConstraints.UNDEFINED) {
node.setProperty(CoreOptions.PORT_CONSTRAINTS, portConstraints);
}
parent.getChildren().add(node);
return node;
}
Aggregations