Drawable implementation

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
tbardzil

Drawable implementation

Post by tbardzil » Mon May 17, 2004 8:30 pm

David,

I'm starting to use JFreeChart along with JFreeReport. I presume that JFreeReport is using the Drawable interface which the JFreeChart class implements.

However, in its implemenation it passes a null instance of ChartRenderingInfo to the actual draw() method where all the work is done. I'm now running into all types of problems because if the ChartRenderingInfo is null then the plot is not passed a PlotRenderingInfo which I need.

Shouldn't the implementation look like :

Code: Select all

    public void draw(Graphics2D g2, Rectangle2D area) {
        draw(g2, area, null, new ChartRenderingInfo());
    }

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 » Mon May 17, 2004 10:07 pm

I think that would add a lot of overhead (collection of chart entities) which wouldn't be necessary in the general case. Can you get away with subclassing the JFreeChart class and overriding the draw() method?
David Gilbert
JFreeChart Project Leader

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

tbardzil

Post by tbardzil » Tue May 18, 2004 2:50 am

Yeah, I tried that today and it did work. I'll have to take another look tomorrow to see what other options exist in my code.

One alternative for the library might be to have an option which can be controlled via the constructor for JFreeChart (or a setter as well) which determines whether or not a ChartRenderingInfo object is instantiated. What do you think about this approach?

Tim

Mimil
JFreeReport Staff Member
Posts: 69
Joined: Tue Mar 25, 2003 7:33 pm

Post by Mimil » Tue May 18, 2004 9:34 am

Hi,

JFreeChart objects are already drawable objects (implement draw() method).
Did you take a look to JFreeReport package that includes JFreeChart demos?
That is a temporary way to use JFC but it is working ...


Bye,
Mimil

tbardzil

Post by tbardzil » Tue May 18, 2004 2:09 pm

Yes I am aware of that. This discussion is about the implemenation of that interface which is internal to JFC.

Tim

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 » Tue May 18, 2004 9:41 pm

tbardzil wrote:One alternative for the library might be to have an option which can be controlled via the constructor for JFreeChart (or a setter as well) which determines whether or not a ChartRenderingInfo object is instantiated. What do you think about this approach?
It is better, although it still seems odd to create a ChartRenderingInfo object that can never be used after the chart is drawn. But can you tell me what you are using the PlotRenderingInfo for? Maybe there is a better way to meet your requirement.
David Gilbert
JFreeChart Project Leader

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

tbardzil

Post by tbardzil » Wed May 19, 2004 2:10 am

Yes, it's for the plot title code that I've been working on. I want to have the plot title centered over the data area so I get this information from the PlotRenderingInfo. Actually if you look at the code I posted last week you will see this (I think). Seems to be the easy way to access the data area but if maybe you can point me in another direction.

Tim

Locked