use of org.jfree.chart.legend.LegendItem in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.
the class BarRendererTest method testGetLegendItem.
/**
* Some checks for the getLegendItem() method.
*/
@Test
public void testGetLegendItem() {
DefaultCategoryDataset<String, String> dataset = new DefaultCategoryDataset<>();
dataset.addValue(21.0, "R1", "C1");
BarRenderer r = new BarRenderer();
CategoryPlot<String, String> 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.legend.LegendItem in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.
the class CategoryStepRendererTest method testGetLegendItemSeriesIndex.
/**
* A check for the datasetIndex and seriesIndex fields in the LegendItem
* returned by the getLegendItem() method.
*/
@Test
public void testGetLegendItemSeriesIndex() {
DefaultCategoryDataset<String, String> dataset0 = new DefaultCategoryDataset<>();
dataset0.addValue(21.0, "R1", "C1");
dataset0.addValue(22.0, "R2", "C1");
DefaultCategoryDataset<String, String> dataset1 = new DefaultCategoryDataset<>();
dataset1.addValue(23.0, "R3", "C1");
dataset1.addValue(24.0, "R4", "C1");
dataset1.addValue(25.0, "R5", "C1");
CategoryStepRenderer r = new CategoryStepRenderer();
CategoryPlot<String, String> plot = new CategoryPlot<>(dataset0, new CategoryAxis("x"), new NumberAxis("y"), r);
plot.setDataset(1, dataset1);
/*JFreeChart chart =*/
new JFreeChart(plot);
LegendItem li = r.getLegendItem(1, 2);
assertEquals("R5", li.getLabel());
assertEquals(1, li.getDatasetIndex());
assertEquals(2, li.getSeriesIndex());
}
use of org.jfree.chart.legend.LegendItem in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.
the class LineAndShapeRendererTest method testGetLegendItemSeriesIndex.
/**
* A check for the datasetIndex and seriesIndex fields in the LegendItem
* returned by the getLegendItem() method.
*/
@Test
public void testGetLegendItemSeriesIndex() {
DefaultCategoryDataset<String, String> dataset0 = new DefaultCategoryDataset<>();
dataset0.addValue(21.0, "R1", "C1");
dataset0.addValue(22.0, "R2", "C1");
DefaultCategoryDataset<String, String> dataset1 = new DefaultCategoryDataset<>();
dataset1.addValue(23.0, "R3", "C1");
dataset1.addValue(24.0, "R4", "C1");
dataset1.addValue(25.0, "R5", "C1");
LineAndShapeRenderer r = new LineAndShapeRenderer();
CategoryPlot<String, String> plot = new CategoryPlot<>(dataset0, new CategoryAxis("x"), new NumberAxis("y"), r);
plot.setDataset(1, dataset1);
JFreeChart chart = new JFreeChart(plot);
LegendItem li = r.getLegendItem(1, 2);
assertEquals("R5", li.getLabel());
assertEquals(1, li.getDatasetIndex());
assertEquals(2, li.getSeriesIndex());
}
use of org.jfree.chart.legend.LegendItem in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.
the class LevelRendererTest method testGetLegendItemSeriesIndex.
/**
* A check for the datasetIndex and seriesIndex fields in the LegendItem
* returned by the getLegendItem() method.
*/
@Test
public void testGetLegendItemSeriesIndex() {
DefaultCategoryDataset<String, String> dataset0 = new DefaultCategoryDataset<>();
dataset0.addValue(21.0, "R1", "C1");
dataset0.addValue(22.0, "R2", "C1");
DefaultCategoryDataset<String, String> dataset1 = new DefaultCategoryDataset<>();
dataset1.addValue(23.0, "R3", "C1");
dataset1.addValue(24.0, "R4", "C1");
dataset1.addValue(25.0, "R5", "C1");
LevelRenderer r = new LevelRenderer();
CategoryPlot<String, String> plot = new CategoryPlot<>(dataset0, new CategoryAxis("x"), new NumberAxis("y"), r);
plot.setDataset(1, dataset1);
JFreeChart chart = new JFreeChart(plot);
LegendItem li = r.getLegendItem(1, 2);
assertEquals("R5", li.getLabel());
assertEquals(1, li.getDatasetIndex());
assertEquals(2, li.getSeriesIndex());
}
use of org.jfree.chart.legend.LegendItem in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.
the class AbstractXYItemRenderer 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) {
XYPlot xyplot = getPlot();
if (xyplot == null) {
return null;
}
XYDataset dataset = xyplot.getDataset(datasetIndex);
if (dataset == null) {
return null;
}
String label = this.legendItemLabelGenerator.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);
LegendItem item = new LegendItem(label, paint);
item.setToolTipText(toolTipText);
item.setURLText(urlText);
item.setLabelFont(lookupLegendTextFont(series));
Paint labelPaint = lookupLegendTextPaint(series);
if (labelPaint != null) {
item.setLabelPaint(labelPaint);
}
item.setSeriesKey(dataset.getSeriesKey(series));
item.setSeriesIndex(series);
item.setDataset(dataset);
item.setDatasetIndex(datasetIndex);
if (getTreatLegendShapeAsLine()) {
item.setLineVisible(true);
item.setLine(shape);
item.setLinePaint(paint);
item.setShapeVisible(false);
} else {
Paint outlinePaint = lookupSeriesOutlinePaint(series);
Stroke outlineStroke = lookupSeriesOutlineStroke(series);
item.setOutlinePaint(outlinePaint);
item.setOutlineStroke(outlineStroke);
}
return item;
}
Aggregations