Zoom doesn't respect specifications

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Cdr

Zoom doesn't respect specifications

Post by Cdr » Thu Oct 20, 2005 8:32 am

I think the problem has been pointed out already, but since I'm facing it right now, let's mention it again :?

The method zoomInBoth(double x,double y) and all the other related methods, don't work right.

In the specifications (Javadoc), it's said that
Zooms in on an anchor point (specified in screen coordinate space).

Parameters:
x - the x value (in screen coordinates).
y - the y value (in screen coordinates).
But in fact the method is completely ignoring the arguments x and y and just zooms on the center of the screen ; I suppose that it somehow makes use of the zoom methods of ValueAxis, which as far as I could notice, have the same problem.

I'm trying to write a workaround, hoping it could be used for fixing that bug :)

Cdr
Posts: 9
Joined: Thu Oct 20, 2005 8:39 am
Location: Belgium
Contact:

Post by Cdr » Thu Oct 20, 2005 8:56 am

Here's a simple workaround, hope it could help others :)

Code: Select all

	/**
	 * Zooms a particular axis on a point, workaround to the centered version of ValueAxis
	 * @param axis
	 * @param x
	 * @param zoomFactor
	 */
	public static void zoomOnPoint(ValueAxis axis, double x, double zoomFactor) {
		double oldLowerBound = axis.getLowerBound() ;
		double oldUpperBound = axis.getUpperBound() ;
		
		double lowerDistance = (x-oldLowerBound)*zoomFactor ;
		double upperDistance = (oldUpperBound-x)*zoomFactor ;
		
		double newLowerBound = x-lowerDistance ;
		double newUpperBound = x+upperDistance ;
		
		axis.setRange(newLowerBound,newUpperBound) ;
	}
I made the method static for now but if it works fine, it could be included in the ValueAxis class I guess :)
Cdr
Theory is when we know everything but nothing works.
Practice is when everything works but noone knows why.
Here we joined theory and practice : nothing works and noone knows why ...

Locked