Search in sources :

Example 1 with PieSectionLabelGenerator

use of org.jfree.chart.labels.PieSectionLabelGenerator in project MtgDesktopCompanion by nicho92.

the class ManaRepartitionPanel method refresh.

private void refresh() {
    this.removeAll();
    JFreeChart chart = ChartFactory.createPieChart3D(// chart title
    "Color repartition", // data
    getManaRepartitionDataSet(), // include legend
    false, true, true);
    pane = new ChartPanel(chart);
    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setSectionPaint("Black", Color.BLACK);
    plot.setSectionPaint("White", Color.WHITE);
    plot.setSectionPaint("Blue", Color.BLUE);
    plot.setSectionPaint("Green", Color.GREEN);
    plot.setSectionPaint("Red", Color.RED);
    plot.setSectionPaint("Multi", Color.YELLOW);
    plot.setSectionPaint("Uncolor", Color.GRAY);
    plot.setSectionPaint("black", Color.BLACK);
    plot.setSectionPaint("white", Color.WHITE);
    plot.setSectionPaint("blue", Color.BLUE);
    plot.setSectionPaint("green", Color.GREEN);
    plot.setSectionPaint("red", Color.RED);
    plot.setSectionPaint("multi", Color.YELLOW);
    plot.setSectionPaint("uncolor", Color.GRAY);
    plot.setSimpleLabels(true);
    PieSectionLabelGenerator generator = new StandardPieSectionLabelGenerator("{1}", new DecimalFormat("0"), new DecimalFormat("0.00%"));
    plot.setLabelGenerator(generator);
    this.add(pane, BorderLayout.CENTER);
    this.revalidate();
    this.repaint();
}
Also used : ChartPanel(org.jfree.chart.ChartPanel) StandardPieSectionLabelGenerator(org.jfree.chart.labels.StandardPieSectionLabelGenerator) PieSectionLabelGenerator(org.jfree.chart.labels.PieSectionLabelGenerator) DecimalFormat(java.text.DecimalFormat) PiePlot(org.jfree.chart.plot.PiePlot) StandardPieSectionLabelGenerator(org.jfree.chart.labels.StandardPieSectionLabelGenerator) JFreeChart(org.jfree.chart.JFreeChart)

Example 2 with PieSectionLabelGenerator

use of org.jfree.chart.labels.PieSectionLabelGenerator in project SIMVA-SoS by SESoS.

the class PiePlot method drawSimpleLabels.

/**
 * Draws the pie section labels in the simple form.
 *
 * @param g2  the graphics device.
 * @param keys  the section keys.
 * @param totalValue  the total value for all sections in the pie.
 * @param plotArea  the plot area.
 * @param pieArea  the area containing the pie.
 * @param state  the plot state.
 *
 * @since 1.0.7
 */
protected void drawSimpleLabels(Graphics2D g2, List keys, double totalValue, Rectangle2D plotArea, Rectangle2D pieArea, PiePlotState state) {
    Composite originalComposite = g2.getComposite();
    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f));
    Rectangle2D labelsArea = this.simpleLabelOffset.createInsetRectangle(pieArea);
    double runningTotal = 0.0;
    Iterator iterator = keys.iterator();
    while (iterator.hasNext()) {
        Comparable key = (Comparable) iterator.next();
        boolean include;
        double v = 0.0;
        Number n = getDataset().getValue(key);
        if (n == null) {
            include = !getIgnoreNullValues();
        } else {
            v = n.doubleValue();
            include = getIgnoreZeroValues() ? v > 0.0 : v >= 0.0;
        }
        if (include) {
            runningTotal = runningTotal + v;
            // work out the mid angle (0 - 90 and 270 - 360) = right,
            // otherwise left
            double mid = getStartAngle() + (getDirection().getFactor() * ((runningTotal - v / 2.0) * 360) / totalValue);
            Arc2D arc = new Arc2D.Double(labelsArea, getStartAngle(), mid - getStartAngle(), Arc2D.OPEN);
            int x = (int) arc.getEndPoint().getX();
            int y = (int) arc.getEndPoint().getY();
            PieSectionLabelGenerator myLabelGenerator = getLabelGenerator();
            if (myLabelGenerator == null) {
                continue;
            }
            String label = myLabelGenerator.generateSectionLabel(this.dataset, key);
            if (label == null) {
                continue;
            }
            g2.setFont(this.labelFont);
            FontMetrics fm = g2.getFontMetrics();
            Rectangle2D bounds = TextUtilities.getTextBounds(label, g2, fm);
            Rectangle2D out = this.labelPadding.createOutsetRectangle(bounds);
            Shape bg = ShapeUtilities.createTranslatedShape(out, x - bounds.getCenterX(), y - bounds.getCenterY());
            if (this.labelShadowPaint != null && this.shadowGenerator == null) {
                Shape shadow = ShapeUtilities.createTranslatedShape(bg, this.shadowXOffset, this.shadowYOffset);
                g2.setPaint(this.labelShadowPaint);
                g2.fill(shadow);
            }
            if (this.labelBackgroundPaint != null) {
                g2.setPaint(this.labelBackgroundPaint);
                g2.fill(bg);
            }
            if (this.labelOutlinePaint != null && this.labelOutlineStroke != null) {
                g2.setPaint(this.labelOutlinePaint);
                g2.setStroke(this.labelOutlineStroke);
                g2.draw(bg);
            }
            g2.setPaint(this.labelPaint);
            g2.setFont(this.labelFont);
            TextUtilities.drawAlignedString(label, g2, x, y, TextAnchor.CENTER);
        }
    }
    g2.setComposite(originalComposite);
}
Also used : StandardPieSectionLabelGenerator(org.jfree.chart.labels.StandardPieSectionLabelGenerator) PieSectionLabelGenerator(org.jfree.chart.labels.PieSectionLabelGenerator) Shape(java.awt.Shape) Composite(java.awt.Composite) AlphaComposite(java.awt.AlphaComposite) Rectangle2D(java.awt.geom.Rectangle2D) Arc2D(java.awt.geom.Arc2D) RadialGradientPaint(java.awt.RadialGradientPaint) Paint(java.awt.Paint) FontMetrics(java.awt.FontMetrics) Iterator(java.util.Iterator)

Example 3 with PieSectionLabelGenerator

use of org.jfree.chart.labels.PieSectionLabelGenerator in project MtgDesktopCompanion by nicho92.

the class RarityRepartitionPanel method refresh.

private void refresh() {
    this.removeAll();
    JFreeChart chart = ChartFactory.createPieChart3D(// chart title
    "Rarity repartition", // data
    getRarityRepartitionDataSet(), // include legend
    false, true, true);
    pane = new ChartPanel(chart);
    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setSectionPaint("Uncommon", Color.GRAY);
    plot.setSectionPaint("Common", Color.WHITE);
    plot.setSectionPaint("Rare", Color.YELLOW);
    plot.setSectionPaint("Mythic Rare", Color.ORANGE);
    PieSectionLabelGenerator generator = new StandardPieSectionLabelGenerator("{0} = {1}", new DecimalFormat("0"), new DecimalFormat("0.00%"));
    plot.setLabelGenerator(generator);
    this.add(pane, BorderLayout.CENTER);
}
Also used : ChartPanel(org.jfree.chart.ChartPanel) StandardPieSectionLabelGenerator(org.jfree.chart.labels.StandardPieSectionLabelGenerator) PieSectionLabelGenerator(org.jfree.chart.labels.PieSectionLabelGenerator) DecimalFormat(java.text.DecimalFormat) PiePlot(org.jfree.chart.plot.PiePlot) StandardPieSectionLabelGenerator(org.jfree.chart.labels.StandardPieSectionLabelGenerator) JFreeChart(org.jfree.chart.JFreeChart)

Example 4 with PieSectionLabelGenerator

use of org.jfree.chart.labels.PieSectionLabelGenerator in project MtgDesktopCompanion by nicho92.

the class TypeRepartitionPanel method refresh.

private void refresh() {
    this.removeAll();
    JFreeChart chart = ChartFactory.createPieChart3D(// chart title
    "Type repartition", // data
    getTypeRepartitionDataSet(), // include legend
    false, true, true);
    pane = new ChartPanel(chart);
    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setSectionPaint("B", Color.BLACK);
    plot.setSectionPaint("W", Color.WHITE);
    plot.setSectionPaint("U", Color.BLUE);
    plot.setSectionPaint("G", Color.GREEN);
    plot.setSectionPaint("R", Color.RED);
    plot.setSectionPaint("multi", Color.YELLOW);
    plot.setSectionPaint("uncolor", Color.GRAY);
    PieSectionLabelGenerator generator = new StandardPieSectionLabelGenerator("{0} = {1}", new DecimalFormat("0"), new DecimalFormat("0.00%"));
    plot.setLabelGenerator(generator);
    this.add(pane, BorderLayout.CENTER);
}
Also used : ChartPanel(org.jfree.chart.ChartPanel) StandardPieSectionLabelGenerator(org.jfree.chart.labels.StandardPieSectionLabelGenerator) PieSectionLabelGenerator(org.jfree.chart.labels.PieSectionLabelGenerator) DecimalFormat(java.text.DecimalFormat) PiePlot(org.jfree.chart.plot.PiePlot) StandardPieSectionLabelGenerator(org.jfree.chart.labels.StandardPieSectionLabelGenerator) JFreeChart(org.jfree.chart.JFreeChart)

Aggregations

PieSectionLabelGenerator (org.jfree.chart.labels.PieSectionLabelGenerator)4 StandardPieSectionLabelGenerator (org.jfree.chart.labels.StandardPieSectionLabelGenerator)4 DecimalFormat (java.text.DecimalFormat)3 ChartPanel (org.jfree.chart.ChartPanel)3 JFreeChart (org.jfree.chart.JFreeChart)3 PiePlot (org.jfree.chart.plot.PiePlot)3 AlphaComposite (java.awt.AlphaComposite)1 Composite (java.awt.Composite)1 FontMetrics (java.awt.FontMetrics)1 Paint (java.awt.Paint)1 RadialGradientPaint (java.awt.RadialGradientPaint)1 Shape (java.awt.Shape)1 Arc2D (java.awt.geom.Arc2D)1 Rectangle2D (java.awt.geom.Rectangle2D)1 Iterator (java.util.Iterator)1