Search in sources :

Example 51 with LegendItem

use of org.jfree.chart.legend.LegendItem in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.

the class AbstractCategoryItemRenderer method getLegendItem.

/**
 * Returns a legend item for a series.  This default implementation will
 * return {@code null} if {@link #isSeriesVisible(int)} or
 * {@link #isSeriesVisibleInLegend(int)} returns {@code false}.
 *
 * @param datasetIndex  the dataset index (zero-based).
 * @param series  the series index (zero-based).
 *
 * @return The legend item (possibly {@code null}).
 *
 * @see #getLegendItems()
 */
@Override
public LegendItem getLegendItem(int datasetIndex, int series) {
    CategoryPlot p = getPlot();
    if (p == null) {
        return null;
    }
    // check that a legend item needs to be displayed...
    if (!isSeriesVisible(series) || !isSeriesVisibleInLegend(series)) {
        return null;
    }
    CategoryDataset dataset = p.getDataset(datasetIndex);
    String label = this.legendItemLabelGenerator.generateLabel(dataset, series);
    String description = label;
    String toolTipText = null;
    if (this.legendItemToolTipGenerator != null) {
        toolTipText = this.legendItemToolTipGenerator.generateLabel(dataset, series);
    }
    String urlText = null;
    if (this.legendItemURLGenerator != null) {
        urlText = this.legendItemURLGenerator.generateLabel(dataset, series);
    }
    Shape shape = lookupLegendShape(series);
    Paint paint = lookupSeriesPaint(series);
    Paint outlinePaint = lookupSeriesOutlinePaint(series);
    Stroke outlineStroke = lookupSeriesOutlineStroke(series);
    LegendItem item = new LegendItem(label, description, toolTipText, urlText, shape, paint, outlineStroke, outlinePaint);
    item.setLabelFont(lookupLegendTextFont(series));
    Paint labelPaint = lookupLegendTextPaint(series);
    if (labelPaint != null) {
        item.setLabelPaint(labelPaint);
    }
    item.setSeriesKey(dataset.getRowKey(series));
    item.setSeriesIndex(series);
    item.setDataset(dataset);
    item.setDatasetIndex(datasetIndex);
    return item;
}
Also used : Stroke(java.awt.Stroke) Shape(java.awt.Shape) LegendItem(org.jfree.chart.legend.LegendItem) CategoryDataset(org.jfree.data.category.CategoryDataset) Paint(java.awt.Paint) GradientPaint(java.awt.GradientPaint) CategoryPlot(org.jfree.chart.plot.CategoryPlot)

Example 52 with LegendItem

use of org.jfree.chart.legend.LegendItem in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.

the class BoxAndWhiskerRenderer 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 (possibly {@code null}).
 */
@Override
public LegendItem getLegendItem(int datasetIndex, int series) {
    CategoryPlot cp = getPlot();
    if (cp == null) {
        return null;
    }
    // check that a legend item needs to be displayed...
    if (!isSeriesVisible(series) || !isSeriesVisibleInLegend(series)) {
        return null;
    }
    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 outlinePaint = lookupSeriesOutlinePaint(series);
    Stroke outlineStroke = lookupSeriesOutlineStroke(series);
    LegendItem result = new LegendItem(label, description, toolTipText, urlText, shape, paint, outlineStroke, outlinePaint);
    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;
}
Also used : Stroke(java.awt.Stroke) Shape(java.awt.Shape) LegendItem(org.jfree.chart.legend.LegendItem) BoxAndWhiskerCategoryDataset(org.jfree.data.statistics.BoxAndWhiskerCategoryDataset) CategoryDataset(org.jfree.data.category.CategoryDataset) Paint(java.awt.Paint) CategoryPlot(org.jfree.chart.plot.CategoryPlot)

Example 53 with LegendItem

use of org.jfree.chart.legend.LegendItem in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.

the class MultiplePiePlot method getLegendItems.

/**
 * Returns a collection of legend items for the pie chart.
 *
 * @return The legend items.
 */
@Override
public LegendItemCollection getLegendItems() {
    LegendItemCollection result = new LegendItemCollection();
    if (this.dataset == null) {
        return result;
    }
    List keys = null;
    prefetchSectionPaints();
    if (this.dataExtractOrder == TableOrder.BY_ROW) {
        keys = this.dataset.getColumnKeys();
    } else if (this.dataExtractOrder == TableOrder.BY_COLUMN) {
        keys = this.dataset.getRowKeys();
    }
    if (keys == null) {
        return result;
    }
    int section = 0;
    for (Object o : keys) {
        Comparable key = (Comparable) o;
        // TODO: use a generator here
        String label = key.toString();
        String description = label;
        Paint paint = (Paint) this.sectionPaints.get(key);
        LegendItem item = new LegendItem(label, description, null, null, getLegendItemShape(), paint, Plot.DEFAULT_OUTLINE_STROKE, paint);
        item.setSeriesKey(key);
        item.setSeriesIndex(section);
        item.setDataset(getDataset());
        result.add(item);
        section++;
    }
    if (this.limit > 0.0) {
        LegendItem a = new LegendItem(this.aggregatedItemsKey.toString(), this.aggregatedItemsKey.toString(), null, null, getLegendItemShape(), this.aggregatedItemsPaint, Plot.DEFAULT_OUTLINE_STROKE, this.aggregatedItemsPaint);
        result.add(a);
    }
    return result;
}
Also used : LegendItem(org.jfree.chart.legend.LegendItem) LegendItemCollection(org.jfree.chart.legend.LegendItemCollection) List(java.util.List) Paint(java.awt.Paint) Paint(java.awt.Paint)

Example 54 with LegendItem

use of org.jfree.chart.legend.LegendItem in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.

the class PiePlot method getLegendItems.

/**
 * Returns a collection of legend items for the pie chart.
 *
 * @return The legend items (never {@code null}).
 */
@Override
public LegendItemCollection getLegendItems() {
    LegendItemCollection result = new LegendItemCollection();
    if (this.dataset == null) {
        return result;
    }
    List<K> keys = this.dataset.getKeys();
    int section = 0;
    Shape shape = getLegendItemShape();
    for (K key : keys) {
        Number n = this.dataset.getValue(key);
        boolean include;
        if (n == null) {
            include = !this.ignoreNullValues;
        } else {
            double v = n.doubleValue();
            if (v == 0.0) {
                include = !this.ignoreZeroValues;
            } else {
                include = v > 0.0;
            }
        }
        if (include) {
            String label = this.legendLabelGenerator.generateSectionLabel(this.dataset, key);
            if (label != null) {
                String description = label;
                String toolTipText = null;
                if (this.legendLabelToolTipGenerator != null) {
                    toolTipText = this.legendLabelToolTipGenerator.generateSectionLabel(this.dataset, key);
                }
                String urlText = null;
                if (this.legendLabelURLGenerator != null) {
                    urlText = this.legendLabelURLGenerator.generateURL(this.dataset, key, this.pieIndex);
                }
                Paint paint = lookupSectionPaint(key);
                Paint outlinePaint = lookupSectionOutlinePaint(key);
                Stroke outlineStroke = lookupSectionOutlineStroke(key);
                LegendItem item = new LegendItem(label, description, toolTipText, urlText, true, shape, true, paint, true, outlinePaint, outlineStroke, // line not visible
                false, new Line2D.Float(), new BasicStroke(), Color.BLACK);
                item.setDataset(getDataset());
                item.setSeriesIndex(this.dataset.getIndex(key));
                item.setSeriesKey(key);
                result.add(item);
            }
            section++;
        } else {
            section++;
        }
    }
    return result;
}
Also used : LegendItemCollection(org.jfree.chart.legend.LegendItemCollection) LegendItem(org.jfree.chart.legend.LegendItem)

Example 55 with LegendItem

use of org.jfree.chart.legend.LegendItem in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.

the class WaferMapRenderer method getLegendCollection.

/**
 * Builds the list of legend entries.  called by getLegendItems in
 * WaferMapPlot to populate the plot legend.
 *
 * @return The legend items.
 */
public LegendItemCollection getLegendCollection() {
    LegendItemCollection result = new LegendItemCollection();
    if (this.paintIndex != null && this.paintIndex.size() > 0) {
        if (this.paintIndex.size() <= this.paintLimit) {
            for (Iterator i = this.paintIndex.entrySet().iterator(); i.hasNext(); ) {
                // in this case, every color has a unique value
                Map.Entry entry = (Map.Entry) i.next();
                String label = entry.getKey().toString();
                String description = label;
                Shape shape = new Rectangle2D.Double(1d, 1d, 1d, 1d);
                Paint paint = lookupSeriesPaint(((Integer) entry.getValue()).intValue());
                Paint outlinePaint = Color.BLACK;
                Stroke outlineStroke = DEFAULT_STROKE;
                result.add(new LegendItem(label, description, null, null, shape, paint, outlineStroke, outlinePaint));
            }
        } else {
            // in this case, every color has a range of values
            Set unique = new HashSet();
            for (Iterator i = this.paintIndex.entrySet().iterator(); i.hasNext(); ) {
                Map.Entry entry = (Map.Entry) i.next();
                if (unique.add(entry.getValue())) {
                    String label = getMinPaintValue((Integer) entry.getValue()).toString() + " - " + getMaxPaintValue((Integer) entry.getValue()).toString();
                    String description = label;
                    Shape shape = new Rectangle2D.Double(1d, 1d, 1d, 1d);
                    Paint paint = getSeriesPaint(((Integer) entry.getValue()).intValue());
                    Paint outlinePaint = Color.BLACK;
                    Stroke outlineStroke = DEFAULT_STROKE;
                    result.add(new LegendItem(label, description, null, null, shape, paint, outlineStroke, outlinePaint));
                }
            }
        // end foreach map entry
        }
    // end else
    }
    return result;
}
Also used : Stroke(java.awt.Stroke) Shape(java.awt.Shape) Set(java.util.Set) HashSet(java.util.HashSet) LegendItemCollection(org.jfree.chart.legend.LegendItemCollection) Paint(java.awt.Paint) LegendItem(org.jfree.chart.legend.LegendItem) Iterator(java.util.Iterator) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Aggregations

LegendItem (org.jfree.chart.legend.LegendItem)58 Test (org.junit.jupiter.api.Test)32 Paint (java.awt.Paint)23 NumberAxis (org.jfree.chart.axis.NumberAxis)20 LegendItemCollection (org.jfree.chart.legend.LegendItemCollection)20 JFreeChart (org.jfree.chart.JFreeChart)19 XYPlot (org.jfree.chart.plot.XYPlot)18 Stroke (java.awt.Stroke)16 Shape (java.awt.Shape)15 CategoryPlot (org.jfree.chart.plot.CategoryPlot)15 XYDataset (org.jfree.data.xy.XYDataset)12 GradientPaint (java.awt.GradientPaint)9 DefaultCategoryDataset (org.jfree.data.category.DefaultCategoryDataset)9 XYSeriesCollection (org.jfree.data.xy.XYSeriesCollection)9 CategoryAxis (org.jfree.chart.axis.CategoryAxis)8 CategoryDataset (org.jfree.data.category.CategoryDataset)8 XYSeries (org.jfree.data.xy.XYSeries)7 BasicStroke (java.awt.BasicStroke)6 Rectangle2D (java.awt.geom.Rectangle2D)6 Line2D (java.awt.geom.Line2D)5