Logarithmic XYShapeAnnotation

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
snoopygee
Posts: 18
Joined: Wed Jan 28, 2009 3:10 pm

Logarithmic XYShapeAnnotation

Post by snoopygee » Thu Jul 09, 2009 1:42 pm

Hi,

When I'm using the standard linear axis (X and Y), I can draw elipses around my selected XYPlot chart points using the XYShapeAnnotation and they appear as I expect (i.e circles aroudn the points).

However when I create XYPlot charts with a log axis using LogarithmicAxis for example on the y axis these same elipses no longer draw circles but flattened or stretched elipses of differing sizes.

I believe this is because the height and width I am using needs to be adjusted to log rather than linear values, but weas hoping there was some facility related to the LogarithmicAxis which could convert this for me.

Any idea's how to get my elipses looking like circles again on a log scale?

Thanks
Snoopygee

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

Re: Logarithmic XYShapeAnnotation

Post by david.gilbert » Thu Jul 09, 2009 3:52 pm

You probably need to write a custom annotation for this, one that positions a circle centered on some (x, y) value, but leaves the width and height at some fixed size (so as not to be distorted by the log axes).
David Gilbert
JFreeChart Project Leader

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

snoopygee
Posts: 18
Joined: Wed Jan 28, 2009 3:10 pm

Re: Logarithmic XYShapeAnnotation

Post by snoopygee » Thu Jul 09, 2009 4:35 pm

Hi David,

That sounds like a great approach!

Without meaning to sound like I want you to write the whole thing for me, I'm not entirely sure how to approach writing a custom annotation class. Any suggestions on the approach would be much appreciated.

Would you suggest simply replacing the draw method of the XYShapeAnnotation class to ignore the width and height?

Thanks
Snoopygee

snoopygee
Posts: 18
Joined: Wed Jan 28, 2009 3:10 pm

Re: Logarithmic XYShapeAnnotation

Post by snoopygee » Fri Jul 10, 2009 7:56 pm

Hi,

In order to achieve what you have suggested would you suggest replacing the draw method of the XYShapeAnnotation class to ignore the width and height?

Thanks
Snoopygee

paradoxoff
Posts: 1634
Joined: Sat Feb 17, 2007 1:51 pm

Re: Logarithmic XYShapeAnnotation

Post by paradoxoff » Sat Jul 11, 2009 10:33 am

snoopygee wrote: In order to achieve what you have suggested would you suggest replacing the draw method of the XYShapeAnnotation class to ignore the width and height?
Kind of. The present XYShapeAnnotation uses two AffineTransforms to define the position and the size of the shape. In order to get what you want, you could try the following:
- use a Shape centered at (0,0).
- translate that Shape with an AffineTransform to the x,y-location in java2D space (you can use valueToJava2D(...) method to translate the data coordinates to java2D coordinates) and draw it.

Locked