3

I am working with the JUNG libraries to create graphs in Java. I need to fit a graph to its parent frame and set the view so that the graph is shown in the center of the view.

I have managed to set the zoom to the correct size using code from here: How to manually set the zoom on a Jung visualisation? however the shrunken graph remains in the same place. I have also written a function to move the graph using code from here: How to programatically pan a VisualizationViewer with Jung (the java library)?.

The problem remains how do I work out how much the graph needs to be panned from its current location to center in the view. How can I find the current location of the graph?

Thanks

Community
  • 1
  • 1

1 Answers1

2

It seems that the way to do this is using a ScalingControl. Using the scaling control it is very easy to make sure the graph fits its parent frame, the code to do this is:

ScalingControl visualizationViewerScalingControl
            = new CrossoverScalingControl();

visualizationViewer.scaleToLayout(visualizationViewerScalingControl);

I found the way to do this by looking at the source code for the SatelliteViewDemo which also implements a SatelitteView; this allows for a zoomed out view of the graph alongside the full size version.