Search in sources :

Example 1 with SpringLayout

use of edu.uci.ics.jung.algorithms.layout.SpringLayout in project titan.EclipsePlug-ins by eclipse.

the class LayoutBuilder method build.

/**
 * This method implements the building of the chosen layout with chosen parameters
 * @return The built layout
 * @throws BadLayoutException If the chosen layout doesn't exist (invalid code was provided)
 */
public Layout<NodeDescriptor, EdgeDescriptor> build() throws BadLayoutException {
    Layout<NodeDescriptor, EdgeDescriptor> layout;
    final String layoutCode = layoutEntry.getCode();
    if (layoutCode.equals(Layouts.LAYOUT_ISOM.getCode())) {
        layout = new TitaniumISOMLayout<NodeDescriptor, EdgeDescriptor>(g);
        ((TitaniumISOMLayout<NodeDescriptor, EdgeDescriptor>) layout).setMaxIterations(Activator.getDefault().getPreferenceStore().getInt(PreferenceConstants.NO_ITERATIONS));
    } else if (layoutCode.equals(Layouts.LAYOUT_KK.getCode())) {
        layout = new KKLayout<NodeDescriptor, EdgeDescriptor>(g);
        ((KKLayout<NodeDescriptor, EdgeDescriptor>) layout).setMaxIterations(Activator.getDefault().getPreferenceStore().getInt(PreferenceConstants.NO_ITERATIONS));
    } else if (layoutCode.equals(Layouts.LAYOUT_FR.getCode())) {
        layout = new FRLayout<NodeDescriptor, EdgeDescriptor>(g);
        ((FRLayout<NodeDescriptor, EdgeDescriptor>) layout).setAttractionMultiplier(0.6);
        ((FRLayout<NodeDescriptor, EdgeDescriptor>) layout).setRepulsionMultiplier(0.8);
        ((FRLayout<NodeDescriptor, EdgeDescriptor>) layout).setMaxIterations(Activator.getDefault().getPreferenceStore().getInt(PreferenceConstants.NO_ITERATIONS));
    } else if (layoutCode.equals(Layouts.LAYOUT_SPRING.getCode())) {
        layout = new SpringLayout<NodeDescriptor, EdgeDescriptor>(g);
    } else if (layoutCode.equals(Layouts.LAYOUT_CIRCLE.getCode())) {
        layout = new CircleLayout<NodeDescriptor, EdgeDescriptor>(g);
    } else if (layoutCode.equals(Layouts.LAYOUT_RTDAG.getCode())) {
        layout = new ReverseDAGLayout<NodeDescriptor, EdgeDescriptor>(g, size);
    } else if (layoutCode.equals(Layouts.LAYOUT_TDAG.getCode())) {
        layout = new TitaniumDAGLayout<NodeDescriptor, EdgeDescriptor>(g, size);
    } else if (layoutCode.equals(Layouts.METRIC_LAYOUT_CODE)) {
        if (!(layoutEntry instanceof MetricsLayoutEntry)) {
            throw new IllegalStateException("A metric must be chosen before using metric layout!");
        }
        layout = new MetricLayout<EdgeDescriptor>(g, size, ((MetricsLayoutEntry) layoutEntry).getMetric());
    } else if (layoutCode.equals(Layouts.S_LAYOUT_CLUSTER)) {
        if (clusters == null) {
            throw new IllegalStateException("A clustering must be set before using cluster layout!");
        }
        final ClusterTransformer trf = new ClusterTransformer(new FRLayout<NodeDescriptor, EdgeDescriptor>(g), clusters, size);
        layout = new StaticLayout<NodeDescriptor, EdgeDescriptor>(g, trf);
    } else if ("STATIC".equals(layoutCode)) {
        if (pointTransformer == null) {
            throw new IllegalStateException("A point transformer must be set before using static layout!");
        }
        layout = new StaticLayout<NodeDescriptor, EdgeDescriptor>(g, pointTransformer);
    } else {
        throw new BadLayoutException("There is no such layout! (Layout=" + layoutCode + ")", ErrorType.NOT_EXISITING_LAYOUT);
    }
    layout.setSize(size);
    return layout;
}
Also used : KKLayout(edu.uci.ics.jung.algorithms.layout.KKLayout) ClusterTransformer(org.eclipse.titanium.graph.clustering.gui.ClusterTransformer) MetricsLayoutEntry(org.eclipse.titanium.graph.gui.utils.MetricsLayoutEntry) FRLayout(edu.uci.ics.jung.algorithms.layout.FRLayout) NodeDescriptor(org.eclipse.titanium.graph.components.NodeDescriptor) StaticLayout(edu.uci.ics.jung.algorithms.layout.StaticLayout) EdgeDescriptor(org.eclipse.titanium.graph.components.EdgeDescriptor) ReverseDAGLayout(org.eclipse.titanium.graph.gui.layouts.ReverseDAGLayout) MetricLayout(org.eclipse.titanium.graph.gui.layouts.MetricLayout) SpringLayout(edu.uci.ics.jung.algorithms.layout.SpringLayout) TitaniumISOMLayout(org.eclipse.titanium.graph.gui.layouts.TitaniumISOMLayout)

Example 2 with SpringLayout

use of edu.uci.ics.jung.algorithms.layout.SpringLayout in project opennms by OpenNMS.

the class RealUltimateLayoutAlgorithm method doSpringLayout.

private static void doSpringLayout(final Layout graphLayout, SparseGraph<VertexRef, EdgeRef> jungGraph, Dimension size, int repulsion) {
    SpringLayout<VertexRef, EdgeRef> layout = new SpringLayout<VertexRef, EdgeRef>(jungGraph);
    layout.setForceMultiplier(SPRING_FORCE_MULTIPLIER);
    layout.setRepulsionRange(repulsion);
    layout.setInitializer(initializer(graphLayout));
    layout.setSize(size);
    int count = 0;
    while (!layout.done() && count < 700) {
        layout.step();
        count++;
    }
    for (VertexRef v : jungGraph.getVertices()) {
        graphLayout.setLocation(v, new Point(layout.getX(v), layout.getY(v)));
    }
}
Also used : SpringLayout(edu.uci.ics.jung.algorithms.layout.SpringLayout) EdgeRef(org.opennms.features.topology.api.topo.EdgeRef) Point(org.opennms.features.topology.api.Point) VertexRef(org.opennms.features.topology.api.topo.VertexRef) Point(org.opennms.features.topology.api.Point)

Example 3 with SpringLayout

use of edu.uci.ics.jung.algorithms.layout.SpringLayout in project opennms by OpenNMS.

the class SpringLayoutAlgorithm method updateLayout.

@Override
public void updateLayout(final Graph graph) {
    final Layout graphLayout = graph.getLayout();
    SparseGraph<VertexRef, EdgeRef> jungGraph = new SparseGraph<VertexRef, EdgeRef>();
    Collection<? extends Vertex> vertices = graph.getDisplayVertices();
    for (VertexRef v : vertices) {
        jungGraph.addVertex(v);
    }
    Collection<? extends Edge> edges = graph.getDisplayEdges();
    for (Edge e : edges) {
        jungGraph.addEdge(e, e.getSource().getVertex(), e.getTarget().getVertex());
    }
    SpringLayout<VertexRef, EdgeRef> layout = new SpringLayout<VertexRef, EdgeRef>(jungGraph);
    layout.setForceMultiplier(SPRING_FORCE_MULTIPLIER);
    layout.setRepulsionRange(SPRING_LAYOUT_REPULSION);
    layout.setInitializer(initializer(graphLayout));
    layout.setSize(selectLayoutSize(graph));
    int count = 0;
    while (!layout.done() && count < 700) {
        layout.step();
        count++;
    }
    for (VertexRef v : vertices) {
        graphLayout.setLocation(v, new Point(layout.getX(v), layout.getY(v)));
    }
}
Also used : SparseGraph(edu.uci.ics.jung.graph.SparseGraph) Layout(org.opennms.features.topology.api.Layout) SpringLayout(edu.uci.ics.jung.algorithms.layout.SpringLayout) SpringLayout(edu.uci.ics.jung.algorithms.layout.SpringLayout) EdgeRef(org.opennms.features.topology.api.topo.EdgeRef) Point(org.opennms.features.topology.api.Point) VertexRef(org.opennms.features.topology.api.topo.VertexRef) Edge(org.opennms.features.topology.api.topo.Edge) Point(org.opennms.features.topology.api.Point)

Aggregations

SpringLayout (edu.uci.ics.jung.algorithms.layout.SpringLayout)3 Point (org.opennms.features.topology.api.Point)2 EdgeRef (org.opennms.features.topology.api.topo.EdgeRef)2 VertexRef (org.opennms.features.topology.api.topo.VertexRef)2 FRLayout (edu.uci.ics.jung.algorithms.layout.FRLayout)1 KKLayout (edu.uci.ics.jung.algorithms.layout.KKLayout)1 StaticLayout (edu.uci.ics.jung.algorithms.layout.StaticLayout)1 SparseGraph (edu.uci.ics.jung.graph.SparseGraph)1 ClusterTransformer (org.eclipse.titanium.graph.clustering.gui.ClusterTransformer)1 EdgeDescriptor (org.eclipse.titanium.graph.components.EdgeDescriptor)1 NodeDescriptor (org.eclipse.titanium.graph.components.NodeDescriptor)1 MetricLayout (org.eclipse.titanium.graph.gui.layouts.MetricLayout)1 ReverseDAGLayout (org.eclipse.titanium.graph.gui.layouts.ReverseDAGLayout)1 TitaniumISOMLayout (org.eclipse.titanium.graph.gui.layouts.TitaniumISOMLayout)1 MetricsLayoutEntry (org.eclipse.titanium.graph.gui.utils.MetricsLayoutEntry)1 Layout (org.opennms.features.topology.api.Layout)1 Edge (org.opennms.features.topology.api.topo.Edge)1