setBasePaint not giving same result as deprecated setPaint..

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Commander Salamander
Posts: 21
Joined: Sat Jan 05, 2008 2:14 am

setBasePaint not giving same result as deprecated setPaint..

Post by Commander Salamander » Wed Nov 19, 2008 2:18 am

I have a XYLineAndShapeRenderer that needs to paint all series black. This works fine with the deprecated setPaint method, but when I use setBasePaint it does not work (each XYSeries is a different color).

The note for the deprecated method says:
Deprecated. This method should no longer be used (as of version 1.0.6). It is sufficient to rely on setSeriesPaint(int, Paint) and setBasePaint(Paint).
I'd rather not do this for each series, so I had hoped setBasePaint(Color.BLACK) would work. I take it I am overlooking something?

Thanks.

P.S. David, if you happen to be reading this: it would be nice if the addSeries() method would return an int that is the index for that series. Would this be possible?

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

Re: setBasePaint not giving same result as deprecated setPai

Post by paradoxoff » Wed Nov 19, 2008 9:43 am

Commander Salamander wrote:I have a XYLineAndShapeRenderer that needs to paint all series black. This works fine with the deprecated setPaint method, but when I use setBasePaint it does not work (each XYSeries is a different color).
XYLineAndShapeRenderer uses the return value of getItemPaint(series,item) when drawing the items.
This method is defined in AbstractRenderer and returns lookupSeriesPaint(series) which will return the variable "paint". If "paint" is null, it will check getSeriesPaint(series) for a non-null value. If that also fails and if autoPopulateSeriesPaint is true, the paint will be requested from the DrawingSupplier. If for some reason that still gives a null paint, then basePaint will be returned which is intialized as DEFAULT_PAINT or Color.blue.
IMHO the first check in AbstractRenderer.getItemPaint(series,item) should be whether the basePaint should be used and if so, return it. A simple patch (introducing a private useBasePaint flag with public setters and getters and modification of getItemPaint(series,item)) should do it.

Commander Salamander
Posts: 21
Joined: Sat Jan 05, 2008 2:14 am

Post by Commander Salamander » Wed Nov 19, 2008 5:53 pm

Thanks. I'll give it a shot.

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 » Fri Nov 21, 2008 9:39 am

If you want all the series to have a single colour, you need to first set the "autoPopulate" flag (inherited from AbstractRenderer) to false, then set the base paint:

Code: Select all

renderer.setAutoPopulateSeriesPaint(false);
renderer.setBasePaint(Color.black);
David Gilbert
JFreeChart Project Leader

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

Commander Salamander
Posts: 21
Joined: Sat Jan 05, 2008 2:14 am

Post by Commander Salamander » Fri Nov 21, 2008 5:43 pm

Thank you David, that works perfectly. I thought I had tried that before, but I realize now I probably set the autofillpaint.

Any thoughts on my request from my initial post? I often find that I want to add something to a dataset and then immediately require the index. It would be great if the standard approach for such methods in JFreeChart would be to return the index upon addition (or is there a performance cost?)

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 Nov 24, 2008 1:58 pm

I think it would be easy enough to do. But addSeries() just adds the series as the last one in the collection, so the index will be given by dataset.getSeriesCount() - 1.
David Gilbert
JFreeChart Project Leader

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

Locked