XYPolygonAnnotation drawing bug

A free public discussion forum for the JFreeChart class library.

XYPolygonAnnotation drawing bug

Postby Commander Salamander » Tue Jan 20, 2009 1:35 am

I have a DomainAxis that is extremely long (1-250,000,000). When I zoom to small windows of this domain (e.g. < 200), my XYPolygonAnnotation that spans the entire axis is not drawn for some - but not all! - of the window sizes (e.g. 45 no, 31 yes)... I strongly suspect that there is some sort of rounding error occurring during the determination of the painting coordinates.
Commander Salamander
 
Posts: 21
Joined: Sat Jan 05, 2008 2:14 am

Postby david.gilbert » Tue Jan 20, 2009 9:56 am

I suspect the problem is caused by this bug:

http://bugs.sun.com/bugdatabase/view_bu ... id=4265778

The solution / workaround is probably to clip the polygon to the plot's data area (or a rectangle a little larger) before rendering it. I don't have time to do this right now, but I'll file a bug report for it and hopefully come back to it later (if someone else doesn't do it first):

https://sourceforge.net/tracker2/?func= ... tid=115494
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: 11352
Joined: Fri Mar 14, 2003 10:29 am

Postby Commander Salamander » Wed Jan 21, 2009 3:01 am

Thanks David. I overrode the XYPolygonAnnotation draw() method and did as you suggested, and the problem is fixed.

As an aside, I also added in a method that checks whether the annotation falls within the viewing area and returns immediately if it does not (saving several rather expensive JavaTo2D method calls).
Commander Salamander
 
Posts: 21
Joined: Sat Jan 05, 2008 2:14 am

Postby david.gilbert » Wed Jan 21, 2009 9:14 am

Cool. If you want to, post a diff of the changes you made and I'll update the class for the next release.
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: 11352
Joined: Fri Mar 14, 2003 10:29 am

Postby Commander Salamander » Wed Jan 21, 2009 7:16 pm

david.gilbert wrote:Cool. If you want to, post a diff of the changes you made and I'll update the class for the next release.


I'd be happy to help, but my code is actually specialized to deal with only the type of polygon that my project utilizes... I'm not sure it would work for all cases.

Plus, I'm a rather amateur coder so I wouldn't want to pollute your terrific software with my code :lol:

That said, I'll at least explain the workaround:

[1] Find max and min of 'x' and 'y' values in polygon
[2] Get the domain and range axis lower and upper bounds
[3] Check whether polygon falls within domain and range bounds, and return if it does not (this prevents a lot of unnecessary JavaTo2D method calls for charts that are often heavily zoomed in).
[4] When drawing the polygon, always take the 'x' and 'y' value and use max() and min() functions to restrict them to the edge of the visible bounds when needed.
Commander Salamander
 
Posts: 21
Joined: Sat Jan 05, 2008 2:14 am


Return to JFreeChart - General

Who is online

Users browsing this forum: Bing [Bot], Google [Bot], Yahoo [Bot] and 5 guests