outlines around legend items

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

outlines around legend items

Post by jim moore » Fri Feb 15, 2002 5:35 pm

Just a feature request. Wondering if you could add a feature to allow you to draw outlines around the little key boxes in the legend.

Essentially adding a protected boolean outlineKeyBoxes to Legend (which would default to false) and then providing getter/setters for it. Then draw in StandardLegend becomes (only relavent portion shown)

protected Rectangle2D draw(Graphics2D g2, Rectangle2D available,
boolean horizontal, boolean inverted) {
...

for (int i=0; i<items.length; i++) {
g2.setPaint(chart.getPlot().getSeriesPaint(i));
g2.fill(items.getMarker());
if (outlineKeyBoxes) {
g2.setPaint(outlinePaint);
g2.setStroke(outlineStroke);
g2.draw(legendArea);
}
g2.setPaint(itemPaint);
g2.drawString(items.label,
(float)items.labelPosition.getX(),
(float)items.labelPosition.getY());
}

...
}

I only ask because I need this feature (came up when we needed one of the series colors to be white (without the outline it sort of disappeared from the legend), and I have to go in and modify the code everytime I move to the latest version to put it back in. Thank goodness for opensource software, its not difficult to do, but I figure if I need to do it, then someone else out there must as well.

jim moore

Re: outlines around legend items

Post by jim moore » Fri Feb 15, 2002 5:41 pm

I should check my java before posting.

preceding should be fixed as so:

...

if (outlineKeyBoxes) {
g2.setPaint(outlinePaint);
g2.setStroke(outlineStroke);
g2.draw(items.getMarker()); //this is the fixed line
}

...

David Gilbert

Re: outlines around legend items

Post by David Gilbert » Tue Feb 19, 2002 9:38 am

Hi Jim,

Thanks for your post. I'll add this feature for the next release.

Regards,

DG.

jim

Re: outlines around legend items

Post by jim » Wed Jun 19, 2002 6:31 pm

noticed this feature still hasn't been added, so I'm just bumping it to the top.

As for now, I'm still manually making this change with each new release.

David Gilbert

Re: outlines around legend items

Post by David Gilbert » Thu Jun 20, 2002 12:00 pm

Hi Jim,

Sorry, I must have lost that one...thanks for the reminder. I've made the change, and also added attributes to control the paint and stroke separately (your code is using the settings for the outline of the legend box). It will be included with the next release (I'm about to commit the changes to CVS now).

Regards,

DG

Locked