AutoRange and Zoom

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
dorseywright
Posts: 4
Joined: Tue Feb 05, 2008 5:41 pm

AutoRange and Zoom

Post by dorseywright » Tue Feb 05, 2008 5:44 pm

Hello there! I'm currently using JFreeCharts to plot some Times Series data, and have noticed that when I zoom into the chart and then zoom back out, the Y-axis ranges I specify for the chart are no longer adhered too. It's almost as if autorange gets set back equal to true even though I explicitly turned it off. Any ideas on what could be causing this?

Thanks!
Chuck

aznoohwee
Posts: 4
Joined: Fri Feb 15, 2008 4:58 pm

Post by aznoohwee » Fri Feb 15, 2008 11:37 pm

I can also confirm this behavior.

ReneGibson
Posts: 3
Joined: Wed Feb 27, 2008 7:00 pm

An Additional Problem

Post by ReneGibson » Wed Feb 27, 2008 7:14 pm

Although my Y data ranges from 10 to 50, "Auto Range" consistently sets the minimum Y axis value at 0. This only happens when all of the Y data is > 0. The opposite happens when all the Y data is < 0: the maximum Y axis value is set to 0, despite the data only containing values from -100 to -30. Everything seems fine if the Y data contains both positive and negative values. The X axis works fine in any case. I'm not setting any axis ranges. I downloaded the latest version of JFreeChart (1.0.9) and JCommon (1.0.12) to see it that fixed the problem. It didn't.

skunk
Posts: 1087
Joined: Thu Jun 02, 2005 10:14 pm
Location: Brisbane, Australia

Post by skunk » Wed Feb 27, 2008 8:37 pm

Did you try calling

Code: Select all

axis.setAutoRangeIncludesZero(false);

chrisTemp
Posts: 1
Joined: Wed Feb 27, 2008 9:41 pm

Post by chrisTemp » Wed Feb 27, 2008 9:43 pm

I was stuck with something like this, I ended up doing something that kind of works. It has the range axis around 0 to 130000, but when you zoom out it goes to 0 to 131750, but it's close enough and you can't really tell.

I know you're not using this type of plot, but something to lead you in the right direction. I remember there being a problem like this back in 1.0.2 or something, and I ended up just hacking the class to fix it.

Good luck.

plot.getRangeAxis().setRange(0, 130000);

((NumberAxis)plot.getRangeAxis()).setAutoRangeMinimumSize(130000);

((NumberAxis)plot.getRangeAxis()).setRangeType(RangeType.POSITIVE);

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Re: AutoRange and Zoom

Post by david.gilbert » Thu Feb 28, 2008 3:26 am

dorseywright wrote:...and have noticed that when I zoom into the chart and then zoom back out, the Y-axis ranges I specify for the chart are no longer adhered too. It's almost as if autorange gets set back equal to true even though I explicitly turned it off.
The way that zooming is implemented, when you "unzoom" the axes ranges do just return to the auto-range values (so that all data is visible on the chart). It would of course be nice to be able to specify the default base ranges for the axes, and have the "unzoom" behaviour just restore the defaults. I'll add it to the to-do list.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

miq
Posts: 1
Joined: Tue Jul 11, 2006 4:57 pm

Post by miq » Fri Feb 29, 2008 2:46 pm

We have the very same problem in several projects and it would be really great to see a viable solution like the default base ranges you pointed out.

We hope to see this realized in one of the next releases because we don't have a workaround and it really breaks the user experience.

Thanks a lot.

ReneGibson
Posts: 3
Joined: Wed Feb 27, 2008 7:00 pm

Post by ReneGibson » Mon Mar 24, 2008 8:02 pm

[quote="skunk"]Did you try calling
[code]axis.setAutoRangeIncludesZero(false);[/code][/quote]

Sorry I missed this till now. It worked perfect. Thanks!

kaisuchomel
Posts: 1
Joined: Thu Oct 30, 2008 10:09 am

Post by kaisuchomel » Thu Oct 30, 2008 10:14 am

The way that zooming is implemented, when you "unzoom" the axes ranges do just return to the auto-range values (so that all data is visible on the chart). It would of course be nice to be able to specify the default base ranges for the axes, and have the "unzoom" behaviour just restore the defaults. I'll add it to the to-do list.
Is it in the actual release possible to set a default base for a Axis?

shil
Posts: 2
Joined: Thu Jun 25, 2009 11:14 pm

Re: AutoRange and Zoom

Post by shil » Fri Jun 26, 2009 12:23 am

I see this is stil an issue with version 1.0.13. I wonder is there a way we can override this "unzoom" behavior so that it will set the range as "what is before zoom". Basically what jfree method is called when you unzoom or drag the mouse up?

skunk
Posts: 1087
Joined: Thu Jun 02, 2005 10:14 pm
Location: Brisbane, Australia

Re: AutoRange and Zoom

Post by skunk » Fri Jun 26, 2009 1:08 am

shil wrote:Basically what jfree method is called when you unzoom or drag the mouse up?
The implementation of MouseListener is in org/jfree/chart/ChartPanel.java

paradoxoff
Posts: 1634
Joined: Sat Feb 17, 2007 1:51 pm

Re: AutoRange and Zoom

Post by paradoxoff » Fri Jun 26, 2009 9:55 pm

shil wrote:I see this is stil an issue with version 1.0.13. I wonder is there a way we can override this "unzoom" behavior so that it will set the range as "what is before zoom". Basically what jfree method is called when you unzoom or drag the mouse up?
If you unzoom, i. e. if either the x or the y coordinate of the point at which the mouse is released is smaller that the x or y coordinate of the point at which the zoom was started, the restoreAutoBounds() method of ChartPanel is called. If the Plot implements Zoomable, zoomable.zoom[Range/Domain]Axes(double factor, PlotRenderingInfo info, Point2D source) is called with a factor of 0.0 which in turn calls ValueAxis.resizeRange(double factor) with the same factor which, for a factor of =< 0.0, calls ValueAxis.autoAdjustRange().
if you want to change the unzooming behaviour, I would recommend to modify the autoAdjustRange() method of the NumberAxis/DateAxis classes. The required modifications depend on what behaviour you want to have.

In this thread, it was desired that a predefined range was restored upon unzooming. The suggested solution (add a flag that indicates whether the default auto range should be restored in autoAdjustRange() or (the present behaviour) a range that makes all data items visible, check that flag the autoAdjustRange, and if is true, simply restore the default auto range. At present, the defaultAutoRange is only used if the dataset is empty) should be easy to implement.

If you need more advanced features, such as a tracking of all zoom operations (as outlined , and a stepwise unzooming, things can get complicated. it is probably not too difficult to implement such a behaviour, but it can be difficult to figure out what the users wants to achieve if an "unzoom" is triggered. Both unzoom methods (track the zoom operations and go back stepwise upon unzoom or simply restore a predefined range) can be useful. Combinations of mouse operations and key presses could do it but that is not really intuitive.

I have thought about delegating the mouse event handling from the ChartPanel class to pluggable "ChartMouseTool" classes than can be activated or deactivated by pressing icon buttons in a button bar and that offer more modular mouse event handling: one tool for zooming, one for panning, one for modifying annotations, one for markes, one for changing texts of the chart (textTitle, axis labels...) without increasing the size and complexity of the ChartPanel class with every added functionality... but thats something big and will have to wait.

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Re: AutoRange and Zoom

Post by david.gilbert » Fri Jun 26, 2009 11:29 pm

paradoxoff wrote:I have thought about delegating the mouse event handling from the ChartPanel class to pluggable "ChartMouseTool" classes than can be activated or deactivated by pressing icon buttons in a button bar and that offer more modular mouse event handling: one tool for zooming, one for panning, one for modifying annotations, one for markes, one for changing texts of the chart (textTitle, axis labels...) without increasing the size and complexity of the ChartPanel class with every added functionality... but thats something big and will have to wait.
In fact, I just implemented this feature for a client, and it will find its way into Subversion some time next week.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

shil
Posts: 2
Joined: Thu Jun 25, 2009 11:14 pm

Re: AutoRange and Zoom

Post by shil » Fri Jul 24, 2009 6:47 pm

Hi skunk,
Thanks for your tips. I am able to control unzoom behavior by overriding restoreAutoDomainBounds() in CharPanel.

Code: Select all

    public class MyChartPanel extends ChartPanel
    {
        public MyChartPanel(JFreeChart chart)
        {
            super(chart);
        }

        @Override
        public void restoreAutoDomainBounds() 
        {
            super.restoreAutoDomainBounds();
            // Set your desired range
            myDomainAxis.setRange(desiredRange);
            myRangeAxis.setRange(desiredRange);
        }
    }

skunk
Posts: 1087
Joined: Thu Jun 02, 2005 10:14 pm
Location: Brisbane, Australia

Re: AutoRange and Zoom

Post by skunk » Fri Jul 24, 2009 7:25 pm

Glad it helped. Thanks for sharing the code so others can benefit.

Locked