Search in sources :

Example 1 with FLabel

use of org.eclipse.elk.alg.force.graph.FLabel 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);
    }
}
Also used : FBendpoint(org.eclipse.elk.alg.force.graph.FBendpoint) FLabel(org.eclipse.elk.alg.force.graph.FLabel) FNode(org.eclipse.elk.alg.force.graph.FNode) FEdge(org.eclipse.elk.alg.force.graph.FEdge) KVector(org.eclipse.elk.core.math.KVector)

Example 2 with FLabel

use of org.eclipse.elk.alg.force.graph.FLabel 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);
}
Also used : FLabel(org.eclipse.elk.alg.force.graph.FLabel) ElkNode(org.eclipse.elk.graph.ElkNode) ElkLabel(org.eclipse.elk.graph.ElkLabel) FNode(org.eclipse.elk.alg.force.graph.FNode) FEdge(org.eclipse.elk.alg.force.graph.FEdge) KVector(org.eclipse.elk.core.math.KVector) ElkPadding(org.eclipse.elk.core.math.ElkPadding) ElkEdgeSection(org.eclipse.elk.graph.ElkEdgeSection) ElkEdge(org.eclipse.elk.graph.ElkEdge)

Example 3 with FLabel

use of org.eclipse.elk.alg.force.graph.FLabel 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);
                }
            }
        }
    }
}
Also used : UnsupportedGraphException(org.eclipse.elk.core.UnsupportedGraphException) FLabel(org.eclipse.elk.alg.force.graph.FLabel) ElkNode(org.eclipse.elk.graph.ElkNode) ElkLabel(org.eclipse.elk.graph.ElkLabel) FEdge(org.eclipse.elk.alg.force.graph.FEdge) ElkEdge(org.eclipse.elk.graph.ElkEdge)

Aggregations

FEdge (org.eclipse.elk.alg.force.graph.FEdge)3 FLabel (org.eclipse.elk.alg.force.graph.FLabel)3 FNode (org.eclipse.elk.alg.force.graph.FNode)2 KVector (org.eclipse.elk.core.math.KVector)2 ElkEdge (org.eclipse.elk.graph.ElkEdge)2 ElkLabel (org.eclipse.elk.graph.ElkLabel)2 ElkNode (org.eclipse.elk.graph.ElkNode)2 FBendpoint (org.eclipse.elk.alg.force.graph.FBendpoint)1 UnsupportedGraphException (org.eclipse.elk.core.UnsupportedGraphException)1 ElkPadding (org.eclipse.elk.core.math.ElkPadding)1 ElkEdgeSection (org.eclipse.elk.graph.ElkEdgeSection)1