BUG:Vers 1.09, zoomRangeAxis + CombinedDomainXYPlot

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
RoyW
Posts: 93
Joined: Wed Apr 23, 2008 7:42 pm
Contact:

BUG:Vers 1.09, zoomRangeAxis + CombinedDomainXYPlot

Post by RoyW » Wed Apr 23, 2008 8:30 pm

Hi,
I have posted this in the bug tracking system at sourceforge but it didn't format the code too well so I am re-posting it here. Please feel free to delete one or the other.

There appears to be a bug either in ChartPanel or CombinedDomainXYPlot when trying to zoom in/out on the range axis.

ChartPanel

Code: Select all

    public void zoomOutRange(double x, double y) {
        Plot p = this.chart.getPlot();
        if (p instanceof Zoomable) {
            Zoomable z = (Zoomable) p;
            z.zoomRangeAxes(this.zoomOutFactor, this.info.getPlotInfo(), 
                    translateScreenToJava2D(new Point((int) x, (int) y)),
                    this.zoomAroundAnchor);
        }
    }
This calls zoomRangeAxis() in XYPlot and not in CombinedDomainXYPlot. The other 2 zoomRangeAxis() methods are overridden in CombinedDomainXYPlot and correctly identify the sub plot to zoom.

Because ChartPanel.zoomOutRange calls the one that is not overridden it tries to use the Range of the MainPlot and not the SubPlot. The Range is null so no zoom occurs. I have managed to get around this by overriding the methods in ChartPanel

Code: Select all

      //Create the actual chart
      final JFreeChart chart = new JFreeChart(null, null, mainPlot, false);
      //Create the visible chart panel
      chartPanel = new ChartPanel(chart)
      {
         public void zoomInRange(double x, double y)
         {
            Plot p = chart.getPlot();
            if (p instanceof Zoomable) {
               Zoomable z = (Zoomable) p;
               z.zoomRangeAxes(getZoomInFactor(), getChartRenderingInfo().getPlotInfo(),
                       translateScreenToJava2D(new Point((int) x, (int) y)));
           }
         }
         public void zoomOutRange(double x, double y) {
             Plot p = chart.getPlot();
             if (p instanceof Zoomable) {
                 Zoomable z = (Zoomable) p;
                 z.zoomRangeAxes(getZoomOutFactor(), getChartRenderingInfo().getPlotInfo(),
                         translateScreenToJava2D(new Point((int) x, (int) y)));
             }
         }
      };
(They call the methods without the this.zoomAroundAnchor so the overridden method gets called)

My suggestion for a fix would be in CombinedDomainXYPlot to override the method

Code: Select all

public void zoomRangeAxes(double factor, PlotRenderingInfo info,
                              Point2D source, boolean useAnchor);
and not

Code: Select all

public void zoomRangeAxes(double factor, PlotRenderingInfo info,
                              Point2D source);
}
as it does currently.

I think the same may be true of CombinedRangeXYPlot but I have not tested thet.[/code]

RoyW
Posts: 93
Joined: Wed Apr 23, 2008 7:42 pm
Contact:

Post by RoyW » Thu Apr 24, 2008 7:07 pm

Here is a small program to illustrate the point. If you right click, Zoom Out->Range Axis, nothing happens. If you put in the fix I suggested above it works.

Code: Select all

import org.jfree.chart.axis.*;
import org.jfree.chart.plot.*;
import org.jfree.chart.renderer.xy.*;
import org.jfree.chart.*;
import org.jfree.data.xy.*;

import javax.swing.*;
import java.awt.*;

public class ZoomTest extends JFrame{
   public ZoomTest(){
      super("ZoomTest");
      this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

      NumberAxis           domainAxis = new NumberAxis("X Values");
      XYItemRenderer       renderer   = new XYLineAndShapeRenderer();
      CombinedDomainXYPlot mainPlot   = new CombinedDomainXYPlot(domainAxis);

      for(int i=1 ; i<=4 ; i++)
         mainPlot.add( new XYPlot(getDataSet(i), domainAxis, new NumberAxis("y"+i), renderer) ,i);

      //Create the actual chart
      final JFreeChart chart = new JFreeChart(null, null, mainPlot, false);
      //Create the visible chart panel
      ChartPanel chartPanel = new ChartPanel(chart);
      chartPanel.setPreferredSize( new Dimension(600,600) );

      this.add(chartPanel);
      this.pack();
   }
   protected XYDataset getDataSet(final int power) {
      return new AbstractXYDataset(){
         public int getSeriesCount(){return 1;}
         public Comparable getSeriesKey(int series){return "zoom";}
         public int getItemCount(int series){return 10;}
         public Number getX(int series, int item){return new Double(item);}
         public Number getY(int series, int item){return new Double(Math.pow(item , power));}
      };
   }

   public static void main(String[] args){
      new ZoomTest().setVisible(true);
   }
}

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

Post by david.gilbert » Mon Apr 28, 2008 11:20 am

Thanks for the report. Fixing this now.
David Gilbert
JFreeChart Project Leader

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

Locked