After skimming the message boards, I had put together a graphmouseplugin that attempts to do a zoom into a rectangular area in which you have drawn a box. While I have it properly adjusting determining the new center (center of rectangle), and moving the view there, I cannot seem to get the zoom scale right. It is always overzooming. For awhile I was just zooming out as a hack, but that doesn't always work correctly. I really need to understand why my zoom scale is not correct. I have taken out the mouseReleased portion of the code here to show you. At this point, the rectangle has been properly rendered. I am getting the center translation ok, it is just the zoom scale that is not working.
public void mouseReleased(MouseEvent e)
final VisualizationViewer<V, E> vv = (VisualizationViewer)e.getSource();
if (e.getModifiers() == modifiers)
if (down != null)
if (mRect != null)
//Convert rectangle screen location to a coordinate location
Point2D rectVIEWCenter = new Point2D.Double(mRect.getFrame().getCenterX(), mRect.getFrame().getCenterY());// layout.transform(vertex);
System.out.print("Rect View Center : " + rectVIEWCenter.toString());
Point2D rectLAYOUTCenter = vv.getRenderContext().getMultiLayerTransformer().inverseTransform(rectVIEWCenter);
System.out.print("Rect Layout Center : " + rectLAYOUTCenter.toString());
//convert screen center point to a coordinate location
Point2D vvVIEWCenter = vv.getRenderContext().getMultiLayerTransformer().inverseTransform(vv.getCenter());
System.out.print("VV center point in layout plane: " + vvVIEWCenter.toString());
//Calculate the change in location from the current center to the rectangle center
final double diffx = (vvVIEWCenter.getX() - rectLAYOUTCenter.getX());
final double diffy = (vvVIEWCenter.getY() - rectLAYOUTCenter.getY());
System.out.print("x diff is " + diffx);
System.out.print("y diff is " + diffy);
//Cause the graph to transform to new location by moving the difference
//Now calculate a proportion to use for the scaling factor
//double layoutWidth = vv.getGraphLayout().getSize().getWidth();
double layoutWidth = vv.getSize().getWidth();
System.out.print("layout width : " + layoutWidth);
System.out.print("rect width : " + mRect.getWidth());
//double layoutHeight = vv.getGraphLayout().getSize().getHeight();
double layoutHeight = vv.getSize().getHeight();
System.out.print("layout height : " + layoutHeight);
System.out.print("rect width : " + mRect.getHeight());
//Zoom is proportional to the view over the selected area
float scalingFactor = (float)Math.min(layoutWidth/mRect.getWidth(),layoutHeight/mRect.getHeight());
System.out.print("Scaling factor is : " + scalingFactor);
//ensure the scaling factor is a valid value...if the user just left clicks, it
//could be infinity or even a really small box that would be useless
if(scalingFactor > 0 && scalingFactor < 500)
final ScalingControl scaler = new CrossoverScalingControl();
scaler.scale(vv, scalingFactor, vv.getCenter());
//Clear things for the next one
down = null;
mRect.setFrame(0, 0, 0, 0);
Just skimming your code, I wonder if you would have better luck if your scalingFactor were based on the ratio of the drawn box to the size of the view instead of the size of the layout.
To investigate further, I would need a simple but complete application that demonstrates the problem you are seeing.
I actually had both the view and layout sizes in there...one was commented out. I was trying things because I really didn't have any idea. Neither resolved the overzooming.
I did switch to a:
final ViewScalingControl scaler = new ViewScalingControl();
which caused the shapes to enlarge during a box zoom, but the scaling worked exactly as you would expect (e.g everything in the box was displaying and zoomed in as far as possible given all variables so that the view only contained what was in the box).
I had my regular +, -, and home zoom toolbar buttons using the crossover scaler, so I just switched all scaling to use the view scaler. This seems to at least give me a working solution where before the overzoom was so much that it really wasn't useable for box zoom. When I say overzoom, I would perform a "box zoom" and the zoom was so far in that I would typically have to click the zoom out button 5 or more times to get to what the view really should have looked like after the box zoom.
I am not saying the crossover scaler doesn't work, because I used the crossover scaler with the regular toolbar +,-, home buttons (which I got from the jung samples) and they worked perfectly. It just seems like the algorithm I have for box zoom using the crossover doesn't seem to like the factor I do not understand it totally.
Hi I am trying to findout that how could i zoom a particular vertex whose locations are retrieved so that out of large number of nodes present in bunch,desired node is highlighted and displayed with zoomin
Log in to post a comment.
Sign up for the SourceForge newsletter:
You seem to have CSS turned off.
Please don't fill out this field.