XYPolygonAnnotation drawing bug
-
- Posts: 21
- Joined: Sat Jan 05, 2008 2:14 am
XYPolygonAnnotation drawing bug
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.
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
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
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
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader


-
- Posts: 21
- Joined: Sat Jan 05, 2008 2:14 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).
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).
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
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
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader


-
- Posts: 21
- Joined: Sat Jan 05, 2008 2:14 am
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.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.
Plus, I'm a rather amateur coder so I wouldn't want to pollute your terrific software with my code

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.