Package net.wigis.graph.dnv.utilities

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


      Graphics g = img.createGraphics();
      Graphics2D g2d = (Graphics2D)g;
      g2d.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON );

      // g.clearRect( 0, 0, size + 1, size + 1 );
      Vector2D pos = new Vector2D( imageSize / 2, imageSize / 2 );
      size /= node.getRadius();
      try
      {
        ImageRenderer.drawLabel( g2d, node, pos, size, label, pb.isShowLabels(), pb.isCurvedLabels(), pb.isOutlinedLabels(),
            pb.getLabelSize(), 1, 1, 1, pb.isScaleNodesOnZoom(), pb.isHighlightNeighbors(), pb.getMaxLabelLength(),
View Full Code Here


        {
          List<DNVNode> nodes = graph.getNodes( level );
          SortByLabelSize sbls = new SortByLabelSize( pb.isHighlightNeighbors() );
          Collections.sort( nodes, sbls );
          DNVNode node;
          Vector2D screenPosition;
          double distance;
          double minDistance = Integer.MAX_VALUE;
          int nodeI = -1;
          int distX = 0; // dist b/w this node and mouse click
          int distY = 0;

          // Check if user clicked on a solid node label
          for( int i = nodes.size() - 1; i >= 0; i-- )
          {
            node = nodes.get( i );
            if( node.isVisible() && ( node.isForceLabel() || pb.isShowLabels() ) && node.getProperty( "faded" ) == null )
            {
              screenPosition = ImageRenderer.transformPosition( globalMinX, globalMaxX, globalMinY, globalMaxY, minX, maxX, minY, maxY,
                  width, height, node.getPosition( true ) );
              ImageRenderer.Rectangle boundingRectangle = ImageRenderer.getRectangleBoundingTheLabel( node, screenPosition, null,
                  (int)Math.round( pb.getNodeSize() * node.getRadius() ), node.getLabel( pb.isInterpolationLabels() ), pb
                      .isCurvedLabels()
                      || node.isCurvedLabel(), pb.getLabelSize(), minX, maxX, width / pb.getWidth(), pb.isScaleLabels(), pb
                      .getMaxLabelLength(), pb.getCurvedLabelAngle(), pb.isBoldLabels(), false, false );
              if( mouseDownX >= boundingRectangle.left() && mouseDownX <= boundingRectangle.right()
                  && mouseDownY <= boundingRectangle.bottom() && mouseDownY >= boundingRectangle.top() )
              {
                distX = (int)( mouseDownX - screenPosition.getX() );
                distY = (int)( mouseDownY - screenPosition.getY() );
                node.setProperty( "distX", "" + distX );
                node.setProperty( "distY", "" + distY );
                minDistance = 0;
                nodeI = i;
                break;
              }
            }
          }

          if( nodeI == -1 )
          {
            // loop thru all nodes to find closest node
            for( int i = nodes.size() - 1; i >= 0; i-- )
            {
              node = nodes.get( i );
              if( node.isVisible() )
              {
                screenPosition = ImageRenderer.transformPosition( globalMinX, globalMaxX, globalMinY, globalMaxY, minX, maxX, minY,
                    maxY, width, height, node.getPosition( true ) );

                // find node closest to mouseDown
                distX = (int)( mouseDownX - screenPosition.getX() );
                distY = (int)( mouseDownY - screenPosition.getY() );

                distance = distX * distX + distY * distY;

                if( distance < minDistance )
                {
                  node.setProperty( "distX", "" + distX );
                  node.setProperty( "distY", "" + distY );

                  minDistance = distance;
                  nodeI = i;
                }
              }
            }
          }

          if( nodes.size() > 0 && nodeI != -1 )
          {
            node = nodes.get( nodeI );

            double nodeWidth;
            nodeWidth = getNodeWidth( pb, width, minX, maxX, node.getRadius() );
            // check if selected node is close enough to mouseDown
            if( Settings.DEBUG )
              System.out.println( "Minimum distance was " + Math.sqrt( minDistance ) );

            if( Math.sqrt( minDistance ) >= nodeWidth )
            {
              // Still no node selected so check nodes with faded
              // labels
              for( int i = nodes.size() - 1; i >= 0; i-- )
              {
                node = nodes.get( i );
                if( node.isVisible() && ( node.isForceLabel() || pb.isShowLabels() ) && node.getProperty( "faded" ) != null
                    && Float.parseFloat( node.getProperty( "faded" ) ) > 0.1 )
                {
                  screenPosition = ImageRenderer.transformPosition( globalMinX, globalMaxX, globalMinY, globalMaxY, minX, maxX,
                      minY, maxY, width, height, node.getPosition( true ) );
                  ImageRenderer.Rectangle boundingRectangle = ImageRenderer.getRectangleBoundingTheLabel( node, screenPosition,
                      null, (int)Math.round( pb.getNodeSize() * node.getRadius() ),
                      node.getLabel( pb.isInterpolationLabels() ), pb.isCurvedLabels() || node.isCurvedLabel(), pb
                          .getLabelSize(), minX, maxX, width / pb.getWidth(), pb.isScaleLabels(), pb.getMaxLabelLength(),
                      pb.getCurvedLabelAngle(), pb.isBoldLabels(), false, false );
                  if( mouseDownX >= boundingRectangle.left() && mouseDownX <= boundingRectangle.right()
                      && mouseDownY <= boundingRectangle.bottom() && mouseDownY >= boundingRectangle.top() )
                  {
                    distX = (int)( mouseDownX - screenPosition.getX() );
                    distY = (int)( mouseDownY - screenPosition.getY() );
                    node.setProperty( "distX", "" + distX );
                    node.setProperty( "distY", "" + distY );
                    minDistance = 0;
                    nodeI = i;
                    break;
                  }
                }
              }
            }

            node = nodes.get( nodeI );

            nodeWidth = getNodeWidth( pb, width, minX, maxX, node.getRadius() );
            // check if selected node is close enough to mouseDown
            if( Settings.DEBUG )
              System.out.println( "Minimum distance was " + Math.sqrt( minDistance ) );
            if( Math.sqrt( minDistance ) < nodeWidth )
            {
              // if( node.isSelected() )
              // {
              // sameNode = true;
              // }
              pb.setSelectedNode( node, ctrlPressed );
              selectedNode = node;
            }
            else
            {
              if( pb.getSelectedNode() != null )
              {
                pb.setSelectedNode( null, ctrlPressed );
//                runDocumentTopicsCircularLayout( request, pb, graph, level );
              }
            }
          }

          if( selectedNode == null )
          {
            minDistance = Integer.MAX_VALUE;
            List<DNVEdge> edges = graph.getEdges( level );
            DNVEdge edge;
            Vector2D screenPosition2;
            int edgeI = 0;
            for( int i = 0; i < edges.size(); i++ )
            {
              edge = edges.get( i );
              if( edge.isVisible() )
View Full Code Here

    }

    // int level = (int)pb.getLevel();
    DNVGraph graph = pb.getGraph();

    Vector2D nodeWorldPos;

    Iterator<Node> nodeIterator = nodes.values().iterator();
    while( nodeIterator.hasNext() )
    {
      tempNode = nodeIterator.next();
      x = tempNode.getX();
      y = tempNode.getY();
      id = tempNode.getId();
      selected = tempNode.isSelected();
      nodeWorldPos = ImageRenderer.transformScreenToWorld( x, y, minX, maxX, minY, maxY, pb.getGlobalMinX(), pb.getGlobalMaxX(), pb
          .getGlobalMinY(), pb.getGlobalMaxY(), pb.getWidth(), pb.getHeight() );
      DNVNode node = (DNVNode)graph.getNodeById( id );
      if( node != null )
      {
        Vector2D movement = ImageRenderer.getMovement( node, nodeWorldPos );
        node.moveRelatedNodes( movement, true, false );
        node.setPosition( nodeWorldPos );
        if( selected )
        {
          pb.setSelectedNode( node, false );
View Full Code Here

  public Vector2D performInteraction( PaintBean pb, DNVGraph graph, int width, int height, double minX, double minY, double maxX, double maxY, int mouseUpX, int mouseUpY,
      boolean sameNode, int level, double globalMinX, double globalMaxX, double globalMinY, double globalMaxY, DNVNode selectedNode, boolean released )
  {
    if( selectedNode != null )
    {
      Vector2D movement = im.performInteraction( pb, graph, width, height, minX, minY, maxX, maxY, mouseUpX, mouseUpY, sameNode, level, globalMinX, globalMaxX, globalMinY, globalMaxY, selectedNode, released );
     
      selectedNode.setProperty( "fixed", "true" );
     
      for( int i = 5; i > 0; i-- )
      {
View Full Code Here

   * @param fill
   *            the fill
   */
  public Rectangle( Vector2D topLeft, Vector2D bottomRight, float thickness, Vector3D color, float alpha, boolean fill )
  {
    this.topLeft = new Vector2D( topLeft );
    this.bottomRight = new Vector2D( bottomRight );
    this.thickness = thickness;
    this.color = new Vector3D( color );
    this.fill = fill;
    this.alpha = alpha;
  }
View Full Code Here

   */
  @Override
  public void draw( Graphics2D g2d, PaintBean pb, double minXPercent, double maxXPercent, double minYPercent, double maxYPercent,
      double globalMinX, double globalMaxX, double globalMinY, double globalMaxY, double width, double height, boolean overview )
  {
    Vector2D screenTopLeft = ImageRenderer.transformPosition( globalMinX, globalMaxX, globalMinY, globalMaxY, minXPercent, maxXPercent,
        minYPercent, maxYPercent, width, height, topLeft );
    Vector2D screenBottomRight = ImageRenderer.transformPosition( globalMinX, globalMaxX, globalMinY, globalMaxY, minXPercent, maxXPercent,
        minYPercent, maxYPercent, width, height, bottomRight );
    Color oldColor = g2d.getColor();
    Stroke oldStroke = g2d.getStroke();
    g2d.setColor( new Color( color.getX(), color.getY(), color.getZ(), alpha ) );
    g2d.setStroke( new BasicStroke( thickness ) );
    int x = (int)Math.round( screenTopLeft.getX() );
    int y = (int)Math.round( screenTopLeft.getY() );
    int rectWidth = (int)Math.round( screenBottomRight.getX() - screenTopLeft.getX() );
    int rectHeight = (int)Math.round( screenBottomRight.getY() - screenTopLeft.getY() );
    if( x < 0 )
    {
      rectWidth += x;
      x = 0;
    }
View Full Code Here

  @Override
  public Vector2D performInteraction( PaintBean pb, DNVGraph graph, int width, int height, double minX, double minY, double maxX, double maxY, int mouseUpX, int mouseUpY,
      boolean sameNode, int level, double globalMinX, double globalMaxX, double globalMinY, double globalMaxY, DNVNode selectedNode, boolean released )
  {
    return new Vector2D( 0, 0 );
  }
View Full Code Here

   * @param isScreenPosition
   */
  private void init( Vector2D center, float innerRadius, float outerRadius, float thickness, Vector3D color, float alpha, boolean fill,
      boolean isScreenPosition )
  {
    this.center = new Vector2D( center );
    this.innerRadius = innerRadius;
    this.outerRadius = outerRadius;
    this.thickness = thickness;
    this.color = new Vector3D( color );
    this.fill = fill;
View Full Code Here

   */
  @Override
  public void draw( Graphics2D g2d, PaintBean pb, double minXPercent, double maxXPercent, double minYPercent, double maxYPercent, double globalMinX, double globalMaxX,
      double globalMinY, double globalMaxY, double width, double height, boolean overview )
  {
    Vector2D screenCenter;
    if( isScreenPosition )
    {
      screenCenter = center;
    }
    else
    {
      screenCenter = ImageRenderer.transformPosition( globalMinX, globalMaxX, globalMinY, globalMaxY, minXPercent, maxXPercent,
        minYPercent, maxYPercent, width, height, center );
    }

    Color oldColor = g2d.getColor();
    Stroke oldStroke = g2d.getStroke();
    g2d.setColor( new Color( color.getX(), color.getY(), color.getZ(), alpha ) );
    g2d.setStroke( new BasicStroke( thickness ) );
    int x = (int)Math.round( screenCenter.getX() );
    int y = (int)Math.round( screenCenter.getY() );
    int outerCircleWidth = (int)Math.round( outerRadius * 2.0f );
    int innerCircleWidth = (int)Math.round( innerRadius * 2.0f );
    Ellipse2D.Float outerCircle = new Ellipse2D.Float( x - ( outerCircleWidth / 2.0f ), y - ( outerCircleWidth / 2.0f ), outerCircleWidth,
        outerCircleWidth );
    Ellipse2D.Float innerCircle = new Ellipse2D.Float( x - ( innerCircleWidth / 2.0f ), y - ( innerCircleWidth / 2.0f ), innerCircleWidth,
View Full Code Here

    Timer moveTimer = new Timer( Timer.MILLISECONDS );
    if( selectedNode != null )
    {
      List<DNVNode> nodes = graph.getInterpolationList( level );
      DNVNode tempNode;
      Vector2D tempMove = new Vector2D();
      for( int i = 0; i < nodes.size(); i++ )
      {
        tempNode = nodes.get( i );
        if( tempNode.getDistanceFromNodeWithId( selectedNode.getId() ) != Integer.MAX_VALUE && !tempNode.isSelected() && selectedNode != null )
        {
          tempMove.set( movement );
          if( tempNode != null && selectedNode != null )
          {
            tempMove.dotProduct( tempNode.getInterpolationWeight( selectedNode.getId() ) );
          }

          // System.out.println(
          // tempNode.getDistanceFromSelectedNode() +
          // " : " + tempNode.getInterpolationWeight() + " : " +
          // tempMove
          // + " : " + tempMove.length() );
          moveTimer.setStart();
          tempNode.move( tempMove, true, false );
          moveTimer.setEnd();
        }
      }

      if( pb.isAvoidNodeOverlap() )
      {
//        int count = 0;
        float xRatio = (float)( pb.getWidth() / GraphFunctions.getGraphWidth( nodes, true ) );
        float yRatio = (float)( pb.getHeight() / GraphFunctions.getGraphHeight( nodes, true ) );
        // System.out.println( "cursors " + activeCursors.size() );
        // double nodeSize = 36;
        double nodeSize = ImageRenderer.getNodeWidth( pb.getNodeSize(), pb.getMinX(), pb.getMaxX(), 1 ) * 2;
        // System.out.println( "nodeSize" + nodeSize );
        Vector2D lastMove = movement;

        if( selectedNode != null && lastMove.length() > 0 )
        {
          // System.out.println( "distances " +
          // selectedNode.getDistances().size() );
          for( Integer distance : selectedNode.getDistances() )
          {
            Map<Integer, DNVNode> nodesAtDistance = selectedNode.getNodesAtDistance( distance );

            if( nodesAtDistance.size() > 0 )
            {
              Map<String, List<DNVNode>> nodesAtPosition = new HashMap<String, List<DNVNode>>();

              for( DNVNode node : nodesAtDistance.values() )
              {
                String key = getKey( node, nodeSize, pb );
                List<DNVNode> theNodes = nodesAtPosition.get( key );
                if( theNodes == null )
                {
                  theNodes = new ArrayList<DNVNode>();
                  nodesAtPosition.put( key, theNodes );
                }
                theNodes.add( node );
              }

              for( DNVNode node : nodesAtDistance.values() )
              {
                if( node != selectedNode )
                {
                  for( DNVNode node2 : nodesAtPosition.get( getKey( node, nodeSize, pb ) ) )
                  {
                    if( node2 != node )
                    {
//                      count++;

                      int nodeWidth = ImageRenderer.getNodeWidth( pb.getNodeSize(), pb.getMinX(), pb.getMaxX(), 1 );
                      Vector2D difference = pb.getScreenPosDifference( node, node2 );
                      float randomSign = getRandomSign();
                      Vector2D lastMoveRotated = new Vector2D( randomSign * -1 * lastMove.getY(), randomSign * lastMove.getX() );
                      if( difference.length() == 0 )
                      {
                        difference.set( lastMoveRotated );
                        difference.normalize();
                      }
                      float overlap = pb.getOverlapAmount( node, node2, nodeWidth, difference );
                      if( overlap > 0 )
                      {
                        difference.normalize();
                        Vector2D direction = difference.dotProduct( overlap ).dotProduct( 0.1f );

                        float dotProduct = direction.dotProduct( lastMoveRotated ) / lastMoveRotated.length();

                        Vector2D projection = lastMoveRotated.normalize().dotProduct( dotProduct );

                        projection.setX( projection.getX() / xRatio );
                        projection.setY( projection.getY() / yRatio );

                        if( node.hasAttribute( "align_movement" ) )
                        {
                          Vector2D previousMovement = (Vector2D)node.getAttribute( "align_movement" );
                          if( previousMovement != null )
                          {
                            projection.add( previousMovement );
                          }
                        }
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.