Search in sources :

Example 26 with LegendItemCollection

use of org.jfree.chart.legend.LegendItemCollection 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 27 with LegendItemCollection

use of org.jfree.chart.legend.LegendItemCollection 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 28 with LegendItemCollection

use of org.jfree.chart.legend.LegendItemCollection 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)

Example 29 with LegendItemCollection

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

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}).
 */
@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;
}
Also used : LegendItem(org.jfree.chart.legend.LegendItem) LegendItemCollection(org.jfree.chart.legend.LegendItemCollection) XYDataset(org.jfree.data.xy.XYDataset) Paint(java.awt.Paint) GradientPaint(java.awt.GradientPaint)

Aggregations

LegendItemCollection (org.jfree.chart.legend.LegendItemCollection)29 LegendItem (org.jfree.chart.legend.LegendItem)20 Test (org.junit.jupiter.api.Test)15 Paint (java.awt.Paint)7 BasicStroke (java.awt.BasicStroke)5 GradientPaint (java.awt.GradientPaint)5 Stroke (java.awt.Stroke)4 NumberAxis (org.jfree.chart.axis.NumberAxis)4 Rectangle2D (java.awt.geom.Rectangle2D)3 DefaultCategoryDataset (org.jfree.data.category.DefaultCategoryDataset)3 List (java.util.List)2 JFreeChart (org.jfree.chart.JFreeChart)2 RectangleInsets (org.jfree.chart.api.RectangleInsets)2 DefaultPolarItemRenderer (org.jfree.chart.renderer.DefaultPolarItemRenderer)2 DefaultXYItemRenderer (org.jfree.chart.renderer.xy.DefaultXYItemRenderer)2 StandardXYItemRenderer (org.jfree.chart.renderer.xy.StandardXYItemRenderer)2 XYItemRenderer (org.jfree.chart.renderer.xy.XYItemRenderer)2 DefaultShadowGenerator (org.jfree.chart.util.DefaultShadowGenerator)2 XYDataset (org.jfree.data.xy.XYDataset)2 XYSeriesCollection (org.jfree.data.xy.XYSeriesCollection)2