Export whole Graph Image

Schneidb
2007-01-26
2013-05-29
  • Schneidb

    Schneidb - 2007-01-26

    hi all,

    I search a way to export the whole graph in a jpeg or png file, and not only the visible graph.
    How can I do it easily?

    Thanks

     
    • Tom Nelson

      Tom Nelson - 2007-01-26

      jung-1.7.x does not have any special capability to do this.
      Since it uses the swing component superclass of VisualizationViewer
      to do the drawing, the only thing that shows in the image or printout
      it what is showing in the swing component.

      You could try to resize the VisualizationViewer to show the whole
      graph, remove any transformations (translate, rotate, scale, etc)
      and then print it. Here is a quick test you may find useful:

          public void writeWholeGraphJPEGImage(File file) {
              Dimension oldSize = vv.getSize();
              AffineTransform oldXformV = vv.getViewTransformer().getTransform();
              AffineTransform oldXformL = vv.getLayoutTransformer().getTransform();

              vv.setSize(vv.getGraphLayout().getCurrentSize());
              vv.getLayoutTransformer().setToIdentity();
              vv.getViewTransformer().setToIdentity();
              int width = vv.getWidth();
              int height = vv.getHeight();

              BufferedImage bi = new BufferedImage(width, height,
                      BufferedImage.TYPE_INT_RGB);
              Graphics2D graphics = bi.createGraphics();
              vv.paint(graphics);
              graphics.dispose();
             
              try {
                  ImageIO.write(bi, "jpeg", file);
              } catch (Exception e) {
                  e.printStackTrace();
              }
              vv.setSize(oldSize);
              vv.getLayoutTransformer().concatenate(oldXformL);
              vv.getViewTransformer().concatenate(oldXformV);

          }

      Tom Nelson

       
      • Nobody/Anonymous

        Hi Tom,

        I'm using a slight variation of your code to write a bounding-box
        sized image of the graph rather than the layout size.  The image comes
        out fine but the visualization viewer is not restored to its original
        view at the end of the method.

        I changed:

            vv.setSize(vv.getGraphLayout().getCurrentSize());
            vv.getLayoutTransformer().setToIdentity();
            vv.getViewTransformer().setToIdentity();

        to:

            vv.setSize(boundingBox.getSize());
            vv.getLayoutTransformer().setToIdentity();
            vv.getLayoutTransformer().translate(-boundingBox.getX(), -boundingBox.getY());
            vv.getViewTransformer().setToIdentity();

        Any idea on how to restore the visualization viewer to it's original state
        after this?  I've tried various permutations of this to no avail:

        vv.setSize(oldSize);
            vv.getLayoutTransformer().setToIdentity();
        vv.getLayoutTransformer().concatenate(oldXformL);
            vv.getViewTransformer().setToIdentity();
        vv.getViewTransformer().concatenate(oldXformV);

        Thanks,
        Paul

         
        • Tom Nelson

          Tom Nelson - 2007-05-22

          When you saved off the original AffineTransforms, did you make
          a defensive copy of them? If not, they will be changed by
          your operations on the layout or view transformer.

          Tom Nelson

           
          • Prathap

            Prathap - 2007-10-22

            Tom,

            Can you pl help me, how to work on these deffensive copies of AffineTransforms? I'm facing the same problem as paul facing.

            Thanks in advance.
            Prathap.

             
            • Tom Nelson

              Tom Nelson - 2007-10-22

              If you want a defensive copy of an AffineTransform,
              use its copy constructor or its clone method.

              Tom Nelson

               
    • Nobody/Anonymous

      I tried to do it. The result is a 600px x 600px black image. Do you have any ideas??

       
      • Tom Nelson

        Tom Nelson - 2007-02-02

        That usually happens when the JComponent you are drawing is
        of size width=0, height=0.

        You need to make sure that the JComponent is either really
        showing, or thinks that is it.
        If you are drawing a component that is not showing, be sure
        to call addNotify and setSize on it.

        Hope this helps,
        Tom Nelson

         
    • Schneidb

      Schneidb - 2007-02-05

      Ok thanks you for this help, I try its works fine.
      But is it possible to export and see the whole graph, with the current zoom...

      Perhaps, can we get all the other part of the graph that not displayed currently.
      (and than concatenate it to the bufferImage ?)

      I'm just trying to find a solution, sorry for the question.

       
      • Tom Nelson

        Tom Nelson - 2007-02-05

        jung-1.7.6 does not have this capability.

        jung-2.0 has the capability to get image tiles from any
        part of the graph, and at any scale/translation/rotation/etc.
        The intent is that this capability will be useful when used
        on the server side of a thin-client/server application.
        You may want to wait and use jung-2 instead.

        Tom Nelson

         
    • Nobody/Anonymous

      That did it - thank you very much.

       
    • Prathap

      Prathap - 2007-10-23

      Tom,

      I already used the clone method. But my question is where to make these AffineTransforms as defensive and where to set these to my VisualisationViewer? For example if my mouse wheel event changed the AffineTransforms, Do I need to take backup copy of them in the event handling function and then sets these transform to my VV after importing the whole graph?

      If can post any sample code, that would help me to understand the entire scenario.

      Thanks,
      Prathap.

       
  • Anonymous - 2011-08-03

    Hi Tom,

    you said "jung-2.0 has the capability to get image tiles from any part of the graph, and at any scale/translation/rotation/etc."
    May I ask what that approach would be assuming one uses GraphZoomScrollPane?

    Thanks for your help,
    Martin

     
  • Akram Badr

    Akram Badr - 2013-02-09

    Hi ,
    how could we use JUNG 2 to get image tiles from any part of the graph, and at any scale/translation/rotation/etc."

    please i need your help :(

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks