Package net.wigis.graph.dnv.utilities

Examples of net.wigis.graph.dnv.utilities.Vector2D


    }
    checkString = " Position=\"";
    if( line.contains( checkString ) )
    {
      tempLine = line.substring( line.indexOf( checkString ) + checkString.length() );
      position = new Vector2D( tempLine.substring( 0, tempLine.indexOf( "\"" ) ) );
      originalPosition = new Vector2D( position );
    }
    checkString = " Color=\"";
    if( line.contains( checkString ) )
    {
      tempLine = line.substring( line.indexOf( checkString ) + checkString.length() );
View Full Code Here


//      }
//      System.out.println( "distMoved:" + distMoved );
     
      if( !n.isFixed() && !( n == dragNode ) )
      {
        Vector2D movement = new Vector2D( (float)Math.max( -30, Math.min( 30, dx ) ), (float)Math.max( -30, Math.min( 30, dy ) ) );
//        System.out.println( "Moving " + n.getLabel() + " by " + movement );
        n.move( movement, false, false );
      }
      maxMotionA[0] = Math.max( distMoved, maxMotionA[0] );
    }
View Full Code Here

   * Generate force to original position.
   */
  public void generateForceToOriginalPosition()
  {
    if( force == null )
      force = new Vector2D();
    if( originalPosition != null )
    {
      force.setX( originalPosition.getX() - position.getX() );
      force.setY( originalPosition.getY() - position.getY() );
    }
View Full Code Here

   */
  public static void layoutBasedOnNumberOfSubnodes( DNVGraph graph, int level )
  {
    List<DNVNode> nodes = new ArrayList<DNVNode>( graph.getNodes( level ) );
    Collections.sort( nodes, numberOfSubnodesSort );
    Vector2D position;
    float radius = 0;
    int lastNumberOfSubnodes = -1;
    Vector2D movement = new Vector2D();
    Vector2D center = new Vector2D( 0, 0 );
    Map<Integer, Integer> histogram = generateHistogramOfSubnodes( graph, level );
    int i = 0;
    // float lastRadius = 0;
    // float allowedWidth = 0;
    int counter = 0;
    for( DNVNode node : nodes )
    {
      counter++;
      if( lastNumberOfSubnodes == node.getNumberOfSubNodes() )
      {
        i++;
      }
      else
      {
        // System.out.println( "number of subnodes " +
        // node.getNumberOfSubNodes() );
        // lastRadius = radius;
        radius += node.getDiameterOfSubnodes();
        lastNumberOfSubnodes = node.getNumberOfSubNodes();
        i = 0;
        // sqrt( (area of outer disk - area of inner disk ) / number of
        // nodes in outer disk )
        // allowedWidth = (float)Math.sqrt( ( Math.PI * radius * radius
        // - Math.PI * lastRadius * lastRadius ) / (float)histogram.get(
        // lastNumberOfSubnodes ) );
        // allowedWidth = radius - lastRadius;
        // System.out.println( "Allowed width for " +
        // lastNumberOfSubnodes + " is " + allowedWidth );
      }

      // System.out.println( "Counter : " + counter +
      // " - lastNumberOfSubnodes : " + lastNumberOfSubnodes +
      // " - numberOfClusters : " + histogram.get( lastNumberOfSubnodes )
      // );

      if( counter == 1 && histogram.get( lastNumberOfSubnodes ) == 1 )
      {
        // System.out.println( "Putting " + lastNumberOfSubnodes +
        // " node cluster in the center." );
        position = new Vector2D( 0, 0 );
      }
      else
      {
        position = getPosition( i, lastNumberOfSubnodes, histogram.get( lastNumberOfSubnodes ), radius, center );
      }
View Full Code Here

    // float x_pos = (float)Math.cos( radians );// * bigRadius;

    z_pos = (float)( Math.cos( bigRadians ) * bigRadius );
    y_pos += Math.sin( bigRadians ) * bigRadius;

    return new Vector2D( center.getX() + z_pos, center.getY() + y_pos );
  }
View Full Code Here

    float kPower2 = k * k;

    // System.out.println( "Temperature : " + temperature + " Level : " +
    // level + " Number of Nodes: " + graph.getGraphSize( level ) );

    Vector2D difference = new Vector2D();
    float length;

    Grid grid = new Grid( k * 2, nodes );
    List<DNVNode> potentialNodes;

    // repulsive forces
    for( DNVNode v : nodes )
    {
      v.setForce( 0, 0 );
      potentialNodes = grid.getPotentialNodes( v );
      for( DNVNode u : potentialNodes )
      {
        if( u != v )
        {
          difference.set( v.getPosition() );
          difference.subtract( u.getPosition() );
          length = difference.length();
          // If two nodes are in exact same position
          // then we need to do something to move them apart.
          // Give them a small repelling force in random direction.
          if( length == 0 )
          {
            difference.set( (float)Math.random(), (float)Math.random() );
            length = difference.length();
          }
          if( length < k * 2 )
          {
            difference.normalize();
            difference.dotProduct( repel( length, kPower2 * u.getRadius() ) );
            if( useNumberOfSubnodes )
            {
              difference.dotProduct( Math.max( u.getSubNodes().size(), 1 ) );
              difference.dotProduct( Math.max( v.getSubNodes().size(), 1 ) );
            }
            v.getForce().add( difference );
          }
        }
      }
    }

    // attractive forces
    for( DNVEdge e : edges )
    {
      difference.set( e.getFrom().getPosition() );
      difference.subtract( e.getTo().getPosition() );
      length = difference.length();
      difference.normalize();
      difference.dotProduct( attract( length, k ) );
      e.getFrom().getForce().subtract( difference );
      e.getTo().getForce().add( difference );
    }
    /*
     * Vector2D center = GraphFunctions.getCenterOfGravity( nodes.iterator()
     * ); for( DNVNode v : nodes ) { difference.set( center );
     * difference.subtract( v.getPosition() ); v.getForce().add( difference
     * ); }
     */
    // apply the forces
    for( DNVNode v : nodes )
    {
      if( v.getProperty( "pinned" ) == null )
      {
        difference.set( v.getForce() );
        length = difference.length();
        difference.normalize();
        difference.dotProduct( Math.min( length, temperature ) );
        v.move( difference, true, false );
        // v.getPosition().setX( Math.min( width / 2.0f, Math.max(
        // -width / 2.0f, v.getPosition().getX() ) ) );
        // v.getPosition().setY( Math.min( height / 2.0f, Math.max(
        // -height / 2.0f, v.getPosition().getY() ) ) );
View Full Code Here

      double globalMinX, double globalMaxX, double globalMinY, double globalMaxY, double width, double height, boolean overview )
  {
    Color oldColor = g2d.getColor();
    Stroke oldStroke = g2d.getStroke();
    g2d.setColor( new Color( color.getX(), color.getY(), color.getZ() ) );
    Vector2D screenStart = ImageRenderer.transformPosition( globalMinX, globalMaxX, globalMinY, globalMaxY, minXPercent, maxXPercent,
        minYPercent, maxYPercent, width, height, start );
    Vector2D screenEnd = ImageRenderer.transformPosition( globalMinX, globalMaxX, globalMinY, globalMaxY, minXPercent, maxXPercent, minYPercent,
        maxYPercent, width, height, end );
    g2d.setStroke( new BasicStroke( thickness ) );
    g2d.drawLine( (int)Math.round( screenStart.getX() ), (int)Math.round( screenStart.getY() ), (int)Math.round( screenEnd.getX() ), (int)Math
        .round( screenEnd.getY() ) );
    g2d.setStroke( oldStroke );
    g2d.setColor( oldColor );
  }
View Full Code Here

        double ratio = 1;
        if( pb != null )
        {
          ratio = width / pb.getWidth();
        }
        Vector2D tempPos;
        if( !screenPosition )
        {
          tempPos = ImageRenderer.transformPosition( globalMinX, globalMaxX, globalMinY, globalMaxY, minXPercent, maxXPercent, minYPercent,
              maxYPercent, width, height, node.getPosition( true ) );
        }
        else
        {
          tempPos = node.getPosition( true );
        }
        float yMiddle = tempPos.getY();
        float yPos = yMiddle;
        String label = node.getLabel();
        int lines = StringUtils.countInstancesOf( label, "\n" );
        yPos = yMiddle - ( lines * (float)labelSize / 2.0f );
        StringTokenizer toki = new StringTokenizer( label, "\n" );
        while( toki.hasMoreElements() )
        {
          tempPos.setY( yPos );
          label = toki.nextToken();
          ImageRenderer.drawLabel( g2d, node, tempPos, 1, label, true, curvedLabel, outlined, labelSize, minXPercent, maxXPercent, ratio,
              scaleOnZoom, false, label.length(), 200, drawBackground, bold, false, null );
          yPos += labelSize / ( maxYPercent - minYPercent );
        }
View Full Code Here

      results = dbm.getResults( query );
      results.last();
      System.out.println( "Processing " + results.getRow() + " nodes" );
      results.beforeFirst();
      DNVNode newNode;
      Vector2D position;
      float r, g = 0, b = 0;
      r = graphName.charAt( 0 ) / 120.0f;

      if( graphName.length() > 1 )
        g = graphName.charAt( graphName.length() / 2 ) / 150.0f;
      if( graphName.length() > 2 )
        b = graphName.charAt( graphName.length() - 1 ) / 100.0f;
      while( results.next() )
      {
        position = new Vector2D( 100.0f * (float)Math.random(), 100.0f * (float)Math.random() );
        // position = new Vector2D( results.getFloat( "xPos" ),
        // results.getFloat( "yPos" ) );
        newNode = new DNVNode( position, graph );
        newNode.setColor( r, g, b );
        newNode.setPosition( position );
View Full Code Here

   *            the graph
   * @return the dNV node
   */
  public static DNVNode createParentNode( DNVNode child, Integer newLevel, DNVGraph graph )
  {
    DNVNode parent = new DNVNode( new Vector2D( child.getPosition() ), graph );
    parent.setColor( child.getColor() );
    parent.setLevel( newLevel.intValue() );
    parent.setFirstChild( child );
    child.setParentNode( parent );
    graph.addNode( newLevel, parent );
View Full Code Here

TOP

Related Classes of net.wigis.graph.dnv.utilities.Vector2D

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.