Search in sources :

Example 1 with FBendpoint

use of org.eclipse.elk.alg.force.graph.FBendpoint in project elk by eclipse.

the class AbstractForceModel method initialize.

/**
 * Initialize the force model with the given graph. Subclasses that override this
 * must call the superclass method first.
 *
 * @param fgraph a force graph
 */
protected void initialize(final FGraph fgraph) {
    this.graph = fgraph;
    this.random = fgraph.getProperty(InternalProperties.RANDOM);
    // calculate the adjacency matrix for the graph
    fgraph.calcAdjacency();
    // calculate an upper bound for particle displacement
    dispBound = Math.max(fgraph.getNodes().size() * DISP_BOUND_FACTOR + fgraph.getEdges().size(), DISP_BOUND_FACTOR * DISP_BOUND_FACTOR);
    // if interactive mode is off, randomize the layout
    if (!fgraph.getProperty(ForceOptions.INTERACTIVE)) {
        double posScale = graph.getNodes().size();
        for (FNode node : fgraph.getNodes()) {
            KVector pos = node.getPosition();
            pos.x = random.nextDouble() * posScale;
            pos.y = random.nextDouble() * posScale;
        }
    }
    // create bend points for node repulsion
    List<FBendpoint> bends = fgraph.getBendpoints();
    for (FEdge edge : fgraph.getEdges()) {
        int count = edge.getProperty(ForceOptions.REPULSIVE_POWER);
        if (count > 0) {
            for (int i = 0; i < count; i++) {
                bends.add(new FBendpoint(edge));
            }
            edge.distributeBendpoints();
        }
    }
}
Also used : FBendpoint(org.eclipse.elk.alg.force.graph.FBendpoint) FNode(org.eclipse.elk.alg.force.graph.FNode) FEdge(org.eclipse.elk.alg.force.graph.FEdge) KVector(org.eclipse.elk.core.math.KVector) FBendpoint(org.eclipse.elk.alg.force.graph.FBendpoint)

Example 2 with FBendpoint

use of org.eclipse.elk.alg.force.graph.FBendpoint 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)

Aggregations

FBendpoint (org.eclipse.elk.alg.force.graph.FBendpoint)2 FEdge (org.eclipse.elk.alg.force.graph.FEdge)2 FNode (org.eclipse.elk.alg.force.graph.FNode)2 KVector (org.eclipse.elk.core.math.KVector)2 FLabel (org.eclipse.elk.alg.force.graph.FLabel)1