[regression] CombinedDomainXYPlot repaints too often

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
seh4nc
Posts: 3
Joined: Thu Jan 03, 2008 3:37 am

[regression] CombinedDomainXYPlot repaints too often

Post by seh4nc » Thu Jan 03, 2008 3:49 am

My CombinedDomainXYPlot seemed to be repainting too often after I upgraded from 1.0.3 to 1.0.8a.

I tracked it down to a new 'notifyListeners' call and have fixed the problem by overriding these methods of XYPlot (pls consider putting the equality check in the base methods):

Code: Select all

  public void setFixedDomainAxisSpace(AxisSpace space)
  {
    AxisSpace prev = getFixedRangeAxisSpace();
    if (prev != space && (prev == null || !prev.equals(space))) {
      super.setFixedDomainAxisSpace(space);
    }
  }

  public void setFixedRangeAxisSpace(AxisSpace space)
  {
    AxisSpace prev = getFixedRangeAxisSpace();
    if (prev != space && (prev == null || !prev.equals(space))) {
      super.setFixedRangeAxisSpace(space);
    }
  }

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 » Thu Jan 03, 2008 12:36 pm

Thanks for the report. I tried to create a JUnit test that reproduces this problem, but so far I failed. I'll paste my test below - if you could suggest a change (or another test) that shows the bug, that would be a great help:

Code: Select all

    /**
     * Check that only one chart change event is generated by a change to a
     * subplot.
     */
    public void testNotification() {
        CombinedDomainXYPlot plot = createPlot();
        JFreeChart chart = new JFreeChart(plot);
        chart.addChangeListener(this);
        XYPlot subplot1 = (XYPlot) plot.getSubplots().get(0);
        NumberAxis yAxis = (NumberAxis) subplot1.getRangeAxis();
        yAxis.setAutoRangeIncludesZero(!yAxis.getAutoRangeIncludesZero());
        assertEquals(1, this.events.size());
        
        // a redraw should NOT trigger another change event
        BufferedImage image = new BufferedImage(200, 100, 
                BufferedImage.TYPE_INT_RGB);
        Graphics2D g2 = image.createGraphics();
        this.events.clear();
        chart.draw(g2, new Rectangle2D.Double(0.0, 0.0, 200.0, 100.0));
        assertTrue(this.events.isEmpty());
    } 
... and here is the "listener" part of the code (which I tacked onto the test class):

Code: Select all

public class CombinedDomainXYPlotTests extends TestCase 
        implements ChartChangeListener {

    /** A list of the events received. */
    private List events = new java.util.ArrayList();
    
    /**
     * Receives a chart change event.
     * 
     * @param event  the event.
     */
    public void chartChanged(ChartChangeEvent event) {
        this.events.add(event);
    }

David Gilbert
JFreeChart Project Leader

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

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 » Thu Jan 03, 2008 12:54 pm

Sorry, just re-ran my test with 1.0.8 and it fails. It is fixed already in Subversion and 1.0.9 should be released this week.
David Gilbert
JFreeChart Project Leader

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

Locked