Menu

Coordinates

yugen
2002-11-23
2003-02-06
  • yugen

    yugen - 2002-11-23

    [Continued from https://sourceforge.net/forum/message.php?msg_id=1763622 .]

    > And how does GVF represent co-ordinate?
    > Where is (0,0)? is it the upper left
    > corner? or the middle of the graph pane?

    Node coordinates are stored in a royere.cwi.layout.Coordinates object.

    The origin (0,0) is not necessarily in the center of view.  When you invoke a layout's computePositions() method, it builds up an "enclosing box" that is big enough to enclose all of the known nodes, plus a "white space" margin.  This enclosing box represents the four corners of the view when a graph is initially laid out (before you do any zooming or panning).

    You can see the coordinates of any particular node by selecting the View->Enable Tool Tips menu item, and then hovering your mouse over the node.

     
    • sam

      sam - 2002-11-23

      Thanks for your support.

      Can I find out how big is that "enclosing box"? I am trying to  use GVF in a non-swing application for auto-layout figures in diagram.

      For the sample program I show you, how can I translate the output coordinates to the co-ordinates in my Panel?

      The co-ordinate I got are:
      x=1.2000000000000002 y=0.0
      x=0.0 y=-1.0
      x=1.2000000000000002 y=-1.0
      x=2.4000000000000004 y=-1.0

      The X- coordinate are 1.2 apart. But the y-coordinate are 1 apart. Why there is a difference?  Is the unit  in pixel?
      And  what if the nodes are 10 pixels wide and 20 pixels in height? Or what if the nodes are different in width and height.

      Thanks again.

       
    • sam

      sam - 2002-11-23

      Thanks for your support.

      Can I find out how big is that "enclosing box"? I am trying to  use GVF in a non-swing application for auto-layout figures in diagram.

      For the sample program I show you, how can I translate the output coordinates to the co-ordinates in my Panel?

      The co-ordinate I got are:
      x=1.2000000000000002 y=0.0
      x=0.0 y=-1.0
      x=1.2000000000000002 y=-1.0
      x=2.4000000000000004 y=-1.0

      The X- coordinate are 1.2 apart. But the y-coordinate are 1 apart. Why there is a difference?  Is the unit  in pixel?
      And  what if the nodes are 10 pixels wide and 20 pixels in height? Or what if the nodes are different in width and height.

      Thanks again.

       
    • yugen

      yugen - 2002-11-24

      > Can I find out how big is that "enclosing box"? I
      > am trying to use GVF in a non-swing application
      > for auto-layout figures in diagram.

      EnclosingBox eb =  layout.getEnclosingBox(graph);

      > For the sample program I show you, how can I
      > translate the output coordinates to the co-ordinates
      > in my Panel?

      The EnclosingBox object has four methods -- getXmin(), getXmax(), getYmin(), and getYmax() -- which define the coordinates of a square.  All the node coordinates assigned by the layout will be inside this square.

      Presumably your panel is also square (or at least rectangular), so translating the layout coordinates to your panel's coordinates space should be a matter of simple algebra.

      > The X- coordinate are 1.2 apart. But the y-coordinate
      > are 1 apart. Why there is a difference?

      To be honest, I don't know.  (I wasn't the author of ReingoldTilford.java.)  However, the Javadocs mention that it is based on the paper of Reingold & Tilford (IEEE Trans. Soft. Engineering, 1981), with some additions and modifications by Walker (Soft. Pract. and Experience, 1990).  These references might be worth checking out, if you're curious.

      > Is the unit in pixel? And what if the nodes are
      > 10 pixels wide and 20 pixels in height? Or what
      > if the nodes are different in width and height.

      I don't think the coordinates are meant to have anything to do with pixels.  The dimensions of a node (in pixels) should be on a much smaller scale than the differences between node locations in the view panel.

       
    • sam

      sam - 2002-11-24

      > I don't think the coordinates are meant to have anything to
      > do with pixels. The dimensions of a node (in pixels)
      > should be on a much smaller scale than the differences
      > between  node locations in the view panel.

      Thanks.  If the co-ordinates are not related to pixels?
      How can I use those co-ordinates when I draw the figure on my panel?

      For example, the co-ordinates are the following:
      x=1.2000000000000002 y=0.0
      x=0.0 y=-1.0
      x=1.2000000000000002 y=-1.0

      And my nodes are 10 pixels wide and 20 pixels high, do I need to multiple those coordinates by a factor (x by 10, y by 20), before i can draw them?

      x=2.4000000000000004 y=-1.0

       
      • yugen

        yugen - 2002-11-27

        > Thanks. If the co-ordinates are not related to pixels?
        > How can I use those co-ordinates when I draw
        > the figure on my panel?

        Have a look at ElementDrawing.nodeGlyph(), which uses the rVertex() method to draw a node at a particular position:

            // Draw a rectangle
            rVertex(p.x - sX, p.y - sY, 0.0);
            rVertex(p.x - sX, p.y + sY, 0.0);
            rVertex(p.x + sX, p.y + sY, 0.0);
            rVertex(p.x + sX, p.y - sY, 0.0);

        where p is the node position and sX and sY are the dimensions of the node size.

        Java2DElementDrawing.java provides a concrete implementation of rVertex(), if you want to see the details.

         
    • Michael

      Michael - 2003-02-06

      I have a little question about the same subject. Suppose I get coordinates (1,0)  ,  (0,1)  ,  (1,1)  ,  (2,1).
      Now suppose that they map onto rectangles with some text in it. It makes a lot of difference how big the text is. I mean, "abc"  requires much less space than "aaaaaaaaaaaaaabbbbbbbbbbbb"
      So my concrete problem is that the rectangles are different sizes, and that they overlap in the layout. So I ask myself whether the only possible way to solve this is to get the maximum of the node sizes, and then take this into account to adapt the coordinates.
      thanks...
      Michael.

       

Log in to post a comment.