}
}
// create a Grid representing the chart legend.
private Grid createLegend(PlotPanel pp) {
Grid result = new Grid(getNVisibleCurvesOnLegend(), 2);
int iVisible = 0;
/*
* Simply eliminating the border entirely is a valid transparency
* emulation for the legend (no positional shifting is needed as is
* needed for the images used to draw the main chart's curves) because
* the legend is always positioned by its center point, and the border
* extends around the entire legend key, so removing it does not result
* in any change to the legend key's center position. <p>
*
* If multiple legend locations (beyond the current "always centered in
* a band along the right edge" option) were ever supported, appropriate
* positional shifts would then have to be introduced to emulate
* transparent borders.
*
*/
GChart.setBorderWidth(result,
TRANSPARENT_BORDER_COLOR == getLegendBorderColor() ? 0 :
Math.abs(getLegendBorderWidth()));
GChart.setBorderColor(result,
TRANSPARENT_BORDER_COLOR == getLegendBorderColor() ?
"transparent" :
getLegendBorderColor());
GChart.setBorderStyle(result, getLegendBorderStyle());
GChart.setBackgroundColor(result, getLegendBackgroundColor());
int nCurves = getNCurves();
for (int i = 0; i < nCurves; i++) {
Curve c = getSystemCurve(i);
if (c.isVisible() && c.getLegendLabel()!=null) {
double symBorderFraction =
c.getSymbol().getBorderWidth()/
Math.max(
Math.max(1.0,c.getSymbol().getFillThickness()),
Math.max(c.getSymbol().getWidth(pp),
c.getSymbol().getHeight(pp, c.onY2())));
Image icon =
c.getSymbol().getSymbolType().createIconImage(
c.getSymbol(), getLegendFontSize(),
symBorderFraction);
result.setWidget(iVisible, 0, icon);
result.getCellFormatter().setAlignment(iVisible, 0,
HasHorizontalAlignment.ALIGN_CENTER,
HasVerticalAlignment.ALIGN_MIDDLE);
HTML label = new HTML(c.getLegendLabel());
GChart.setFontWeight(label, getLegendFontWeight());
GChart.setFontStyle(label, getLegendFontStyle());
GChart.setColor(label, getLegendFontColor());
GChart.setFontSize(label, getLegendFontSize());
result.setWidget(iVisible, 1, label);
result.getCellFormatter().setAlignment(iVisible, 1,
HasHorizontalAlignment.ALIGN_LEFT,
HasVerticalAlignment.ALIGN_MIDDLE);
iVisible++;
}