Search in sources :

Example 11 with FNode

use of org.eclipse.elk.alg.force.graph.FNode 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 12 with FNode

use of org.eclipse.elk.alg.force.graph.FNode 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
    }
}
Also used : ElkNode(org.eclipse.elk.graph.ElkNode) FNode(org.eclipse.elk.alg.force.graph.FNode) PortConstraints(org.eclipse.elk.core.options.PortConstraints)

Example 13 with FNode

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

the class ElkGraphImporter method importGraph.

// /////////////////////////////////////////////////////////////////////////////
// Transformation KGraph -> FGraph
@Override
public FGraph importGraph(final ElkNode kgraph) {
    FGraph fgraph = new FGraph();
    // copy the properties of the KGraph to the force graph
    fgraph.copyProperties(kgraph);
    // TODO Find another way to do this kind of bounds checking
    // fgraph.checkProperties(Properties.SPACING, Properties.ASPECT_RATIO, Properties.TEMPERATURE,
    // Properties.ITERATIONS, Properties.REPULSION);
    fgraph.setProperty(InternalProperties.ORIGIN, kgraph);
    // keep a list of created nodes in the force graph
    Map<ElkNode, FNode> elemMap = new HashMap<ElkNode, FNode>();
    // transform everything
    transformNodes(kgraph, fgraph, elemMap);
    transformEdges(kgraph, fgraph, elemMap);
    return fgraph;
}
Also used : ElkNode(org.eclipse.elk.graph.ElkNode) HashMap(java.util.HashMap) FNode(org.eclipse.elk.alg.force.graph.FNode) FGraph(org.eclipse.elk.alg.force.graph.FGraph)

Example 14 with FNode

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

the class StressMajorization method computeStress.

/**
 * @return the stress value of the current node positioning.
 */
private double computeStress() {
    double stress = 0;
    List<FNode> nodes = graph.getNodes();
    // we know 'nodes' is an arraylist
    for (int i = 0; i < nodes.size(); ++i) {
        FNode u = nodes.get(i);
        for (int j = i + 1; j < nodes.size(); ++j) {
            FNode v = nodes.get(j);
            double eucDist = u.getPosition().distance(v.getPosition());
            double eucDisplacement = eucDist - apsp[u.id][v.id];
            stress += w[u.id][v.id] * eucDisplacement * eucDisplacement;
        }
    }
    return stress;
}
Also used : FNode(org.eclipse.elk.alg.force.graph.FNode)

Example 15 with FNode

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

the class FruchtermanReingoldModel method initialize.

@Override
protected void initialize(final FGraph graph) {
    super.initialize(graph);
    temperature = graph.getProperty(ForceOptions.TEMPERATURE).doubleValue();
    threshold = temperature / graph.getProperty(ForceOptions.ITERATIONS);
    // calculate an appropriate value for K
    int n = graph.getNodes().size();
    double totalWidth = 0;
    double totalHeight = 0;
    for (FNode v : graph.getNodes()) {
        totalWidth += v.getSize().x;
        totalHeight += v.getSize().y;
    }
    double area = totalWidth * totalHeight;
    double c = graph.getProperty(ForceOptions.SPACING_NODE_NODE) * SPACING_FACTOR;
    k = Math.sqrt(area / (2 * n)) * c;
}
Also used : FNode(org.eclipse.elk.alg.force.graph.FNode)

Aggregations

FNode (org.eclipse.elk.alg.force.graph.FNode)15 KVector (org.eclipse.elk.core.math.KVector)7 FBendpoint (org.eclipse.elk.alg.force.graph.FBendpoint)6 FEdge (org.eclipse.elk.alg.force.graph.FEdge)6 FGraph (org.eclipse.elk.alg.force.graph.FGraph)3 ElkNode (org.eclipse.elk.graph.ElkNode)3 LinkedList (java.util.LinkedList)2 List (java.util.List)2 FLabel (org.eclipse.elk.alg.force.graph.FLabel)2 HashMap (java.util.HashMap)1 PriorityQueue (java.util.PriorityQueue)1 FParticle (org.eclipse.elk.alg.force.graph.FParticle)1 ElkPadding (org.eclipse.elk.core.math.ElkPadding)1 PortConstraints (org.eclipse.elk.core.options.PortConstraints)1 ElkEdge (org.eclipse.elk.graph.ElkEdge)1 ElkEdgeSection (org.eclipse.elk.graph.ElkEdgeSection)1 ElkLabel (org.eclipse.elk.graph.ElkLabel)1