use of org.jfree.chart.legend.LegendItem in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.
the class CategoryPlotTest method testCloning3.
/**
* Some more cloning checks.
*/
@Test
public void testCloning3() {
LegendItemCollection c1 = new LegendItemCollection();
CategoryPlot<String, String> p1 = new CategoryPlot<>();
p1.setFixedLegendItems(c1);
CategoryPlot<String, String> p2;
try {
p2 = CloneUtils.clone(p1);
} catch (CloneNotSupportedException e) {
fail("Cloning failed.");
return;
}
assertNotSame(p1, p2);
assertSame(p1.getClass(), p2.getClass());
assertEquals(p1, p2);
c1.add(new LegendItem("X", "XX", "tt", "url", true, new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0), true, Color.RED, true, Color.YELLOW, new BasicStroke(1.0f), true, new Line2D.Double(1.0, 2.0, 3.0, 4.0), new BasicStroke(1.0f), Color.GREEN));
assertNotEquals(p1, p2);
p2.getFixedLegendItems().add(new LegendItem("X", "XX", "tt", "url", true, new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0), true, Color.RED, true, Color.YELLOW, new BasicStroke(1.0f), true, new Line2D.Double(1.0, 2.0, 3.0, 4.0), new BasicStroke(1.0f), Color.GREEN));
assertEquals(p1, p2);
}
use of org.jfree.chart.legend.LegendItem in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.
the class PolarPlotTest method testGetLegendItems2.
/**
* Some checks for the getLegendItems() method with multiple datasets.
*/
@Test
public void testGetLegendItems2() {
XYSeriesCollection<String> d1 = new XYSeriesCollection<>();
d1.addSeries(new XYSeries<>("A"));
d1.addSeries(new XYSeries<>("B"));
XYSeriesCollection<String> d2 = new XYSeriesCollection<>();
d2.addSeries(new XYSeries<>("C"));
d2.addSeries(new XYSeries<>("D"));
DefaultPolarItemRenderer r = new DefaultPolarItemRenderer();
PolarPlot plot = new PolarPlot();
plot.setDataset(d1);
plot.setDataset(1, d2);
plot.setRenderer(r);
plot.setRenderer(1, new DefaultPolarItemRenderer());
LegendItemCollection items = plot.getLegendItems();
assertEquals(4, items.getItemCount());
LegendItem item1 = items.get(0);
assertEquals("A", item1.getLabel());
LegendItem item2 = items.get(1);
assertEquals("B", item2.getLabel());
LegendItem item3 = items.get(2);
assertEquals("C", item3.getLabel());
LegendItem item4 = items.get(3);
assertEquals("D", item4.getLabel());
}
use of org.jfree.chart.legend.LegendItem in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.
the class SpiderWebPlotTest method testGetLegendItems.
/**
* Fetches the legend items and checks the values.
*/
@Test
public void testGetLegendItems() {
DefaultCategoryDataset<String, String> dataset = new DefaultCategoryDataset<>();
dataset.addValue(35.0, "S1", "C1");
dataset.addValue(45.0, "S1", "C2");
dataset.addValue(55.0, "S2", "C1");
dataset.addValue(15.0, "S2", "C2");
SpiderWebPlot plot = new SpiderWebPlot(dataset);
JFreeChart chart = new JFreeChart(plot);
LegendItemCollection legendItems = plot.getLegendItems();
assertEquals(2, legendItems.getItemCount());
LegendItem item1 = legendItems.get(0);
assertEquals("S1", item1.getLabel());
assertEquals("S1", item1.getSeriesKey());
assertEquals(0, item1.getSeriesIndex());
assertEquals(dataset, item1.getDataset());
assertEquals(0, item1.getDatasetIndex());
LegendItem item2 = legendItems.get(1);
assertEquals("S2", item2.getLabel());
assertEquals("S2", item2.getSeriesKey());
assertEquals(1, item2.getSeriesIndex());
assertEquals(dataset, item2.getDataset());
assertEquals(0, item2.getDatasetIndex());
}
use of org.jfree.chart.legend.LegendItem in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.
the class XYBarRenderer 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;
}
LegendItem result;
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);
}
Shape shape = this.legendBar;
Paint paint = lookupSeriesPaint(series);
Paint outlinePaint = lookupSeriesOutlinePaint(series);
Stroke outlineStroke = lookupSeriesOutlineStroke(series);
if (this.drawBarOutline) {
result = new LegendItem(label, description, toolTipText, urlText, shape, paint, outlineStroke, outlinePaint);
} else {
result = new LegendItem(label, description, toolTipText, urlText, shape, 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);
if (getGradientPaintTransformer() != null) {
result.setFillPaintTransformer(getGradientPaintTransformer());
}
return result;
}
use of org.jfree.chart.legend.LegendItem in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.
the class XYDifferenceRenderer 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 p = getPlot();
if (p != null) {
XYDataset dataset = p.getDataset(datasetIndex);
if (dataset != null) {
if (getItemVisible(series, 0)) {
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);
}
Paint paint = lookupSeriesPaint(series);
Stroke stroke = lookupSeriesStroke(series);
Shape line = getLegendLine();
result = new LegendItem(label, description, toolTipText, urlText, line, stroke, 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