use of org.eclipse.elk.alg.force.graph.FEdge in project elk by eclipse.
the class ComponentsProcessor method moveGraph.
/**
* Move the source graph into the destination graph using a specified offset.
*
* @param destGraph the destination graph.
* @param sourceGraph the source graph.
* @param offsetx x coordinate offset.
* @param offsety y coordinate offset.
*/
private void moveGraph(final FGraph destGraph, final FGraph sourceGraph, final double offsetx, final double offsety) {
KVector graphOffset = new KVector(offsetx, offsety);
graphOffset.sub(sourceGraph.getProperty(InternalProperties.BB_UPLEFT));
for (FNode node : sourceGraph.getNodes()) {
node.getPosition().add(graphOffset);
destGraph.getNodes().add(node);
}
for (FEdge edge : sourceGraph.getEdges()) {
for (FBendpoint bendpoint : edge.getBendpoints()) {
bendpoint.getPosition().add(graphOffset);
}
destGraph.getEdges().add(edge);
}
for (FLabel label : sourceGraph.getLabels()) {
label.getPosition().add(graphOffset);
destGraph.getLabels().add(label);
}
}
use of org.eclipse.elk.alg.force.graph.FEdge in project elk by eclipse.
the class ElkGraphImporter method applyLayout.
// /////////////////////////////////////////////////////////////////////////////
// Apply Layout Results
@Override
public void applyLayout(final FGraph fgraph) {
ElkNode kgraph = (ElkNode) fgraph.getProperty(InternalProperties.ORIGIN);
// calculate the offset from border spacing and node distribution
double minXPos = Integer.MAX_VALUE;
double minYPos = Integer.MAX_VALUE;
double maxXPos = Integer.MIN_VALUE;
double maxYPos = Integer.MIN_VALUE;
for (FNode node : fgraph.getNodes()) {
KVector pos = node.getPosition();
KVector size = node.getSize();
minXPos = Math.min(minXPos, pos.x - size.x / 2);
minYPos = Math.min(minYPos, pos.y - size.y / 2);
maxXPos = Math.max(maxXPos, pos.x + size.x / 2);
maxYPos = Math.max(maxYPos, pos.y + size.y / 2);
}
ElkPadding padding = kgraph.getProperty(ForceOptions.PADDING);
KVector offset = new KVector(padding.getLeft() - minXPos, padding.getTop() - minYPos);
// process the nodes
for (FNode fnode : fgraph.getNodes()) {
Object object = fnode.getProperty(InternalProperties.ORIGIN);
if (object instanceof ElkNode) {
// set the node position
ElkNode knode = (ElkNode) object;
KVector nodePos = fnode.getPosition().add(offset);
knode.setLocation(nodePos.x - knode.getWidth() / 2, nodePos.y - knode.getHeight() / 2);
}
}
// process the edges
for (FEdge fedge : fgraph.getEdges()) {
ElkEdge kedge = (ElkEdge) fedge.getProperty(InternalProperties.ORIGIN);
ElkEdgeSection kedgeSection = ElkGraphUtil.firstEdgeSection(kedge, true, true);
KVector startLocation = fedge.getSourcePoint();
kedgeSection.setStartLocation(startLocation.x, startLocation.y);
KVector endLocation = fedge.getTargetPoint();
kedgeSection.setEndLocation(endLocation.x, endLocation.y);
}
// process the labels
for (FLabel flabel : fgraph.getLabels()) {
ElkLabel klabel = (ElkLabel) flabel.getProperty(InternalProperties.ORIGIN);
KVector labelPos = flabel.getPosition().add(offset);
klabel.setLocation(labelPos.x, labelPos.y);
}
// set up the parent node
double width = (maxXPos - minXPos) + padding.getHorizontal();
double height = (maxYPos - minYPos) + padding.getVertical();
ElkUtil.resizeNode(kgraph, width, height, false, true);
}
use of org.eclipse.elk.alg.force.graph.FEdge in project elk by eclipse.
the class ElkGraphImporter method transformEdges.
/**
* Transforms the edges 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 transformEdges(final ElkNode parentNode, final FGraph fgraph, final Map<ElkNode, FNode> elemMap) {
for (ElkNode knode : parentNode.getChildren()) {
for (ElkEdge kedge : ElkGraphUtil.allOutgoingEdges(knode)) {
// We don't support hyperedges
if (kedge.isHyperedge()) {
throw new UnsupportedGraphException("Graph must not contain hyperedges.");
}
// exclude edges that pass hierarchy bounds as well as self-loops
if (!kedge.isHierarchical() && knode != ElkGraphUtil.connectableShapeToNode(kedge.getTargets().get(0))) {
// create a force edge
FEdge newEdge = new FEdge();
newEdge.copyProperties(kedge);
// TODO
// newEdge.checkProperties(Properties.LABEL_SPACING, Properties.REPULSIVE_POWER);
newEdge.setProperty(InternalProperties.ORIGIN, kedge);
newEdge.setSource(elemMap.get(knode));
newEdge.setTarget(elemMap.get(ElkGraphUtil.connectableShapeToNode(kedge.getTargets().get(0))));
fgraph.getEdges().add(newEdge);
// transform the edge's labels
for (ElkLabel klabel : kedge.getLabels()) {
FLabel newLabel = new FLabel(newEdge, klabel.getText());
newLabel.copyProperties(klabel);
newLabel.setProperty(InternalProperties.ORIGIN, klabel);
newLabel.getSize().x = Math.max(klabel.getWidth(), 1);
newLabel.getSize().y = Math.max(klabel.getHeight(), 1);
newLabel.refreshPosition();
fgraph.getLabels().add(newLabel);
}
}
}
}
}
Aggregations