use of org.jfree.chart.LegendItem in project SIMVA-SoS by SESoS.
the class BoxAndWhiskerRendererTest method testGetLegendItem.
/**
* Some checks for the getLegendItem() method.
*/
@Test
public void testGetLegendItem() {
DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset();
List values = new ArrayList();
values.add(new Double(1.10));
values.add(new Double(1.45));
values.add(new Double(1.33));
values.add(new Double(1.23));
dataset.add(values, "R1", "C1");
BoxAndWhiskerRenderer r = new BoxAndWhiskerRenderer();
CategoryPlot plot = new CategoryPlot(dataset, new CategoryAxis("x"), new NumberAxis("y"), r);
/*JFreeChart chart =*/
new JFreeChart(plot);
LegendItem li = r.getLegendItem(0, 0);
assertNotNull(li);
r.setSeriesVisibleInLegend(0, Boolean.FALSE);
li = r.getLegendItem(0, 0);
assertNull(li);
}
use of org.jfree.chart.LegendItem in project SIMVA-SoS by SESoS.
the class XYDotRendererTest method testGetLegendItemSeriesIndex.
/**
* A check for the datasetIndex and seriesIndex fields in the LegendItem
* returned by the getLegendItem() method.
*/
@Test
public void testGetLegendItemSeriesIndex() {
XYSeriesCollection d1 = new XYSeriesCollection();
XYSeries s1 = new XYSeries("S1");
s1.add(1.0, 1.1);
XYSeries s2 = new XYSeries("S2");
s2.add(1.0, 1.1);
d1.addSeries(s1);
d1.addSeries(s2);
XYSeriesCollection d2 = new XYSeriesCollection();
XYSeries s3 = new XYSeries("S3");
s3.add(1.0, 1.1);
XYSeries s4 = new XYSeries("S4");
s4.add(1.0, 1.1);
XYSeries s5 = new XYSeries("S5");
s5.add(1.0, 1.1);
d2.addSeries(s3);
d2.addSeries(s4);
d2.addSeries(s5);
XYDotRenderer r = new XYDotRenderer();
XYPlot plot = new XYPlot(d1, new NumberAxis("x"), new NumberAxis("y"), r);
plot.setDataset(1, d2);
/*JFreeChart chart =*/
new JFreeChart(plot);
LegendItem li = r.getLegendItem(1, 2);
assertEquals("S5", li.getLabel());
assertEquals(1, li.getDatasetIndex());
assertEquals(2, li.getSeriesIndex());
}
use of org.jfree.chart.LegendItem in project SIMVA-SoS by SESoS.
the class LineAndShapeRenderer method getLegendItem.
/**
* Returns a legend item for a series.
*
* @param datasetIndex the dataset index (zero-based).
* @param series the series index (zero-based).
*
* @return The legend item.
*/
@Override
public LegendItem getLegendItem(int datasetIndex, int series) {
CategoryPlot cp = getPlot();
if (cp == null) {
return null;
}
if (isSeriesVisible(series) && isSeriesVisibleInLegend(series)) {
CategoryDataset dataset = cp.getDataset(datasetIndex);
String label = getLegendItemLabelGenerator().generateLabel(dataset, series);
String description = label;
String toolTipText = null;
if (getLegendItemToolTipGenerator() != null) {
toolTipText = getLegendItemToolTipGenerator().generateLabel(dataset, series);
}
String urlText = null;
if (getLegendItemURLGenerator() != null) {
urlText = getLegendItemURLGenerator().generateLabel(dataset, series);
}
Shape shape = lookupLegendShape(series);
Paint paint = lookupSeriesPaint(series);
Paint fillPaint = (this.useFillPaint ? getItemFillPaint(series, 0) : paint);
boolean shapeOutlineVisible = this.drawOutlines;
Paint outlinePaint = (this.useOutlinePaint ? getItemOutlinePaint(series, 0) : paint);
Stroke outlineStroke = lookupSeriesOutlineStroke(series);
boolean lineVisible = getItemLineVisible(series, 0);
boolean shapeVisible = getItemShapeVisible(series, 0);
LegendItem result = new LegendItem(label, description, toolTipText, urlText, shapeVisible, shape, getItemShapeFilled(series, 0), fillPaint, shapeOutlineVisible, outlinePaint, outlineStroke, lineVisible, new Line2D.Double(-7.0, 0.0, 7.0, 0.0), getItemStroke(series, 0), getItemPaint(series, 0));
result.setLabelFont(lookupLegendTextFont(series));
Paint labelPaint = lookupLegendTextPaint(series);
if (labelPaint != null) {
result.setLabelPaint(labelPaint);
}
result.setDataset(dataset);
result.setDatasetIndex(datasetIndex);
result.setSeriesKey(dataset.getRowKey(series));
result.setSeriesIndex(series);
return result;
}
return null;
}
use of org.jfree.chart.LegendItem in project SIMVA-SoS by SESoS.
the class AbstractXYItemRenderer method getLegendItems.
/**
* Returns a (possibly empty) collection of legend items for the series
* that this renderer is responsible for drawing.
*
* @return The legend item collection (never <code>null</code>).
*/
@Override
public LegendItemCollection getLegendItems() {
if (this.plot == null) {
return new LegendItemCollection();
}
LegendItemCollection result = new LegendItemCollection();
int index = this.plot.getIndexOf(this);
XYDataset dataset = this.plot.getDataset(index);
if (dataset != null) {
int seriesCount = dataset.getSeriesCount();
for (int i = 0; i < seriesCount; i++) {
if (isSeriesVisibleInLegend(i)) {
LegendItem item = getLegendItem(index, i);
if (item != null) {
result.add(item);
}
}
}
}
return result;
}
use of org.jfree.chart.LegendItem in project SIMVA-SoS by SESoS.
the class XYAreaRenderer method getLegendItem.
/**
* Returns a default legend item for the specified series. Subclasses
* should override this method to generate customised items.
*
* @param datasetIndex the dataset index (zero-based).
* @param series the series index (zero-based).
*
* @return A legend item for the series.
*/
@Override
public LegendItem getLegendItem(int datasetIndex, int series) {
LegendItem result = null;
XYPlot xyplot = getPlot();
if (xyplot != null) {
XYDataset dataset = xyplot.getDataset(datasetIndex);
if (dataset != null) {
XYSeriesLabelGenerator lg = getLegendItemLabelGenerator();
String label = lg.generateLabel(dataset, series);
String description = label;
String toolTipText = null;
if (getLegendItemToolTipGenerator() != null) {
toolTipText = getLegendItemToolTipGenerator().generateLabel(dataset, series);
}
String urlText = null;
if (getLegendItemURLGenerator() != null) {
urlText = getLegendItemURLGenerator().generateLabel(dataset, series);
}
Paint paint = lookupSeriesPaint(series);
result = new LegendItem(label, description, toolTipText, urlText, this.legendArea, paint);
result.setLabelFont(lookupLegendTextFont(series));
Paint labelPaint = lookupLegendTextPaint(series);
if (labelPaint != null) {
result.setLabelPaint(labelPaint);
}
result.setDataset(dataset);
result.setDatasetIndex(datasetIndex);
result.setSeriesKey(dataset.getSeriesKey(series));
result.setSeriesIndex(series);
}
}
return result;
}
Aggregations