Package net.wigis.graph.dnv.utilities

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


    float globalMinX = GraphFunctions.getMinXPosition( subgraph.getSuperGraph(), level, true );
    float globalMaxX = GraphFunctions.getMaxXPosition( subgraph.getSuperGraph(), level, true );
    float globalMinY = GraphFunctions.getMinYPosition( subgraph.getSuperGraph(), level, true );
    float globalMaxY = GraphFunctions.getMaxYPosition( subgraph.getSuperGraph(), level, true );

    Vector2D bottomLeft = new Vector2D( globalMinX, globalMaxY );
    Vector2D bottomRight = new Vector2D( globalMaxX, globalMaxY );
    Vector2D topLeft = new Vector2D( globalMinX, globalMinY );

    Vector2D bottomLeftScreen = ImageRenderer.transformPosition( pb, bottomLeft );
    Vector2D bottomRightScreen = ImageRenderer.transformPosition( pb, bottomRight );
    Vector2D topLeftScreen = ImageRenderer.transformPosition( pb, topLeft );

    g2d.setColor( Color.black );
    g2d.setStroke( new BasicStroke( 1 ) );
    Vector3D color = new Vector3D( 0, 0, 0 );
    Vector3D outlineColor = new Vector3D( 1, 1, 1 );

    // X-axis
    g2d.drawLine( (int)bottomLeftScreen.getX(), (int)bottomLeftScreen.getY(), (int)bottomRightScreen.getX() + 20, (int)bottomRightScreen.getY() );
    Vector2D tempPos = new Vector2D( bottomLeft );
    Vector2D tempPosScreen = new Vector2D( bottomLeftScreen );
    int numberOfTicks = 5;
    float axisTickLength = ( bottomRight.getX() - bottomLeft.getX() ) / numberOfTicks;
    float axisTickLengthScreen = ( bottomRightScreen.getX() - bottomLeftScreen.getX() ) / numberOfTicks;
    for( int i = 0; i <= numberOfTicks; i++ )
    {
      g2d.drawLine( (int)tempPosScreen.getX(), (int)tempPosScreen.getY(), (int)tempPosScreen.getX(), (int)tempPosScreen.getY() + 10 );
      Text text = new Text( "" + ( Math.round( tempPos.getX() * 1000.0 ) / 1000.0 ), new Vector2D( tempPosScreen.getX(),
          tempPosScreen.getY() + 15 ), outlineColor, color, 10, false, true, false, false, false, false, true );
      text.draw( g2d, pb, minXPercent, maxXPercent, minYPercent, maxYPercent, globalMinX, globalMaxX, globalMinY, globalMaxY,
          nodeWidth, height, overview );
      tempPos.add( axisTickLength, 0 );
      tempPosScreen.add( axisTickLengthScreen, 0 );
    }

    // Y-axis
    g2d.drawLine( (int)bottomLeftScreen.getX(), (int)bottomLeftScreen.getY(), (int)topLeftScreen.getX(), (int)topLeftScreen.getY() );
    tempPos.set( bottomLeft );
    tempPosScreen.set( bottomLeftScreen );
    axisTickLength = ( topLeft.getY() - bottomLeft.getY() ) / numberOfTicks;
    axisTickLengthScreen = ( topLeftScreen.getY() - bottomLeftScreen.getY() ) / numberOfTicks;
    for( int i = 0; i <= numberOfTicks; i++ )
    {
      g2d.drawLine( (int)tempPosScreen.getX(), (int)tempPosScreen.getY(), (int)tempPosScreen.getX() - 10, (int)tempPosScreen.getY() );
      Text text = new Text( "" + ( Math.round( tempPos.getY() * 1000.0 ) / 1000.0 ), new Vector2D( tempPosScreen.getX() - 25,
          tempPosScreen.getY() ), outlineColor, color, 10, false, true, false, false, false, false, true );
      text.draw( g2d, pb, minXPercent, maxXPercent, minYPercent, maxYPercent, globalMinX, globalMaxX, globalMinY, globalMaxY,
          nodeWidth, height, overview );
      tempPos.add( 0, axisTickLength );
      tempPosScreen.add( 0, axisTickLengthScreen );
    }
  }
View Full Code Here


      Map<String, Integer> drawnHeadings, boolean drawNumberOfNodesInBox, boolean drawNeighborHighlightAsBoxes,
      boolean drawAllNeighborsHighlight, boolean alignBoxInfoRelativeToBox, Map<String, Boolean> headerAlignment )
  {
    if( nodes != null )
    {
      Vector2D maxPos = new Vector2D( Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY );
      Vector2D minPos = new Vector2D( Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY );
      float maxRadius = Float.NEGATIVE_INFINITY;
      synchronized( nodes )
      {
        maxRadius = getBoundaries( nodes, maxPos, minPos, maxRadius );
      }

      Vector2D maxPosScreen = transformPosition( minX, maxX, minY, maxY, minXPercent, maxXPercent, minYPercent, maxYPercent, width, height,
          maxPos );
      Vector2D minPosScreen = transformPosition( minX, maxX, minY, maxY, minXPercent, maxXPercent, minYPercent, maxYPercent, width, height,
          minPos );
      maxPosScreen.setX( maxPosScreen.getX() + maxRadius * nodeWidth );
      maxPosScreen.setY( maxPosScreen.getY() + maxRadius * nodeWidth );

      minPosScreen.setX( minPosScreen.getX() - maxRadius * nodeWidth );
      minPosScreen.setY( minPosScreen.getY() - maxRadius * nodeWidth );

      for( DNVNode node : allNodes.values() )
      {
        if( nodes.get( node.getId() ) == null )
        {
          // This is not one of the nodes inside the box
          Vector2D screenPos = transformPosition( minX, maxX, minY, maxY, minXPercent, maxXPercent, minYPercent, maxYPercent, width,
              height, node.getPosition() );
          float x = screenPos.getX();
          float y = screenPos.getY();
          if( x >= minPosScreen.getX() && x <= maxPosScreen.getX() && y >= minPosScreen.getY() && y <= maxPosScreen.getY() )
          {
            // this node overlaps with the box, so don't draw it
            if( !drawAllNeighborsHighlight )
            {
              return 0;
            }
          }
        }
      }

      if( drawNeighborHighlightAsBoxes )
      {
        g2d.setColor( new Color( fillColor.getX(), fillColor.getY(), fillColor.getZ(), 0.7f ) );
        g2d.fillRoundRect( (int)Math.round( minPosScreen.getX() ), (int)Math.round( minPosScreen.getY() ),
            (int)Math.round( maxPosScreen.getX() - minPosScreen.getX() ), (int)Math.round( maxPosScreen.getY() - minPosScreen.getY() ),
            10, 10 );
        g2d.setStroke( new BasicStroke( 3 ) );
        g2d.setColor( new Color( outlineColor.getX(), outlineColor.getY(), outlineColor.getZ(), 0.7f ) );
        g2d.drawRoundRect( (int)Math.round( minPosScreen.getX() ), (int)Math.round( minPosScreen.getY() ),
            (int)Math.round( maxPosScreen.getX() - minPosScreen.getX() ), (int)Math.round( maxPosScreen.getY() - minPosScreen.getY() ),
            10, 10 );
      }
      else
      {
        for( DNVNode node : nodes.values() )
        {
          Vector3D color;
          if( !node.hasProperty( "originalColor" ) )
          {
            node.setProperty( "originalColor", node.getColor().toString() );
            color = fillColor;
          }
          else
          {
            color = new Vector3D( node.getColor() );
            color.add( fillColor );
            color.dotProduct( 0.5f );
          }
          node.setColor( color );
        }
      }

      Vector2D position = new Vector2D();
      Vector2D selectedNodeScreenPos = transformPosition( minX, maxX, minY, maxY, minXPercent, maxXPercent, minYPercent, maxYPercent, width,
          height, selectedNode.getPosition() );
      float xDiff = Math.abs( selectedNodeScreenPos.getX() - ( minPosScreen.getX() + ( maxPosScreen.getX() - minPosScreen.getX() ) / 2.0f ) );
      float yDiff = Math.abs( selectedNodeScreenPos.getY() - ( minPosScreen.getY() + ( maxPosScreen.getY() - minPosScreen.getY() ) / 2.0f ) );

      String key;
      if( alignBoxInfoRelativeToBox )
      {
        if( headerAlignment.containsKey( "X-align" + selectedNode.getId() )
            || ( !headerAlignment.containsKey( "Y-align" + selectedNode.getId() ) && xDiff >= yDiff ) )
        {
          headerAlignment.put( "X-align" + selectedNode.getId(), true );
          position = new Vector2D( minPosScreen.getX() + ( maxPosScreen.getX() - minPosScreen.getX() ) / 2.0f, 14 );
          key = "X" + hops;
          if( !drawnHeadings.containsKey( key ) )
          {
            Text t = new Text( "Dist " + hops, position, new Vector3D( 1, 1, 1 ), fillColor, 12, true, true, true, false, false, false,
                true );
            t.draw( g2d, pb, minXPercent, maxXPercent, minYPercent, maxYPercent, minX, maxX, minY, maxY, nodeWidth, height, overview );
            drawnHeadings.put( key, 1 );
          }
          else
          {
            drawnHeadings.put( key, drawnHeadings.get( key ) + 1 );
          }
        }
        else
        {
          headerAlignment.put( "Y-align" + selectedNode.getId(), true );
          position = new Vector2D( 35, minPosScreen.getY() + ( maxPosScreen.getY() - minPosScreen.getY() ) / 2.0f );
          key = "Y" + hops;
          if( !drawnHeadings.containsKey( key ) )
          {
            Text t = new Text( "Dist " + hops, position, new Vector3D( 1, 1, 1 ), fillColor, 12, true, true, true, false, false, false,
                true );
            t.draw( g2d, pb, minXPercent, maxXPercent, minYPercent, maxYPercent, minX, maxX, minY, maxY, nodeWidth, height, overview );
            drawnHeadings.put( key, 1 );
          }
          else
          {
            drawnHeadings.put( key, drawnHeadings.get( key ) + 1 );
          }
        }
      }
      else
      {
        position = new Vector2D( 70 * hops, 14 );
        key = "Align" + hops;
        if( !drawnHeadings.containsKey( key ) )
        {
          Text t = new Text( "Dist " + hops, position, new Vector3D( 1, 1, 1 ), fillColor, 12, true, true, true, false, false, false, true );
          t.draw( g2d, pb, minXPercent, maxXPercent, minYPercent, maxYPercent, minX, maxX, minY, maxY, nodeWidth, height, overview );
View Full Code Here

      double maxXPercent, double maxYPercent, boolean showIcons, double minX, double maxX, double minY, double maxY,
      boolean highlightNeighbors, int type, int nodeWidth, List<DNVNode> selectedNodes, Timer transformTimer, Timer drawNodeTimer,
      SortByLabelSize sortByLabelSize, boolean sortNodes, int maxDistanceToHighlight ) throws MalformedURLException, IOException
  {
    DNVNode tempNode;
    Vector2D tempPos;
    List<DNVNode> nodes;
    Vector3D color;
    nodes = subgraph.getSortedNodes();
    if( nodes == null )
    {
View Full Code Here

      double minX, double maxX, double minY, double maxY, boolean highlightNeighbors, int maxLabelLength, int curvedLabelAngle,
      boolean scaleLabels, boolean drawLabelBox, DNVNode tempNode, Graphics2D g2d, int nodeWidth, boolean boldLabels, boolean highlighted,
      Vector3D neighborHighlightColor )
      throws MalformedURLException, IOException
  {
    Vector2D tempPos;
    tempPos = transformPosition( minX, maxX, minY, maxY, minXPercent, maxXPercent, minYPercent, maxYPercent, width, height,
        tempNode.getPosition( true ) );
    drawLabel( g2d, tempNode, tempPos, nodeWidth, tempNode.getLabel( interpolationLabels ), drawLabels, curvedLabels, outlinedLabels, labelSize,
        minXPercent, maxXPercent, ratio, scaleLabels, highlightNeighbors, maxLabelLength, curvedLabelAngle, drawLabelBox, boldLabels,
        highlighted, neighborHighlightColor );
View Full Code Here

      double labelSize, double minX, double maxX, double minY, double maxY, double minXPercent, double maxXPercent, double minYPercent,
      double maxYPercent, int width, int height, double ratio, boolean scaleLabels, int maxLabelLength, int curvedLabelAngle,
      boolean boldLabels, DNVGraph graph, Map<Integer, Rectangle> boundingRectangles, Map<Integer, List<DNVNode>> nodesByYPos,
      Map<Integer, Map<Integer, Integer>> nodeAndKeyToIndex, boolean includeNodeBounds, int areaHeight )
  {
    Vector2D tempPos;
    Rectangle boundingRectangle;
    for( int i = 0; i < nodes.size(); i++ )
    {
      DNVNode tempNode = nodes.get( i );
      tempPos = transformPosition( minX, maxX, minY, maxY, minXPercent, maxXPercent, minYPercent, maxYPercent, width, height,
View Full Code Here

    else
    {
      g2d.setStroke( new BasicStroke( edgeThickness ) );
    }

    Vector2D tempPos;
    Vector2D tempPos2;
    tempPos = transformPosition( minX, maxX, minY, maxY, minXPercent, maxXPercent, minYPercent, maxYPercent, width, height, tempEdge.getFrom()
        .getPosition( true ) );
    // if( tempEdge.getFrom().hasAttribute( "screenPositionOffset" ) &&
    // !overview )
    // {
    // Vector2D screenPositionOffset =
    // (Vector2D)tempEdge.getFrom().getAttribute( "screenPositionOffset" );
    // tempPos.setX( tempPos.getX() + screenPositionOffset.getX() );
    // tempPos.setY( tempPos.getY() + screenPositionOffset.getY() );
    // }
    tempPos2 = transformPosition( minX, maxX, minY, maxY, minXPercent, maxXPercent, minYPercent, maxYPercent, width, height, tempEdge.getTo()
        .getPosition( true ) );
    // if( tempEdge.getTo().hasAttribute( "screenPositionOffset" ) &&
    // !overview )
    // {
    // Vector2D screenPositionOffset =
    // (Vector2D)tempEdge.getTo().getAttribute( "screenPositionOffset" );
    // tempPos2.setX( tempPos2.getX() + screenPositionOffset.getX() );
    // tempPos2.setY( tempPos2.getY() + screenPositionOffset.getY() );
    // }

    Vector3D edgeColor = tempEdge.getColor();
    if( tempEdge.isSelected() || ( tempEdge.isHighlighted() && tempEdge.getHighlightColor() == null ) || edgeColor == null
        || edgeColor.equals( DNVEntity.NO_COLOR ) )
    {
      g2d.setColor( color );
    }
    else if( tempEdge.isHighlighted() && tempEdge.getHighlightColor() != null )
    {
      g2d.setColor( new Color( tempEdge.getHighlightColor().getX(), tempEdge.getHighlightColor().getY(), tempEdge.getHighlightColor().getZ() ) );
    }
    else
    {
      g2d.setColor( new Color( edgeColor.getX(), edgeColor.getY(), edgeColor.getZ(), tempEdge.getAlpha() ) );
    }

    int pivotX = getPivot( width, (int)tempPos.getX(), (int)tempPos2.getX() );
    int pivotY = getPivot( height, (int)tempPos.getY(), (int)tempPos2.getY() );
    int temp = getPivot( width, pivotX, pivotY );
    if( temp == pivotX )
    {
      if( pivotX == (int)tempPos.getX() )
      {
        pivotY = (int)tempPos2.getY();
      }
      else
      {
        pivotY = (int)tempPos.getY();
      }
    }
    else
    {
      if( pivotY == (int)tempPos.getY() )
      {
        pivotX = (int)tempPos2.getX();
      }
      else
      {
        pivotX = (int)tempPos.getX();
      }
    }

    if( tempEdge.isDirectional() || tempEdge.getTo().getAlpha() != 1 || tempEdge.getFrom().getAlpha() != 1 )
    {
      double theta = Math.atan2( tempPos2.getY() - tempPos.getY(), tempPos2.getX() - tempPos.getX() );
      double arrowHeadLength = GraphFunctions.getDistance( tempPos, tempPos2 ) * 0.1;
      if( arrowHeadLength > MAX_ARROWHEAD_LENGTH )
        arrowHeadLength = MAX_ARROWHEAD_LENGTH;
      if( !overview && arrowHeadLength < MIN_ARROWHEAD_LENGTH )
        arrowHeadLength = MIN_ARROWHEAD_LENGTH;
      double angle1 = theta + Math.PI - phi;
      double angle2 = theta + Math.PI + phi;

      int x1 = (int)Math.round( tempPos2.getX() - tempEdge.getTo().getRadius() * nodeWidth / 2.0 * Math.cos( theta ) );
      int y1 = (int)Math.round( tempPos2.getY() - tempEdge.getTo().getRadius() * nodeWidth / 2.0 * Math.sin( theta ) );
      int x2 = (int)Math.round( tempPos.getX() + tempEdge.getFrom().getRadius() * nodeWidth / 2.0 * Math.cos( theta ) );
      int y2 = (int)Math.round( tempPos.getY() + tempEdge.getFrom().getRadius() * nodeWidth / 2.0 * Math.sin( theta ) );

      float direction1 = tempPos2.getX() - tempPos.getX();
      float direction2 = x1 - x2;
      if( direction1 == 0 && direction2 == 0 )
      {
        direction1 = tempPos2.getY() - tempPos.getY();
        direction2 = y1 - y2;
      }

      // g2d.fillRect( pivotX, pivotY, 50, 50 );

      if( ( direction1 > 0 && direction2 > 0 ) || ( direction1 < 0 && direction2 < 0 ) )
      {
        if( Settings.CURVED_EDGES )
        {
          QuadCurve2D quadCurve = new QuadCurve2D.Float( (int)tempPos2.getX(), (int)tempPos2.getY(), pivotX, pivotY, (int)tempPos.getX(),
              (int)tempPos.getY() );
          g2d.draw( quadCurve );
        }
        else
        {
          g2d.drawLine( x2, y2, x1, y1 );
        }
      }
      else
      {
        if( Settings.CURVED_EDGES )
        {
          QuadCurve2D quadCurve = new QuadCurve2D.Float( (int)tempPos2.getX(), (int)tempPos2.getY(), pivotX, pivotY, (int)tempPos.getX(),
              (int)tempPos.getY() );
          g2d.draw( quadCurve );
        }
        else
        {
          g2d.drawLine( x2, y2, x1, y1 );
        }
      }

      if( tempEdge.isDirectional() )
      {
        int x[] = { x1, (int)Math.round( x1 + arrowHeadLength * Math.cos( angle1 ) ),
            (int)Math.round( x1 + arrowHeadLength * Math.cos( angle2 ) ) };
        int y[] = { y1, (int)Math.round( y1 + arrowHeadLength * Math.sin( angle1 ) ),
            (int)Math.round( y1 + arrowHeadLength * Math.sin( angle2 ) ) };
        g2d.fillPolygon( x, y, 3 );
      }
    }
    else
    {
      if( Settings.CURVED_EDGES )
      {
        QuadCurve2D quadCurve = new QuadCurve2D.Float( (int)tempPos.getX(), (int)tempPos.getY(), pivotX, pivotY, (int)tempPos2.getX(),
            (int)tempPos2.getY() );
        g2d.draw( quadCurve );
      }
      else
      {
        g2d.drawLine( (int)tempPos.getX(), (int)tempPos.getY(), (int)tempPos2.getX(), (int)tempPos2.getY() );
      }
    }

    if( edgeThickness != tempEdge.getThickness() )
    {
View Full Code Here

    // Zoom transformation
    x = ( x - minXPercent ) / ( maxXPercent - minXPercent ) * width;
    y = ( y - minYPercent ) / ( maxYPercent - minYPercent ) * height;

    return new Vector2D( (float)x, (float)y );
  }
View Full Code Here

    y = y / height * ( maxY - minY ) + minY;

    float newX = (float)( x * ( globalMaxX - globalMinX ) + globalMinX );
    float newY = (float)( y * ( globalMaxY - globalMinY ) + globalMinY );

    return new Vector2D( newX, newY );
  }
View Full Code Here

    GraphsPathFilter.init();
    PaintBean pb = new PaintBean();
    pb.refreshGlobalBoundaries( (int)pb.getLevel() );
    for( DNVNode node : pb.getGraph().getNodes() )
    {
      Vector2D original = node.getPosition();
      Vector2D screen = transformPosition( pb, original );
      Vector2D transformBack = transformScreenToWorld( screen, pb );

      System.out.println( "original :" + original );
      System.out.println( "screen   :" + screen );
      System.out.println( "transform:" + transformBack );
      System.out.println();
View Full Code Here

   *            the new position
   * @return the movement
   */
  public static Vector2D getMovement( DNVNode node, Vector2D newPosition )
  {
    Vector2D tempPosition = new Vector2D( 0, 0 );
    if( node != null )
    {
      tempPosition = new Vector2D( node.getPosition( true ) );
      tempPosition.setX( -tempPosition.getX() );
      tempPosition.setY( -tempPosition.getY() );
      tempPosition.add( newPosition );
    }
    return tempPosition;
  }
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.