3

I'm using the JUNG framework, with the FRLayout. Like this:

layout = new FRLayout<String, Number>(graph);
preferredSize = new Dimension(600, 600);

final VisualizationModel<String, Number> visualizationModel = 
new DefaultVisualizationModel<String, Number>(layout, preferredSize);
vv = new VisualizationViewer<String, Number>(visualizationModel, preferredSize);

I've placed this in a GraphZoomScrollPane. I can zoom in, zoom out, move the graph around until it looks just like I want it, but I would like it to be like that when I start my Swing application.

What I want exactly, is that the graph's PreferredSize dynamically adjusts based on the graph size, so that when I load large graphs, I don't have to zoom in a billion times before the vertices don't overlap anymore.

What doesn't fit in my panel should normally then "disappear" behind the scrollbars.

Pieter-Jan
  • 1,675
  • 2
  • 19
  • 25

1 Answers1

1

You can scale it programmatically using the following:

double amount = 1.0;    // Or negative to zoom out.
ScalingControl scaler = new CrossoverScalingControl();
scaler.scale(vv, amount > 0 ? 1.1f : 1 / 1.1f, vv.getCenter());

Note: I got this from StackOverflow before (so the credit for this code is not mine), but I can't seem to find the original question.

EDIT:

I found it:

How to manually set the zoom on a Jung visualisation?

Community
  • 1
  • 1
sdasdadas
  • 23,917
  • 20
  • 63
  • 148
  • Thank you for your answer, I use this method for my zoom functions indeed. But I don't know how to calculate the factor, based on the number of vertices I have, and the layout I'm using. – Pieter-Jan Oct 23 '12 at 11:34
  • I understand - I'm trying to achieve something similar but it's not currently high priority. If I do discover a simple way I'll edit my post and let you know. – sdasdadas Oct 25 '12 at 17:33
  • Sorry that this is late but try using vv.scaleToLayout(new CrossoverScalingControl()). – sdasdadas Nov 26 '12 at 19:56
  • 1
    No, it doesn't quite seem to do the trick. But that's ok, I've found a workaround. Upon startup, I show the Graph up to level 2, and to see the lower levels, you need to expand the nodes at level 2. I'll play around with it some more though, should I find the solution, I will post it here. – Pieter-Jan Nov 28 '12 at 11:25
  • This is a late reply but you have to setSize on the layout. The scaleToLayout function works based off of the ratio of vv.getPreferredSize / layout.getSize. – sdasdadas Mar 27 '13 at 16:02