Package org.nanograph.model

Examples of org.nanograph.model.GraphModel


  public void setCentralNode(Object centralNode) {
    this.centralNode = centralNode;
  }

  public void layout(NanoGraph graph) {
    GraphModel g = graph.getModel();
    double x, y, angle;
    Object node;
    int counter = 0;
    for (int i = 0; i < g.getNodeCount(); i++) {
      int nodesOnCircle = (centralNode == null ? g.getNodeCount() : (g.getNodeCount() - 1));
      double d = (counter / ((double) nodesOnCircle));
      angle = d * 2.0d * Math.PI;
      double rotateFactor = 2;
      if (nodesOnCircle % 2 == 0) {
        rotateFactor = 6;
      } else {
        rotateFactor = 3;
      }
      angle += Math.PI / rotateFactor;
      angle = angle % (2 * Math.PI);
      node = g.getNode(i);
      if (centralNode != null && centralNode.equals(node)) {
        x = y = radius;
      } else {
        x = radius + radius * Math.sin(angle);
        y = radius + radius * Math.cos(angle);
        // only increment the counter when this node wasn't the central node
        // or else we get overlapping nodes at 0 degrees and 2 PI degrees
        counter++;
      }
      g.setLocation(node, new Point2D.Double(x+100, y+50));
    }
  }
View Full Code Here


public class RandomLayoutAlgorithm implements LayoutAlgorithm {

    Object root = null;

    public void layout(NanoGraph graph) {
        GraphModel g = graph.getModel();
        for (int t = 0; t < g.getNodeCount(); t++) {
            g.setLocation(g.getNode(t), new Point2D.Double((int) (Math
                    .random() * 400), (int) (Math.random() * 400)));
        }
    }
View Full Code Here

TOP

Related Classes of org.nanograph.model.GraphModel

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.