use of org.eclipse.elk.graph.ElkPort in project elk by eclipse.
the class StraightLineEdgeRouter method routeEdges.
/**
* Route edges from node center to node center. Then clip it, to not cross the node.
*/
public void routeEdges(final ElkNode node) {
for (ElkEdge edge : ElkGraphUtil.allOutgoingEdges(node)) {
if (!(edge.getSources().get(0) instanceof ElkPort)) {
ElkNode target = ElkGraphUtil.connectableShapeToNode(edge.getTargets().get(0));
if (!edge.isHierarchical()) {
double sourceX = node.getX() + node.getWidth() / 2;
double sourceY = node.getY() + node.getHeight() / 2;
double targetX = target.getX() + target.getWidth() / 2;
double targetY = target.getY() + target.getHeight() / 2;
// Clipping
KVector vector = new KVector();
vector.x = targetX - sourceX;
vector.y = targetY - sourceY;
KVector sourceClip = new KVector(vector.x, vector.y);
ElkMath.clipVector(sourceClip, node.getWidth(), node.getHeight());
vector.x -= sourceClip.x;
vector.y -= sourceClip.y;
sourceX = targetX - vector.x;
sourceY = targetY - vector.y;
KVector targetClip = new KVector(vector.x, vector.y);
ElkMath.clipVector(targetClip, target.getWidth(), target.getHeight());
vector.x -= targetClip.x;
vector.y -= targetClip.y;
targetX = sourceX + vector.x;
targetY = sourceY + vector.y;
ElkEdgeSection section = ElkGraphUtil.firstEdgeSection(edge, true, true);
section.setStartLocation(sourceX, sourceY);
section.setEndLocation(targetX, targetY);
routeEdges(target);
}
}
}
}
use of org.eclipse.elk.graph.ElkPort in project elk by eclipse.
the class RadialUtil method getSuccessors.
/**
* The nodes which succedes the given node in the tree. These are defined by the targets of all outgoing edges of
* the node.
*
* @param node
* A node.
* @return List of neighbors with outgoing edges.
*/
public static List<ElkNode> getSuccessors(final ElkNode node) {
List<ElkNode> successors = new ArrayList<>();
HashSet<ElkNode> children = new HashSet<ElkNode>(node.getChildren());
for (ElkEdge outgoingEdge : ElkGraphUtil.allOutgoingEdges(node)) {
if (!(outgoingEdge.getSources().get(0) instanceof ElkPort)) {
ElkNode target = ElkGraphUtil.connectableShapeToNode(outgoingEdge.getTargets().get(0));
if (!children.contains(target)) {
successors.add(target);
}
}
}
return successors;
}
use of org.eclipse.elk.graph.ElkPort in project elk by eclipse.
the class GraphRenderer method renderNodeChildren.
/**
* Paints all children of the given parent node that fall into the given dirty area.
*
* @param parent the node whose children to paint
* @param graphics the graphics context used to paint
* @param area dirty area that needs painting
* @param offset offset to be added to relative coordinates
* @param nodeAlpha alpha value for nodes
*/
private void renderNodeChildren(final ElkNode parent, final GC graphics, final Rectangle area, final KVector offset, final int nodeAlpha) {
for (ElkNode childNode : parent.getChildren()) {
PaintRectangle rect = boundsMap.get(childNode);
if (rect == null) {
rect = new PaintRectangle(childNode, offset, scale);
boundsMap.put(childNode, rect);
}
KVector childOffset = new KVector(rect.x, rect.y);
// render the child node and its content
if (!rect.painted && rect.intersects(area)) {
// paint this node
graphics.setAlpha(nodeAlpha);
if (configurator.getNodeFillColor() != null) {
graphics.setBackground(configurator.getNodeFillColor());
graphics.fillRectangle(rect.x, rect.y, rect.width, rect.height);
}
if (configurator.getNodeBorderColor() != null) {
graphics.setForeground(configurator.getNodeBorderColor());
graphics.drawRectangle(rect.x, rect.y, rect.width, rect.height);
}
rect.painted = true;
renderNodeChildren(childNode, graphics, area, childOffset, nodeAlpha);
}
// render node labels
if (configurator.getNodeLabelFont() != null) {
graphics.setFont(configurator.getNodeLabelFont());
for (ElkLabel label : childNode.getLabels()) {
renderLabel(label, graphics, area, childOffset, nodeAlpha);
}
}
// render ports
for (ElkPort port : childNode.getPorts()) {
renderPort(port, graphics, area, childOffset, nodeAlpha);
}
}
// Paint the edges contained in this node
for (ElkEdge childEdge : parent.getContainedEdges()) {
renderEdge(childEdge, graphics, area, offset, nodeAlpha);
}
}
use of org.eclipse.elk.graph.ElkPort in project elk by eclipse.
the class AllowNonFlowPortsToSwitchSidesTest method createSimpleGraph.
/**
* Create a simple test graph.
*
* Note that port positions are set for the test case FIXED_POS.
*/
private static ElkNode createSimpleGraph(final PortConstraints portConstraints, final boolean node1MaySwitchPortSides, final boolean node2MaySwitchPortSides) {
ElkNode graph = ElkGraphUtil.createGraph();
ElkNode node1 = ElkGraphUtil.createNode(graph);
node1.setWidth(30);
node1.setHeight(30);
node1.setProperty(LayeredOptions.PORT_CONSTRAINTS, portConstraints);
ElkPort portNorth1 = ElkGraphUtil.createPort(node1);
portNorth1.setX(15.0);
portNorth1.setY(-1.0);
portNorth1.setProperty(LayeredOptions.PORT_SIDE, PortSide.NORTH);
portNorth1.setProperty(LayeredOptions.ALLOW_NON_FLOW_PORTS_TO_SWITCH_SIDES, node1MaySwitchPortSides);
ElkPort portSouth1 = ElkGraphUtil.createPort(node1);
portSouth1.setX(15.0);
portSouth1.setY(30.0);
portSouth1.setProperty(LayeredOptions.PORT_SIDE, PortSide.SOUTH);
portSouth1.setProperty(LayeredOptions.ALLOW_NON_FLOW_PORTS_TO_SWITCH_SIDES, node1MaySwitchPortSides);
ElkNode node2 = ElkGraphUtil.createNode(graph);
node2.setWidth(30);
node2.setHeight(30);
node2.setProperty(LayeredOptions.PORT_CONSTRAINTS, portConstraints);
ElkPort portNorth2 = ElkGraphUtil.createPort(node2);
portNorth2.setX(15.0);
portNorth2.setY(-1.0);
portNorth2.setProperty(LayeredOptions.PORT_SIDE, PortSide.NORTH);
portNorth2.setProperty(LayeredOptions.ALLOW_NON_FLOW_PORTS_TO_SWITCH_SIDES, node2MaySwitchPortSides);
ElkPort portSouth2 = ElkGraphUtil.createPort(node2);
portSouth2.setX(15.0);
portSouth2.setY(30.0);
portSouth2.setProperty(LayeredOptions.PORT_SIDE, PortSide.SOUTH);
portSouth2.setProperty(LayeredOptions.ALLOW_NON_FLOW_PORTS_TO_SWITCH_SIDES, node2MaySwitchPortSides);
// Create two edges that, with fixed port sides, will have to cross.
ElkGraphUtil.createSimpleEdge(portNorth1, portSouth2);
ElkGraphUtil.createSimpleEdge(portSouth1, portNorth2);
return graph;
}
use of org.eclipse.elk.graph.ElkPort in project elk by eclipse.
the class PortListSorterTest method configurePorts.
// ////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Configuration
@Configurator
public void configurePorts(final ElkNode graph) {
Deque<ElkNode> nodeQueue = new LinkedList<>(graph.getChildren());
while (!nodeQueue.isEmpty()) {
ElkNode node = nodeQueue.poll();
nodeQueue.addAll(node.getChildren());
if (node.getProperty(LayeredOptions.PORT_CONSTRAINTS) != PortConstraints.FIXED_ORDER) {
node.setProperty(LayeredOptions.PORT_CONSTRAINTS, PortConstraints.FIXED_ORDER);
int index = 0;
for (ElkPort port : node.getPorts()) {
port.setProperty(LayeredOptions.PORT_INDEX, index++);
}
}
}
}
Aggregations