Issue with PerioidAxis

A free public discussion forum for the JFreeChart class library.

Issue with PerioidAxis

Postby kalle » Tue Jan 06, 2009 4:48 pm

Hi,

There seems to an issue with perioid axis. It displays AFAIK time from start-of-period (like a week or month) forward, but reports the time differently when asked for getlowerbound. As it keeps record of first/last and then renders itself with that information, you can (and most certainly will) end up with a scenario that does not correctly display charts along the edges.

For instance, I have a chart zoomed at 11.25.2008 1:24:00, and I have data points for each day at 00:00:00. The week starts at 11.24.2008. Axis shows range 11.24.2008 -> 1.1.2009. when asked for getlowerbound, it reports 11.25.2008, but shows 11.24. It leads to having an empty gap between chart edge and data series.

This does not happen for dateaxis.
kalle
 
Posts: 36
Joined: Wed Dec 31, 2008 4:17 pm

Postby david.gilbert » Tue Jan 06, 2009 9:40 pm

I ran into a bug very similar to this one, and thought I'd fixed it. But it looks like I didn't for some reason...strange. The PeriodAxis does behave slightly differently to a regular DateAxis, because it will try to display whole periods...so when you call setRange() it will usually choose a wider range. But then, of course, getLowerBound() and getUpperBound() should return the correct values.

To track this, I've opened a bug report at SourceForge:

https://sourceforge.net/tracker2/?func= ... tid=115494

I'll come back and investigate when I have a chance.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Ask your company to buy the JFreeChart Developer Guide
:idea: Check out other products sold by my company Object Refinery Limited
david.gilbert
JFreeChart Project Leader
 
Posts: 11359
Joined: Fri Mar 14, 2003 10:29 am

Postby kalle » Wed Jan 07, 2009 1:21 am

I would guess the trouble is here


Code: Select all
    public void setRange(Range range, boolean turnOffAutoRange,
                         boolean notify) {
        super.setRange(range, turnOffAutoRange, false);
        long upper = Math.round(range.getUpperBound());
        long lower = Math.round(range.getLowerBound());
        this.first = createInstance(this.autoRangeTimePeriodClass,
                new Date(lower), this.timeZone);
        this.last = createInstance(this.autoRangeTimePeriodClass,
                new Date(upper), this.timeZone);
        if (notify) {
            notifyListeners(new AxisChangeEvent(this));
        }
    }

If that code would call super for first and last, then I guess it would be in sync. Could be that I'm jumping to the gun here. It'd go something like this:
Code: Select all
    public void setRange(Range range, boolean turnOffAutoRange,
                         boolean notify) {
        long upper = Math.round(range.getUpperBound());
        long lower = Math.round(range.getLowerBound());
        this.first = createInstance(this.autoRangeTimePeriodClass,
                new Date(lower), this.timeZone);
        this.last = createInstance(this.autoRangeTimePeriodClass,
                new Date(upper), this.timeZone);
        super.setRange(new Range(first, last), turnOffAutoRange, false);
        if (notify) {
            notifyListeners(new AxisChangeEvent(this));
        }
    }

Of course one would have to get the ms for the start of first and end of last.

BTW: I've got newer versions for the patches I posted earlier, are they of value? Both for the RendererUtilities (now correctly supports under and overflow) and the lineandshape.
kalle
 
Posts: 36
Joined: Wed Dec 31, 2008 4:17 pm

Postby david.gilbert » Fri Jan 16, 2009 4:07 pm

I *had* fixed this bug in a local source tree but for some strange reason hadn't checked the code in to Subversion (perhaps because I hadn't written a unit test for it?). Anyway, it is committed now and will be included in the 1.0.13 release.

The fix is just as 'kalle' suggests above.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Ask your company to buy the JFreeChart Developer Guide
:idea: Check out other products sold by my company Object Refinery Limited
david.gilbert
JFreeChart Project Leader
 
Posts: 11359
Joined: Fri Mar 14, 2003 10:29 am


Return to JFreeChart - General

Who is online

Users browsing this forum: Bing [Bot], david.gilbert, Google [Bot], sergey, Yahoo [Bot] and 10 guests